Allow building without git.
This commit is contained in:
parent
9bbe4365d1
commit
adebaba799
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright 2015 Ben Vanik. All Rights Reserved.
|
||||
|
||||
|
@ -107,13 +107,14 @@ def has_bin(bin):
|
|||
return None
|
||||
|
||||
|
||||
def shell_call(command, throw_on_error=True, stdout_path=None):
|
||||
def shell_call(command, throw_on_error=True, stdout_path=None, stderr_path=None, shell=False):
|
||||
"""Executes a shell command.
|
||||
|
||||
Args:
|
||||
command: Command to execute, as a list of parameters.
|
||||
throw_on_error: Whether to throw an error or return the status code.
|
||||
stdout_path: File path to write stdout output to.
|
||||
stderr_path: File path to write stderr output to.
|
||||
|
||||
Returns:
|
||||
If throw_on_error is False the status code of the call will be returned.
|
||||
|
@ -121,17 +122,22 @@ def shell_call(command, throw_on_error=True, stdout_path=None):
|
|||
stdout_file = None
|
||||
if stdout_path:
|
||||
stdout_file = open(stdout_path, 'w')
|
||||
stderr_file = None
|
||||
if stderr_path:
|
||||
stderr_file = open(stderr_path, 'w')
|
||||
result = 0
|
||||
try:
|
||||
if throw_on_error:
|
||||
result = 1
|
||||
subprocess.check_call(command, shell=False, stdout=stdout_file)
|
||||
subprocess.check_call(command, shell=shell, stdout=stdout_file, stderr=stderr_file)
|
||||
result = 0
|
||||
else:
|
||||
result = subprocess.call(command, shell=False, stdout=stdout_file)
|
||||
result = subprocess.call(command, shell=shell, stdout=stdout_file, stderr=stderr_file)
|
||||
finally:
|
||||
if stdout_file:
|
||||
stdout_file.close()
|
||||
if stderr_file:
|
||||
stderr_file.close()
|
||||
return result
|
||||
|
||||
|
||||
|
@ -196,42 +202,5 @@ def import_subprocess_environment(args):
|
|||
os.environ[var.upper()] = setting
|
||||
break
|
||||
|
||||
def git_submodule_update():
|
||||
"""Runs a full recursive git submodule init and update.
|
||||
|
||||
Older versions of git do not support 'update --init --recursive'. We could
|
||||
check and run it on versions that do support it and speed things up a bit.
|
||||
"""
|
||||
if True:
|
||||
shell_call([
|
||||
'git',
|
||||
'submodule',
|
||||
'update',
|
||||
'--init',
|
||||
'--recursive',
|
||||
])
|
||||
else:
|
||||
shell_call([
|
||||
'git',
|
||||
'submodule',
|
||||
'init',
|
||||
])
|
||||
shell_call([
|
||||
'git',
|
||||
'submodule',
|
||||
'foreach',
|
||||
'--recursive',
|
||||
'git',
|
||||
'submodule',
|
||||
'init',
|
||||
])
|
||||
shell_call([
|
||||
'git',
|
||||
'submodule',
|
||||
'update',
|
||||
'--recursive',
|
||||
])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
111
xenia-build
111
xenia-build
|
@ -34,8 +34,11 @@ def main():
|
|||
|
||||
# Check git exists.
|
||||
if not has_bin('git'):
|
||||
print('ERROR: git must be installed and on PATH.')
|
||||
sys.exit(1)
|
||||
print('WARNING: Git should be installed and on PATH. Version info will be omitted from all binaries!')
|
||||
print('')
|
||||
elif not git_is_repository():
|
||||
print('WARNING: The source tree is unversioned. Version info will be omitted from all binaries!')
|
||||
print('')
|
||||
|
||||
# Check python version.
|
||||
if not sys.version_info[:2] >= (3, 6):
|
||||
|
@ -185,13 +188,14 @@ def get_bin(binary):
|
|||
return None
|
||||
|
||||
|
||||
def shell_call(command, throw_on_error=True, stdout_path=None, shell=False):
|
||||
def shell_call(command, throw_on_error=True, stdout_path=None, stderr_path=None, shell=False):
|
||||
"""Executes a shell command.
|
||||
|
||||
Args:
|
||||
command: Command to execute, as a list of parameters.
|
||||
throw_on_error: Whether to throw an error or return the status code.
|
||||
stdout_path: File path to write stdout output to.
|
||||
stderr_path: File path to write stderr output to.
|
||||
|
||||
Returns:
|
||||
If throw_on_error is False the status code of the call will be returned.
|
||||
|
@ -199,21 +203,49 @@ def shell_call(command, throw_on_error=True, stdout_path=None, shell=False):
|
|||
stdout_file = None
|
||||
if stdout_path:
|
||||
stdout_file = open(stdout_path, 'w')
|
||||
stderr_file = None
|
||||
if stderr_path:
|
||||
stderr_file = open(stderr_path, 'w')
|
||||
result = 0
|
||||
try:
|
||||
if throw_on_error:
|
||||
result = 1
|
||||
subprocess.check_call(command, shell=shell, stdout=stdout_file)
|
||||
subprocess.check_call(command, shell=shell, stdout=stdout_file, stderr=stderr_file)
|
||||
result = 0
|
||||
else:
|
||||
result = subprocess.call(command, shell=shell, stdout=stdout_file)
|
||||
result = subprocess.call(command, shell=shell, stdout=stdout_file, stderr=stderr_file)
|
||||
finally:
|
||||
if stdout_file:
|
||||
stdout_file.close()
|
||||
if stderr_file:
|
||||
stderr_file.close()
|
||||
return result
|
||||
|
||||
|
||||
def get_git_head_info():
|
||||
def generate_version_h():
|
||||
"""Generates a build/version.h file that contains current git info.
|
||||
"""
|
||||
if git_is_repository():
|
||||
(branch_name, commit, commit_short) = git_get_head_info()
|
||||
else:
|
||||
branch_name = 'tarball'
|
||||
commit = ':(-dont-do-this'
|
||||
commit_short = ':('
|
||||
|
||||
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_get_head_info():
|
||||
"""Queries the current branch and commit checksum from git.
|
||||
|
||||
Returns:
|
||||
|
@ -247,58 +279,28 @@ def get_git_head_info():
|
|||
return branch_name, commit, commit_short
|
||||
|
||||
|
||||
def generate_version_h():
|
||||
"""Generates a build/version.h file that contains current git info.
|
||||
def git_is_repository():
|
||||
"""Checks if git is available and this source tree is versioned.
|
||||
"""
|
||||
(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)
|
||||
if not has_bin('git'):
|
||||
return False
|
||||
return shell_call([
|
||||
'git',
|
||||
'rev-parse',
|
||||
'--is-inside-work-tree',
|
||||
], throw_on_error=False, stdout_path=os.devnull, stderr_path=os.devnull) == 0
|
||||
|
||||
|
||||
def git_submodule_update():
|
||||
"""Runs a full recursive git submodule init and update.
|
||||
|
||||
Older versions of git do not support 'update --init --recursive'. We could
|
||||
check and run it on versions that do support it and speed things up a bit.
|
||||
"""
|
||||
if True:
|
||||
shell_call([
|
||||
'git',
|
||||
'submodule',
|
||||
'update',
|
||||
'--init',
|
||||
'--recursive',
|
||||
])
|
||||
else:
|
||||
shell_call([
|
||||
'git',
|
||||
'submodule',
|
||||
'init',
|
||||
])
|
||||
shell_call([
|
||||
'git',
|
||||
'submodule',
|
||||
'foreach',
|
||||
'--recursive',
|
||||
'git',
|
||||
'submodule',
|
||||
'init',
|
||||
])
|
||||
shell_call([
|
||||
'git',
|
||||
'submodule',
|
||||
'update',
|
||||
'--recursive',
|
||||
])
|
||||
shell_call([
|
||||
'git',
|
||||
'submodule',
|
||||
'update',
|
||||
'--init',
|
||||
'--recursive',
|
||||
])
|
||||
|
||||
|
||||
def get_clang_format_binary():
|
||||
|
@ -491,7 +493,10 @@ class SetupCommand(Command):
|
|||
|
||||
# Setup submodules.
|
||||
print('- git submodule init / update...')
|
||||
git_submodule_update()
|
||||
if git_is_repository():
|
||||
git_submodule_update()
|
||||
else:
|
||||
print('WARNING: Git not available or not a repository. Dependencies may be missing.')
|
||||
print('')
|
||||
|
||||
print('- running premake...')
|
||||
|
|
Loading…
Reference in New Issue