support/buildbot/Versioning
author Scott Ehlert <ds@alliedmods.net>
Sat May 22 00:45:44 2010 -0500 (2010-05-22)
changeset 716 6925fbd2b9fa
parent 704 6055e296b807
child 870 004b1437bd14
permissions -rw-r--r--
Added Mac OS X build support to stub/sample plugin makefiles (bug 4391, r=dvander).
ds@704
     1
# vim: set ts=2 sw=2 tw=99 noet ft=python: 
ds@704
     2
import os
ds@704
     3
import re
ds@704
     4
import subprocess
ds@704
     5
from ambuild.cache import Cache
ds@704
     6
import ambuild.command as command
ds@704
     7
ds@704
     8
#Quickly try to ascertain the current repository revision
ds@704
     9
def GetVersion():
ds@704
    10
	args = ['hg', 'parent', '-R', AMBuild.sourceFolder]
ds@704
    11
	p = command.RunDirectCommand(AMBuild, args)
ds@704
    12
	m = re.match('changeset:\s+(\d+):(.+)', p.stdoutText)
ds@704
    13
	if m == None:
ds@704
    14
		raise Exception('Could not determine repository version')
ds@704
    15
	return m.groups()
ds@704
    16
ds@704
    17
def PerformReversioning():
ds@704
    18
	rev, cset = GetVersion()
ds@704
    19
	cacheFile = os.path.join(AMBuild.outputFolder, '.ambuild', 'hgcache')
ds@704
    20
	cache = Cache(cacheFile)
ds@704
    21
	if os.path.isfile(cacheFile):
ds@704
    22
		cache.LoadCache()
ds@704
    23
		if cache.HasVariable('cset') and cache['cset'] == cset:
ds@704
    24
			return False
ds@704
    25
	cache.CacheVariable('cset', cset)
ds@704
    26
ds@704
    27
	productFile = open(os.path.join(AMBuild.sourceFolder, 'product.version'), 'r')
ds@704
    28
	productContents = productFile.read()
ds@704
    29
	productFile.close()
ds@704
    30
	m = re.match('(\d+)\.(\d+)\.(\d+)(.*)', productContents)
ds@704
    31
	if m == None:
ds@704
    32
		raise Exception('Could not detremine product version')
ds@704
    33
	major, minor, release, tag = m.groups()
ds@704
    34
ds@704
    35
	incFolder = os.path.join(AMBuild.outputFolder, 'includes')
ds@704
    36
	if not os.path.isdir(incFolder):
ds@704
    37
		os.makedirs(incFolder)
ds@704
    38
	incFile = open(os.path.join(incFolder, 'metamod_version_auto.h'), 'w')
ds@704
    39
	incFile.write("""
ds@704
    40
#ifndef _METAMOD_AUTO_VERSION_INFORMATION_H_
ds@704
    41
#define _METAMOD_AUTO_VERSION_INFORMATION_H_
ds@704
    42
ds@704
    43
#define MMS_BUILD_STRING 		\"{0}\"
ds@704
    44
#define MMS_BUILD_UNIQUEID		\"{1}:{2}\" MMS_BUILD_STRING
ds@704
    45
#define MMS_FULL_VERSION		\"{3}.{4}.{5}\" MMS_BUILD_STRING
ds@704
    46
#define MMS_FILE_VERSION		{6},{7},{8},0
ds@704
    47
ds@704
    48
#endif /* _METAMOD_AUTO_VERSION_INFORMATION_H_ */
ds@704
    49
ds@704
    50
""".format(tag, rev, cset, major, minor, release, major, minor, release))
ds@704
    51
	incFile.close()
ds@704
    52
ds@704
    53
	cache.WriteCache()
ds@704
    54
ds@704
    55
PerformReversioning()
ds@704
    56
ds@704
    57