21 Generate a C header file defining some information about the build.
30 Run a command with subprocess and return the stdout.
32 Avoiding use of subprocess.check_output to maintain backwards
35 proc = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE)
36 out = proc.communicate()
37 if proc.returncode != 0:
38 tpl =
'execution of command "{0}" failed'
39 raise Exception(tpl.format(
' '.join(cmd)))
44 Determine the locale to use in SVN.
49 for line
in run([
'locale',
'-a']).split(
'\n'):
53 if entry.startswith(
'en'):
56 if entry.startswith(
'de'):
66 SVN_NAME_MAPPING = {
'Révision':
'Revision'}
68 def svn(directory='.'):
70 Get information about the SVN repository.
72 Uses the --show-item syntax instead of parsing the normal svn info output
73 to avoid issues with language locales.
76 start_wd = os.getcwd()
79 result =
run([
'svn',
'info'], env={
'LC_MESSAGES':
locale()})
84 for line
in result.split(
'\n'):
87 name, value = line.split(
': ')
92 name = SVN_NAME_MAPPING.get(name.strip(), name.strip())
93 name = name.lower().replace(
' ',
'-')
95 info[name] = value.strip()
97 if name ==
'revision':
98 info[
'commit'] = info[name]
103 start_wd = os.getcwd()
108 result =
run([
'git',
'rev-list',
'--all',
'--count'])
109 info[
'revision'] = str(int(result));
112 result =
run([
'git',
'rev-parse',
'HEAD'])
113 result = result[0:len(result)-1]
114 info[
'commit'] = result.decode(
'ascii')
117 result =
run([
'git',
'describe',
'--tags',
'--always'])
118 result = result[0:len(result)-1]
119 info[
'tag'] = result.decode(
'ascii')
122 result =
run([
'git',
'remote',
'-v'])
124 for line
in result.decode(
'ascii').split(
'\n'):
125 line =
' '.join(line.split())
128 alias, path, direction = line.split(
' ')
132 if alias ==
'origin':
136 info[
'subrepo'] =
'.'
144 TEMPLATE =
"""#ifndef __BUILD_INFO__
145 #define __BUILD_INFO__
147 #define GIT_COMMIT_TAG "{tag}"
148 #define GIT_COMMIT_HASH "{commit}"
149 #define GIT_COMMIT_COUNT {revision}
150 #define GIT_PATH "{url}"
152 #define SUBREPO_REVISIONS "{subrepo}"
154 #define SUBREPO_COMMITS "{subrepocommit}"
161 info =
git(os.path.dirname(os.path.abspath(__file__)))
172 info[
'subrepo'] =
','.join([
'{0[0]}={0[1]}'.format(v)
for v
in repo_versions])
175 newline =
'," \\\n' +
' ' * 24 +
'"'
176 info[
'subrepocommit'] = newline.join([
'{0[0]}={0[1]}'.format(v)
for v
in repo_commits])
178 return TEMPLATE.format(**info)
188 if os.path.isfile(filename):
189 with open(filename,
'r')
as myfile:
190 info_h = myfile.read()
191 if info_h == git_info:
196 f = open(filename,
"w")
199 if __name__ ==
'__main__':
200 if(len(sys.argv) > 1):
201 filename = sys.argv[1]
203 filename =
'build_info.h'
def print_build_info(filename)