forked from rcbotCheeseh/rcbot2
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We use a link to build_info to avoid regenerating every file depending on bot_const.h after every update. Versioning based off of SourceMod. Closes rcbotCheeseh#5.
- Loading branch information
Showing
8 changed files
with
123 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# vim: set ts=8 sts=2 sw=2 tw=99 et ft=python: | ||
import os, sys | ||
import re | ||
|
||
builder.SetBuildFolder('/') | ||
|
||
includes = builder.AddFolder('includes/version') | ||
|
||
argv = [ | ||
sys.executable, | ||
os.path.join(builder.sourcePath, 'versioning', 'generate.py'), | ||
os.path.join(builder.sourcePath), | ||
os.path.join(builder.buildPath, 'includes'), | ||
] | ||
outputs = [ | ||
os.path.join(builder.buildFolder, 'includes', 'build_version_auto.h'), | ||
] | ||
|
||
with open(os.path.join(builder.sourcePath, '.git', 'HEAD')) as fp: | ||
head_contents = fp.read().strip() | ||
if re.search('^[a-fA-F0-9]{40}$', head_contents): | ||
git_head_path = os.path.join(builder.sourcePath, '.git', 'HEAD') | ||
else: | ||
git_state = head_contents.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 = [ | ||
# 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] | ||
] | ||
cmd_node, output_nodes = builder.AddCommand( | ||
inputs=sources, | ||
argv=argv, | ||
outputs=outputs | ||
) | ||
|
||
rvalue = output_nodes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include "build_info.h" | ||
|
||
// generated with versioning/generate.py, AMBuild handles this | ||
#include <build_version_auto.h> | ||
|
||
const char* build_info::authors = "Cheeseh, RoboCop, nosoop"; | ||
const char* build_info::url = "http://rcbot.bots-united.com/"; | ||
|
||
const char* build_info::long_version = "nosoop/rcbot2@" GIT_COMMIT_HASH; | ||
const char* build_info::short_version = "nosoop@" GIT_COMMIT_SHORT_HASH; | ||
|
||
const char* build_info::date = __DATE__; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef __RCBOT_VERSION_STUB_H__ | ||
#define __RCBOT_VERSION_STUB_H__ | ||
|
||
namespace build_info { | ||
extern const char* authors; | ||
extern const char* url; | ||
|
||
extern const char* long_version; | ||
extern const char* short_version; | ||
|
||
extern const char* date; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/python3 | ||
|
||
import subprocess | ||
|
||
output_filename = 'build_version_auto.h' | ||
|
||
def git_version(): | ||
return subprocess.check_output(['git', 'log', '--pretty=format:%H', '-n', '1']).decode('ascii') | ||
|
||
if __name__ == '__main__': | ||
import argparse, re, collections, functools, os, textwrap | ||
from string import Template | ||
|
||
parser = argparse.ArgumentParser(description = "Generates git snapshot headers.", | ||
usage = "%(prog)s [options]") | ||
|
||
parser.add_argument('source_dir', help="Source directory") | ||
parser.add_argument('output_dir', help="Output directory") | ||
|
||
args = parser.parse_args() | ||
|
||
source_directory = os.path.abspath(os.path.normpath(args.source_dir)) | ||
output_directory = os.path.normpath(args.output_dir) | ||
with open(os.path.join(output_directory, output_filename), 'wt') as f: | ||
values = { | ||
'git_hash': git_version(), | ||
'git_short_hash': git_version()[:8] | ||
} | ||
f.write(textwrap.dedent(""" | ||
#if defined _auto_version_included | ||
#endinput | ||
#endif | ||
#define _auto_version_included | ||
#define GIT_COMMIT_HASH "{git_hash}" | ||
#define GIT_COMMIT_SHORT_HASH "{git_short_hash}" | ||
""".format(**values))[1:]) |