22 Generate a C header file defining some information about the build. 31 Run a command with subprocess and return the stdout. 33 Avoiding use of subprocess.check_output to maintain backwards 36 proc = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE)
37 out = proc.communicate()
38 if proc.returncode != 0:
39 tpl =
'execution of command "{0}" failed' 40 raise Exception(tpl.format(
' '.join(cmd)))
45 Determine the locale to use in SVN. 50 for line
in run([
'locale',
'-a']).split(
'\n'):
54 if entry.startswith(
'en'):
57 if entry.startswith(
'de'):
67 SVN_NAME_MAPPING = {
'Révision':
'Revision'}
69 def svn(directory='.'):
71 Get information about the SVN repository. 73 Uses the --show-item syntax instead of parsing the normal svn info output 74 to avoid issues with language locales. 77 start_wd = os.getcwd()
80 result =
run([
'svn',
'info'], env={
'LC_MESSAGES':
locale()})
85 for line
in result.split(
'\n'):
88 name, value = line.split(
': ')
93 name = SVN_NAME_MAPPING.get(name.strip(), name.strip())
94 name = name.lower().replace(
' ',
'-')
96 info[name] = value.strip()
98 if name ==
'revision':
99 info[
'commit'] = info[name]
104 start_wd = os.getcwd()
109 result =
run([
'git',
'rev-list',
'--all',
'--count'])
110 info[
'revision'] = str(int(result));
113 result =
run([
'git',
'rev-parse',
'HEAD'])
114 result = result[0:len(result)-1]
115 info[
'commit'] = result.decode(
'ascii')
118 result =
run([
'git',
'describe',
'--tags',
'--always'])
119 result = result[0:len(result)-1]
120 info[
'tag'] = result.decode(
'ascii')
123 result =
run([
'git',
'remote',
'-v'])
125 for line
in result.decode(
'ascii').split(
'\n'):
126 line =
' '.join(line.split())
129 alias, path, direction = line.split(
' ')
133 if alias ==
'origin':
137 info[
'subrepo'] =
'.' 145 TEMPLATE =
"""#ifndef __BUILD_INFO__ 146 #define __BUILD_INFO__ 148 #define GIT_COMMIT_TAG "{tag}" 149 #define GIT_COMMIT_HASH "{commit}" 150 #define GIT_COMMIT_COUNT {revision} 151 #define GIT_PATH "{url}" 153 #define SUBREPO_REVISIONS "{subrepo}" 155 #define SUBREPO_COMMITS "{subrepocommit}" 163 if subprocess.call([
"git",
"branch"], stderr=subprocess.STDOUT, stdout=open(os.devnull,
'w')) == 0:
164 info =
git(os.path.dirname(os.path.abspath(__file__)))
174 info[
'subrepo'] =
','.join([
'{0[0]}={0[1]}'.format(v)
for v
in repo_versions])
177 newline =
'," \\\n' +
' ' * 24 +
'"' 178 info[
'subrepocommit'] = newline.join([
'{0[0]}={0[1]}'.format(v)
for v
in repo_commits])
182 info[
'tag'] =
"built outside a repository" 183 info[
'commit'] =
"built outside a repository" 185 info[
'url'] =
"https://git.opencarp.org/openCARP/openCARP.git" 187 info[
'subrepocommit'] =
"" 189 return TEMPLATE.format(**info)
199 if os.path.isfile(filename):
200 with open(filename,
'r') as myfile: 201 info_h = myfile.read() 202 if info_h == git_info:
207 f = open(filename,
"w")
210 if __name__ ==
'__main__':
211 if(len(sys.argv) > 1):
212 filename = sys.argv[1]
214 filename =
'build_info.h' def print_build_info(filename)