Switch build infrastructure to Git.

This commit is contained in:
David Anderson
2014-05-25 01:53:58 -07:00
parent e20e4677df
commit 2e89d91a86
5 changed files with 92 additions and 60 deletions
+9 -2
View File
@@ -16,11 +16,18 @@ outputs = [
os.path.join(builder.buildFolder, 'includes', 'version_auto.inc'),
]
with open(os.path.join(builder.sourcePath, '.git', 'HEAD')) as fp:
git_state = fp.read().strip().split(':')[1].strip()
git_head_path = os.path.join(builder.sourcePath, '.git', git_state)
if not os.path.exists(git_head_path):
git_head_path = os.path.join(builder.sourcePath, '.git', 'HEAD')
sources = [
os.path.join(builder.sourcePath, 'product.version'),
# This is a hack, but we need some way to only run this script when HG changes.
os.path.join(builder.sourcePath, '.hg', 'dirstate'),
# This is a hack, but we need some way to only run this script when Git changes.
git_head_path,
# The script source is a dependency, of course...
argv[1]
+37 -24
View File
@@ -11,9 +11,19 @@ if len(argv) < 2:
SourceFolder = os.path.abspath(os.path.normpath(argv[0]))
OutputFolder = os.path.normpath(argv[1])
def get_hg_version():
argv = ['hg', 'parent', '-R', SourceFolder]
class FolderChanger:
def __init__(self, folder):
self.old = os.getcwd()
self.new = folder
def __enter__(self):
if self.new:
os.chdir(self.new)
def __exit__(self, type, value, traceback):
os.chdir(self.old)
def run_and_return(argv):
# Python 2.6 doesn't have check_output.
if hasattr(subprocess, 'check_output'):
text = subprocess.check_output(argv)
@@ -26,14 +36,18 @@ def get_hg_version():
if rval:
raise subprocess.CalledProcessError(rval, argv)
text = output.decode('utf8')
return text.strip()
m = re.match('changeset:\s+(\d+):(.+)', text)
if m == None:
raise Exception('Could not determine repository version')
return m.groups()
def get_git_version():
revision_count = run_and_return(['git', 'rev-list', '--count', 'HEAD'])
revision_hash = run_and_return(['git', 'log', '--pretty=format:%h:%H', '-n', '1'])
shorthash, longhash = revision_hash.split(':')
return revision_count, shorthash, longhash
def output_version_headers():
rev, cset = get_hg_version()
with FolderChanger(SourceFolder):
count, shorthash, longhash = get_git_version()
with open(os.path.join(SourceFolder, 'product.version')) as fp:
contents = fp.read()
@@ -41,11 +55,12 @@ def output_version_headers():
if m == None:
raise Exception('Could not detremine product version')
major, minor, release, tag = m.groups()
fullstring = "{0}.{1}.{2}".format(major, minor, release)
product = "{0}.{1}.{2}".format(major, minor, release)
fullstring = product
if tag != "":
fullstring += "-{0}".format(tag)
if tag == "dev":
fullstring += "+{0}".format(rev)
fullstring += "+{0}".format(shorthash)
with open(os.path.join(OutputFolder, 'sourcemod_version_auto.h'), 'w') as fp:
fp.write("""
@@ -53,19 +68,18 @@ def output_version_headers():
#define _SOURCEMOD_AUTO_VERSION_INFORMATION_H_
#define SM_BUILD_TAG \"{0}\"
#define SM_BUILD_REV \"{1}\"
#define SM_BUILD_CSET \"{2}\"
#define SM_BUILD_MAJOR \"{3}\"
#define SM_BUILD_MINOR \"{4}\"
#define SM_BUILD_RELEASE \"{5}\"
#define SM_BUILD_CSET \"{1}\"
#define SM_BUILD_MAJOR \"{2}\"
#define SM_BUILD_MINOR \"{3}\"
#define SM_BUILD_RELEASE \"{4}\"
#define SM_BUILD_UNIQUEID SM_BUILD_REV \":\" SM_BUILD_CSET
#define SM_VERSION_STRING \"{6}\"
#define SM_VERSION_FILE {7},{8},{9},0
#define SM_VERSION_STRING \"{5}\"
#define SM_VERSION_FILE {6},{7},{8},0
#endif /* _SOURCEMOD_AUTO_VERSION_INFORMATION_H_ */
""".format(tag, rev, cset, major, minor, release, fullstring, major, minor, release))
""".format(tag, shorthash, major, minor, release, fullstring, major, minor, release))
with open(os.path.join(OutputFolder, 'version_auto.inc'), 'w') as fp:
fp.write("""
@@ -75,13 +89,12 @@ def output_version_headers():
#define _auto_version_included
#define SOURCEMOD_V_TAG \"{0}\"
#define SOURCEMOD_V_REV {1}
#define SOURCEMOD_V_CSET \"{2}\"
#define SOURCEMOD_V_MAJOR {3}
#define SOURCEMOD_V_MINOR {4}
#define SOURCEMOD_V_RELEASE {5}
#define SOURCEMOD_V_CSET \"{1}\"
#define SOURCEMOD_V_MAJOR {2}
#define SOURCEMOD_V_MINOR {3}
#define SOURCEMOD_V_RELEASE {4}
#define SOURCEMOD_VERSION \"{6}\"
""".format(tag, rev, cset, major, minor, release, fullstring))
#define SOURCEMOD_VERSION \"{5}\"
""".format(tag, shorthash, major, minor, release, fullstring))
output_version_headers()
+31 -15
View File
@@ -17,7 +17,7 @@ elif [ `uname` != "Linux" ] && [ -n "${COMSPEC:+1}" ]; then
decomp=unzip
fi
if [ ! -d "sourcemod-central" ]; then
if [ ! -d "sourcemod" ]; then
if [ ! -d "sourcemod-1.5" ]; then
echo "Could not find a SourceMod repository; make sure you aren't running this script inside it."
exit 1
@@ -54,29 +54,32 @@ fi
checkout ()
{
if [ ! -d "$name" ]; then
hg clone https://hg.alliedmods.net/$path/$name
git clone $repo -b $branch $name
if [ -n "$origin" ]; then
cd $name
git remote rm origin
git remote add origin $origin
cd ..
fi
else
cd $name
sed -i 's/http:/https:/g' .hg/hgrc
hg pull -u
git checkout $branch
git pull origin $branch
cd ..
fi
}
name=mmsource-1.10
path=releases
branch=1.10-dev
repo="https://github.com/alliedmodders/metamod-source"
origin=
checkout
sdks=( csgo hl2dm nd l4d2 dods l4d css tf2 insurgency 2013 dota )
sdks=( csgo hl2dm nucleardawn l4d2 dods l4d css tf2 insurgency sdk2013 dota )
if [ $ismac -eq 0 ]; then
# Checkout original HL2 SDK on Windows or Linux
name=hl2sdk
path=hl2sdks
checkout
# Add these SDKs for Windows or Linux
sdks+=( ob blade )
sdks+=( orangebox blade episode1 )
# Add more SDKs for Windows only
if [ $iswin -eq 1 ]; then
@@ -84,17 +87,30 @@ if [ $ismac -eq 0 ]; then
fi
fi
# Check out a local copy as a proxy.
if [ ! -d "hl2sdk-proxy-repo" ]; then
git clone --mirror https://github.com/alliedmodders/hl2sdk hl2sdk-proxy-repo
else
cd hl2sdk-proxy-repo
git fetch
cd ..
fi
for sdk in "${sdks[@]}"
do
repo=hl2sdk-proxy-repo
origin="https://github.com/alliedmodders/hl2sdk"
name=hl2sdk-$sdk
path=hl2sdks
branch=$sdk
checkout
done
`python -c "import ambuild2"`
if [ $? -eq 1 ]; then
name=
path=ambuild
repo="https://github.com/alliedmodders/ambuild"
origin=
branch=master
name=ambuild
checkout
cd ambuild