Adding build version information to main window/log.
This commit is contained in:
52
xenia-build
52
xenia-build
@@ -178,6 +178,57 @@ def shell_call(command, throw_on_error=True, stdout_path=None):
|
||||
return result
|
||||
|
||||
|
||||
def get_git_head_info():
|
||||
"""Queries the current branch and commit checksum from git.
|
||||
|
||||
Returns:
|
||||
(branch_name, commit, commit_short)
|
||||
If the user is not on any branch the name will be 'detached'.
|
||||
"""
|
||||
p = subprocess.Popen([
|
||||
'git',
|
||||
'symbolic-ref',
|
||||
'--short',
|
||||
'-q',
|
||||
'HEAD',
|
||||
], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
(stdout, stderr) = p.communicate()
|
||||
branch_name = stdout.strip() or 'detached'
|
||||
p = subprocess.Popen([
|
||||
'git',
|
||||
'rev-parse',
|
||||
'HEAD',
|
||||
], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
(stdout, stderr) = p.communicate()
|
||||
commit = stdout.strip() or 'unknown'
|
||||
p = subprocess.Popen([
|
||||
'git',
|
||||
'rev-parse',
|
||||
'--short',
|
||||
'HEAD',
|
||||
], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
(stdout, stderr) = p.communicate()
|
||||
commit_short = stdout.strip() or 'unknown'
|
||||
return (branch_name, commit, commit_short)
|
||||
|
||||
|
||||
def generate_version_h():
|
||||
"""Generates a build/version.h file that contains current git info.
|
||||
"""
|
||||
(branch_name, commit, commit_short) = get_git_head_info()
|
||||
contents = '''// Autogenerated by `xb premake`.
|
||||
#ifndef GENERATED_VERSION_H_
|
||||
#define GENERATED_VERSION_H_
|
||||
#define XE_BUILD_BRANCH "%s"
|
||||
#define XE_BUILD_COMMIT "%s"
|
||||
#define XE_BUILD_COMMIT_SHORT "%s"
|
||||
#define XE_BUILD_DATE __DATE__
|
||||
#endif // GENERATED_VERSION_H_
|
||||
''' % (branch_name, commit, commit_short)
|
||||
with open('build/version.h', 'w') as f:
|
||||
f.write(contents)
|
||||
|
||||
|
||||
def git_submodule_update():
|
||||
"""Runs a full recursive git submodule init and update.
|
||||
|
||||
@@ -253,6 +304,7 @@ def run_premake(target_os, action):
|
||||
'--verbose',
|
||||
action,
|
||||
])
|
||||
generate_version_h()
|
||||
|
||||
|
||||
def run_premake_clean():
|
||||
|
||||
Reference in New Issue
Block a user