# # The EC system generates a Version file that looks like this: # # RELEASE = 2015 1 ; # PATCHLEVEL = 1054991 ; # SUPPDATE = 2015 05 05 ; # # For locally run tests, it looks like this: # # RELEASE = 2099 9 main ; # PATCHLEVEL = 9999999 ; # SUPPDATE = 2099 09 09 ; # # We have two kinds of version strings we basically will generate: # # 1. The official P4Ruby string will be "RELEASE[0].RELEASE[1].PATCHLEVEL", # e.g., '2015.1.1054991' from the Version file example above # # If a Version file exists, but, has a third argument, we then use the third # argument as an "alpha" tag, e.g., '' # # If no Version file exists, we default things out to our "test" values. # DEFAULT_YEAR = '2099' DEFAULT_REV = '9' DEFAULT_CHANGELIST = '9999999' DEFAULT_BRANCH = 'test' VERSION_PATH = File.absolute_path('../../../p4/Version', __FILE__) class P4 if File.exists?(VERSION_PATH) vals = {} IO.readlines(VERSION_PATH).each do |line| if /^(?\w+) = (?.*) ;$/ =~ line vals[key] = value.strip.split(/\s+/) end end year = DEFAULT_YEAR if vals.key?('RELEASE') and vals['RELEASE'].length > 0 year = vals['RELEASE'][0] end rev = DEFAULT_REV if vals.key?('RELEASE') and vals['RELEASE'].length > 1 rev = vals['RELEASE'][1] end branch = DEFAULT_BRANCH if vals.key?('RELEASE') and vals['RELEASE'].length > 2 branch = vals['RELEASE'][2] elsif vals.key?('RELEASE') and vals['RELEASE'].length == 2 branch = nil end change = DEFAULT_CHANGELIST if vals.key?('PATCHLEVEL') change = vals['PATCHLEVEL'][0] end if branch Version = VERSION = "#{year}.#{rev}.0.#{branch}#{change}" else Version = VERSION = "#{year}.#{rev}.#{change}" end else Version = VERSION = "#{DEFAULT_YEAR}.#{DEFAULT_REV}.0.#{DEFAULT_BRANCH}#{DEFAULT_CHANGELIST}" end end