Files
gtav-src/tools_ng/script/coding/projbuild/updateassemblyinfo.rb
T
2025-09-29 00:52:08 +02:00

179 lines
6.1 KiB
Ruby
Executable File

#
# File:: updateassemblyinfo.rb
# Automatically generates assembly information for executables.
#
# Pipeline::
#
# Author:: Kevin Weinberg <kevin.weinberg@rockstarnorth.com>
# Date:: 14 May 2010
#
#-----------------------------------------------------------------------------
# Uses
#-----------------------------------------------------------------------------
require 'pipeline/coding/projbuild.rb'
require 'pipeline/coding/projconvert.rb'
require 'pipeline/os/getopt'
require 'pipeline/os/path'
require 'pipeline/os/file'
#-----------------------------------------------------------------------------
# Helper Functions
#-----------------------------------------------------------------------------
def get_makeheaders_config_root()
config_directory = ENV['RAGE_DIR']
config_directory = OS::Path::combine(config_directory, "base\\src\\forceinclude\\templates")
return config_directory
end
def write_line(file, string)
file.write(string + "\n")
end
def write_assembly_info_file( company, version_string, file_path )
file = File.new(file_path, "w")
write_line(file, "using System.Reflection;" );
write_line(file, "using System.Runtime.CompilerServices;" );
write_line(file, "using System.Runtime.InteropServices;" );
write_line(file, "" );
write_line(file, "/******************************************************************************" );
write_line(file, "* DO NOT EDIT THIS FILE. IT IS AUTO-GENERATED." );
write_line(file, "* " );
write_line(file, "* To use in your project:" );
write_line(file, "* 1) Add this file to your project. If you are using a common file, such as" );
write_line(file, "* rage/build/CommonAssemblyInfo.cs, then add the file as a Link. This" );
write_line(file, "* option can be found on the Add Existing Item dialog in the Add button's" );
write_line(file, "* drop down menu." );
write_line(file, "* 2) Edit your project's AssemblyInfo.cs file, commenting out the Assembly*" );
write_line(file, "* items you see in this file." );
write_line(file, "******************************************************************************/" );
write_line(file, "" );
write_line(file, "// General Information about an assembly is controlled through the following " );
write_line(file, "// set of attributes. Change these attribute values to modify the information" );
write_line(file, "// associated with an assembly." );
write_line(file, "[assembly: AssemblyCompany( \"#{company}\" )]" );
write_line(file, "[assembly: AssemblyCopyright( \"Copyright © #{company} 2010\" )]" ); #TODO: Automate the year?
write_line(file, "" );
write_line(file, "// Version information for an assembly consists of the following four values:" );
write_line(file, "//" );
write_line(file, "// Major Version" );
write_line(file, "// Minor Version " );
write_line(file, "// Build Number" );
write_line(file, "// Revision" );
write_line(file, "//" );
write_line(file, "// You can specify all the values or you can default the Revision and Build Numbers " );
write_line(file, "// by using the '*' as shown below:" );
write_line(file, "[assembly: AssemblyVersion( \"#{version_string}\" )]");
write_line(file, "" );
file.close
end
#-----------------------------------------------------------------------------
# Implementation
#-----------------------------------------------------------------------------
COMMAND_OPTIONS = [ ["--help", "-h", Getopt::BOOLEAN, "Display help text." ],
["--file", "-f", Getopt::REQUIRED, "Path to AssemblyInfo.cs"],
["--company", "-c", Getopt::OPTIONAL, "Name of the Company"],
]
TRAILING_DESC = { }
opts, trailing = Pipeline::OS::Getopt.getopts( COMMAND_OPTIONS )
if ( opts["help"] ) then
puts OS::Getopt.usage( COMMAND_OPTIONS, TRAILING_DESC )
exit( 1 )
end
if ( opts["file"].nil? ) then
puts OS::Getopt.usage( COMMAND_OPTIONS, TRAILING_DESC )
exit( 1 )
end
file_path = opts["file"].intern
if ENV["RAGE_DIR"].nil?
puts "RAGE_DIR environment variable was not found. Please reinstall the framework!\n"
exit( 1 )
end
if ( opts["company"].nil? ) then
company_name = "Rockstar Games"
else
company_name = opts["company"].intern
end
#Acquire the current version of the build.
config_directory = get_makeheaders_config_root()
version_header_path = OS::Path::combine(config_directory, "version.h")
if File.exist?(version_header_path) == false
puts "Unable to find #{version_header_path} to increment version number!"
exit( 1 )
end
#Create a global instance of Perforce to check out header files.
config = Pipeline::Config.instance
@@p4 = SCM::Perforce.new()
@@p4.port = config.sc_server
@@p4.client = config.sc_workspace
@@p4.user = config.sc_username
@@p4.connect()
@@p4.run_edit( version_header_path )
#Parse the header for the current version numbers.
version_lines = File.readlines(version_header_path)
rage_release_id = "RAGE_RELEASE"
rage_major_version_id = "RAGE_MAJOR_VERSION"
rage_minor_version_id = "RAGE_MINOR_VERSION"
define_token = "#define "
release_number = nil
minor_version = nil
major_version = nil
version_lines.each do |line|
tokens = line.split(" ")
#Parse a line that looks like "#define RAGE_MINOR_VERSION 15"
if tokens.size > 2
if tokens[1].eql?(rage_release_id)
release_number = tokens[2]
elsif tokens[1].eql?(rage_minor_version_id)
minor_version = tokens[2]
elsif tokens[1].eql?(rage_major_version_id)
major_version = tokens[2]
end
end
end
if release_number.nil? or minor_version.nil? or major_version.nil?
print "Release Number, Minor Version or Major Version tokens could not be found when parsing #{version_header_path}! Unable to continue...\n"
exit( 1 )
end
version_string = "#{major_version}.#{minor_version}.#{release_number}.*"
print "File Path: #{file_path}\n"
write_assembly_info_file(company_name, version_string, file_path.to_s )
print "Successfully generated #{file_path}!\n"