1 # vim: set ts=2 sw=2 tw=99 noet ft=python:
5 from ambuild.cache import Cache
6 import ambuild.command as command
8 #Quickly try to ascertain the current repository revision
10 args = ['hg', 'parent', '-R', AMBuild.sourceFolder]
11 p = command.RunDirectCommand(AMBuild, args)
12 m = re.match('changeset:\s+(\d+):(.+)', p.stdoutText)
14 raise Exception('Could not determine repository version')
17 def PerformReversioning():
18 rev, cset = GetVersion()
19 cacheFile = os.path.join(AMBuild.outputFolder, '.ambuild', 'hgcache')
20 cache = Cache(cacheFile)
21 if os.path.isfile(cacheFile):
23 if cache.HasVariable('cset') and cache['cset'] == cset:
25 cache.CacheVariable('cset', cset)
27 productFile = open(os.path.join(AMBuild.sourceFolder, 'product.version'), 'r')
28 productContents = productFile.read()
30 m = re.match('(\d+)\.(\d+)\.(\d+)(.*)', productContents)
32 raise Exception('Could not detremine product version')
33 major, minor, release, tag = m.groups()
35 incFolder = os.path.join(AMBuild.outputFolder, 'includes')
36 if not os.path.isdir(incFolder):
37 os.makedirs(incFolder)
38 incFile = open(os.path.join(incFolder, 'cssdm_version_auto.h'), 'w')
40 #ifndef _CSSDM_AUTO_VERSION_INFORMATION_H_
41 #define _CSSDM_AUTO_VERSION_INFORMATION_H_
43 #define CSSDM_BUILD_STRING \"{0}\"
44 #define CSSDM_BUILD_UNIQUEID \"{1}:{2}\" CSSDM_BUILD_STRING
45 #define CSSDM_FULL_VERSION \"{3}.{4}.{5}\" CSSDM_BUILD_STRING
46 #define CSSDM_FILE_VERSION {6},{7},{8},0
48 #endif /* _CSSDM_AUTO_VERSION_INFORMATION_H_ */
50 """.format(tag, rev, cset, major, minor, release, major, minor, release))