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.
|
# Copyright 2015 Ben Vanik. All Rights Reserved.
|
||||||
|
|
||||||
|
@ -107,13 +107,14 @@ def has_bin(bin):
|
||||||
return None
|
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.
|
"""Executes a shell command.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
command: Command to execute, as a list of parameters.
|
command: Command to execute, as a list of parameters.
|
||||||
throw_on_error: Whether to throw an error or return the status code.
|
throw_on_error: Whether to throw an error or return the status code.
|
||||||
stdout_path: File path to write stdout output to.
|
stdout_path: File path to write stdout output to.
|
||||||
|
stderr_path: File path to write stderr output to.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
If throw_on_error is False the status code of the call will be returned.
|
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
|
stdout_file = None
|
||||||
if stdout_path:
|
if stdout_path:
|
||||||
stdout_file = open(stdout_path, 'w')
|
stdout_file = open(stdout_path, 'w')
|
||||||
|
stderr_file = None
|
||||||
|
if stderr_path:
|
||||||
|
stderr_file = open(stderr_path, 'w')
|
||||||
result = 0
|
result = 0
|
||||||
try:
|
try:
|
||||||
if throw_on_error:
|
if throw_on_error:
|
||||||
result = 1
|
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
|
result = 0
|
||||||
else:
|
else:
|
||||||
result = subprocess.call(command, shell=False, stdout=stdout_file)
|
result = subprocess.call(command, shell=shell, stdout=stdout_file, stderr=stderr_file)
|
||||||
finally:
|
finally:
|
||||||
if stdout_file:
|
if stdout_file:
|
||||||
stdout_file.close()
|
stdout_file.close()
|
||||||
|
if stderr_file:
|
||||||
|
stderr_file.close()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
@ -196,42 +202,5 @@ def import_subprocess_environment(args):
|
||||||
os.environ[var.upper()] = setting
|
os.environ[var.upper()] = setting
|
||||||
break
|
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__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
111
xenia-build
111
xenia-build
|
@ -34,8 +34,11 @@ def main():
|
||||||
|
|
||||||
# Check git exists.
|
# Check git exists.
|
||||||
if not has_bin('git'):
|
if not has_bin('git'):
|
||||||
print('ERROR: git must be installed and on PATH.')
|
print('WARNING: Git should be installed and on PATH. Version info will be omitted from all binaries!')
|
||||||
sys.exit(1)
|
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.
|
# Check python version.
|
||||||
if not sys.version_info[:2] >= (3, 6):
|
if not sys.version_info[:2] >= (3, 6):
|
||||||
|
@ -185,13 +188,14 @@ def get_bin(binary):
|
||||||
return None
|
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.
|
"""Executes a shell command.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
command: Command to execute, as a list of parameters.
|
command: Command to execute, as a list of parameters.
|
||||||
throw_on_error: Whether to throw an error or return the status code.
|
throw_on_error: Whether to throw an error or return the status code.
|
||||||
stdout_path: File path to write stdout output to.
|
stdout_path: File path to write stdout output to.
|
||||||
|
stderr_path: File path to write stderr output to.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
If throw_on_error is False the status code of the call will be returned.
|
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
|
stdout_file = None
|
||||||
if stdout_path:
|
if stdout_path:
|
||||||
stdout_file = open(stdout_path, 'w')
|
stdout_file = open(stdout_path, 'w')
|
||||||
|
stderr_file = None
|
||||||
|
if stderr_path:
|
||||||
|
stderr_file = open(stderr_path, 'w')
|
||||||
result = 0
|
result = 0
|
||||||
try:
|
try:
|
||||||
if throw_on_error:
|
if throw_on_error:
|
||||||
result = 1
|
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
|
result = 0
|
||||||
else:
|
else:
|
||||||
result = subprocess.call(command, shell=shell, stdout=stdout_file)
|
result = subprocess.call(command, shell=shell, stdout=stdout_file, stderr=stderr_file)
|
||||||
finally:
|
finally:
|
||||||
if stdout_file:
|
if stdout_file:
|
||||||
stdout_file.close()
|
stdout_file.close()
|
||||||
|
if stderr_file:
|
||||||
|
stderr_file.close()
|
||||||
return result
|
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.
|
"""Queries the current branch and commit checksum from git.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
@ -247,58 +279,28 @@ def get_git_head_info():
|
||||||
return branch_name, commit, commit_short
|
return branch_name, commit, commit_short
|
||||||
|
|
||||||
|
|
||||||
def generate_version_h():
|
def git_is_repository():
|
||||||
"""Generates a build/version.h file that contains current git info.
|
"""Checks if git is available and this source tree is versioned.
|
||||||
"""
|
"""
|
||||||
(branch_name, commit, commit_short) = get_git_head_info()
|
if not has_bin('git'):
|
||||||
contents = '''// Autogenerated by `xb premake`.
|
return False
|
||||||
#ifndef GENERATED_VERSION_H_
|
return shell_call([
|
||||||
#define GENERATED_VERSION_H_
|
'git',
|
||||||
#define XE_BUILD_BRANCH "%s"
|
'rev-parse',
|
||||||
#define XE_BUILD_COMMIT "%s"
|
'--is-inside-work-tree',
|
||||||
#define XE_BUILD_COMMIT_SHORT "%s"
|
], throw_on_error=False, stdout_path=os.devnull, stderr_path=os.devnull) == 0
|
||||||
#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():
|
def git_submodule_update():
|
||||||
"""Runs a full recursive git submodule init and 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([
|
||||||
shell_call([
|
'git',
|
||||||
'git',
|
'submodule',
|
||||||
'submodule',
|
'update',
|
||||||
'update',
|
'--init',
|
||||||
'--init',
|
'--recursive',
|
||||||
'--recursive',
|
])
|
||||||
])
|
|
||||||
else:
|
|
||||||
shell_call([
|
|
||||||
'git',
|
|
||||||
'submodule',
|
|
||||||
'init',
|
|
||||||
])
|
|
||||||
shell_call([
|
|
||||||
'git',
|
|
||||||
'submodule',
|
|
||||||
'foreach',
|
|
||||||
'--recursive',
|
|
||||||
'git',
|
|
||||||
'submodule',
|
|
||||||
'init',
|
|
||||||
])
|
|
||||||
shell_call([
|
|
||||||
'git',
|
|
||||||
'submodule',
|
|
||||||
'update',
|
|
||||||
'--recursive',
|
|
||||||
])
|
|
||||||
|
|
||||||
|
|
||||||
def get_clang_format_binary():
|
def get_clang_format_binary():
|
||||||
|
@ -491,7 +493,10 @@ class SetupCommand(Command):
|
||||||
|
|
||||||
# Setup submodules.
|
# Setup submodules.
|
||||||
print('- git submodule init / update...')
|
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('')
|
||||||
|
|
||||||
print('- running premake...')
|
print('- running premake...')
|
||||||
|
|
Loading…
Reference in New Issue