1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/buildbot/Versioning Sat Apr 16 00:41:25 2011 -0700
1.3 @@ -0,0 +1,57 @@
1.4 +# vim: set ts=2 sw=2 tw=99 noet ft=python:
1.5 +import os
1.6 +import re
1.7 +import subprocess
1.8 +from ambuild.cache import Cache
1.9 +import ambuild.command as command
1.10 +
1.11 +#Quickly try to ascertain the current repository revision
1.12 +def GetVersion():
1.13 + args = ['hg', 'parent', '-R', AMBuild.sourceFolder]
1.14 + p = command.RunDirectCommand(AMBuild, args)
1.15 + m = re.match('changeset:\s+(\d+):(.+)', p.stdoutText)
1.16 + if m == None:
1.17 + raise Exception('Could not determine repository version')
1.18 + return m.groups()
1.19 +
1.20 +def PerformReversioning():
1.21 + rev, cset = GetVersion()
1.22 + cacheFile = os.path.join(AMBuild.outputFolder, '.ambuild', 'hgcache')
1.23 + cache = Cache(cacheFile)
1.24 + if os.path.isfile(cacheFile):
1.25 + cache.LoadCache()
1.26 + if cache.HasVariable('cset') and cache['cset'] == cset:
1.27 + return False
1.28 + cache.CacheVariable('cset', cset)
1.29 +
1.30 + productFile = open(os.path.join(AMBuild.sourceFolder, 'product.version'), 'r')
1.31 + productContents = productFile.read()
1.32 + productFile.close()
1.33 + m = re.match('(\d+)\.(\d+)\.(\d+)(.*)', productContents)
1.34 + if m == None:
1.35 + raise Exception('Could not detremine product version')
1.36 + major, minor, release, tag = m.groups()
1.37 +
1.38 + incFolder = os.path.join(AMBuild.outputFolder, 'includes')
1.39 + if not os.path.isdir(incFolder):
1.40 + os.makedirs(incFolder)
1.41 + incFile = open(os.path.join(incFolder, 'cssdm_version_auto.h'), 'w')
1.42 + incFile.write("""
1.43 +#ifndef _CSSDM_AUTO_VERSION_INFORMATION_H_
1.44 +#define _CSSDM_AUTO_VERSION_INFORMATION_H_
1.45 +
1.46 +#define CSSDM_BUILD_STRING \"{0}\"
1.47 +#define CSSDM_BUILD_UNIQUEID \"{1}:{2}\" CSSDM_BUILD_STRING
1.48 +#define CSSDM_FULL_VERSION \"{3}.{4}.{5}\" CSSDM_BUILD_STRING
1.49 +#define CSSDM_FILE_VERSION {6},{7},{8},0
1.50 +
1.51 +#endif /* _CSSDM_AUTO_VERSION_INFORMATION_H_ */
1.52 +
1.53 +""".format(tag, rev, cset, major, minor, release, major, minor, release))
1.54 + incFile.close()
1.55 +
1.56 + cache.WriteCache()
1.57 +
1.58 +PerformReversioning()
1.59 +
1.60 +