Merge 1938cff127
into 23d1f7a308
This commit is contained in:
commit
f436ab9778
|
@ -0,0 +1,36 @@
|
|||
import os
|
||||
|
||||
|
||||
def is_executable(path) -> bool:
|
||||
return os.path.isfile(path) and os.access(path, os.X_OK)
|
||||
|
||||
|
||||
def get_bin(binary):
|
||||
"""Checks whether the given binary is present and returns the path.
|
||||
|
||||
Args:
|
||||
binary: binary name (without .exe, etc).
|
||||
|
||||
Returns:
|
||||
Full path to the binary or None if not found.
|
||||
"""
|
||||
for path in os.environ['PATH'].split(os.pathsep):
|
||||
path = path.strip('"')
|
||||
exe_file = os.path.join(path, binary)
|
||||
if is_executable(exe_file):
|
||||
return exe_file
|
||||
if is_executable(exe_file + '.exe'):
|
||||
return exe_file + '.exe'
|
||||
return None
|
||||
|
||||
|
||||
def has_bin(binary):
|
||||
"""Checks whether the given binary is present in the PATH.
|
||||
|
||||
Args:
|
||||
binary: binary name (without .exe, etc).
|
||||
|
||||
Returns:
|
||||
True if the binary exists.
|
||||
"""
|
||||
return get_bin(binary) is not None
|
|
@ -12,12 +12,14 @@ import json
|
|||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import pathlib
|
||||
import sys
|
||||
import re
|
||||
from helpers import is_executable, get_bin, has_bin
|
||||
|
||||
|
||||
self_path = os.path.dirname(os.path.abspath(__file__))
|
||||
root_path = os.path.join(self_path, '..', '..')
|
||||
root_path = pathlib.Path(self_path).parent.parent.absolute()
|
||||
premake_submodule_path = os.path.join(root_path, 'third_party', 'premake-core')
|
||||
premake_path = premake_submodule_path
|
||||
|
||||
|
@ -52,30 +54,33 @@ setup_premake_path_override()
|
|||
|
||||
|
||||
def main():
|
||||
# First try the freshly-built premake.
|
||||
premake5_bin = os.path.join(premake_path, 'bin', 'release', 'premake5')
|
||||
if not has_bin(premake5_bin):
|
||||
# No fresh build, so fallback to checked in copy (which we may not have).
|
||||
premake5_bin = os.path.join(self_path, 'bin', 'premake5')
|
||||
if not has_bin(premake5_bin):
|
||||
# Still no valid binary, so build it.
|
||||
premake_bin_name = 'premake5.exe' if sys.platform is 'win32' else 'premake 5'
|
||||
premake_build_bin = os.path.join(premake_path, 'bin', 'release', 'premake5')
|
||||
premake_local_bin = os.path.join(self_path, 'bin', 'premake5')
|
||||
premake5_bin = None
|
||||
# First check if premake is available at the system level
|
||||
if has_bin('premake5'):
|
||||
premake5_bin = get_bin('premake5')
|
||||
print('using the installed version of premake')
|
||||
# Next try the freshly-built premake.
|
||||
elif is_executable(premake_build_bin):
|
||||
premake5_bin = premake_build_bin
|
||||
print('using local build of premake')
|
||||
# No fresh build, so fallback to checked in copy (which we may not have).
|
||||
elif is_executable(premake_local_bin):
|
||||
premake5_bin = premake_local_bin
|
||||
print('using the local prebuilt premake')
|
||||
# Still no valid binary, so build it.
|
||||
else:
|
||||
print('premake5 executable not found, attempting build...')
|
||||
build_premake()
|
||||
premake5_bin = os.path.join(premake_path, 'bin', 'release', 'premake5')
|
||||
if not has_bin(premake5_bin):
|
||||
# Nope, boned.
|
||||
print('ERROR: cannot build premake5 executable.')
|
||||
sys.exit(1)
|
||||
|
||||
# Ensure the submodule has been checked out.
|
||||
if not os.path.exists(os.path.join(premake_path, 'scripts', 'package.lua')):
|
||||
print('third_party/premake-core was not present; run xb setup...')
|
||||
sys.exit(1)
|
||||
return
|
||||
|
||||
if sys.platform == 'win32':
|
||||
# Append the executable extension on windows.
|
||||
premake5_bin = premake5_bin + '.exe'
|
||||
if is_executable(premake_build_bin):
|
||||
premake5_bin = premake_build_bin
|
||||
print('using local build of premake')
|
||||
else:
|
||||
# Nope, boned.
|
||||
print('ERROR: cannot build premake5 executable.')
|
||||
sys.exit(1)
|
||||
|
||||
return_code = shell_call([
|
||||
premake5_bin,
|
||||
|
@ -89,6 +94,12 @@ def main():
|
|||
def build_premake():
|
||||
"""Builds premake from source.
|
||||
"""
|
||||
# Ensure the submodule has been checked out.
|
||||
if not os.path.exists(os.path.join(premake_path, 'scripts', 'package.lua')):
|
||||
print('third_party/premake-core was not present; run xb setup...')
|
||||
sys.exit(1)
|
||||
return
|
||||
|
||||
# Ensure that on Android, premake-core is in the internal storage.
|
||||
clone_premake_to_internal_storage()
|
||||
cwd = os.getcwd()
|
||||
|
@ -152,22 +163,6 @@ def clone_premake_to_internal_storage():
|
|||
])
|
||||
|
||||
|
||||
def has_bin(bin):
|
||||
"""Checks whether the given binary is present.
|
||||
"""
|
||||
for path in os.environ["PATH"].split(os.pathsep):
|
||||
if sys.platform == 'win32':
|
||||
exe_file = os.path.join(path, bin + '.exe')
|
||||
if os.path.isfile(exe_file) and os.access(exe_file, os.X_OK):
|
||||
return True
|
||||
else:
|
||||
path = path.strip('"')
|
||||
exe_file = os.path.join(path, bin)
|
||||
if os.path.isfile(exe_file) and os.access(exe_file, os.X_OK):
|
||||
return True
|
||||
return None
|
||||
|
||||
|
||||
def shell_call(command, throw_on_error=True, stdout_path=None, stderr_path=None, shell=False):
|
||||
"""Executes a shell command.
|
||||
|
||||
|
|
36
xenia-build
36
xenia-build
|
@ -18,6 +18,7 @@ import shutil
|
|||
import subprocess
|
||||
import sys
|
||||
import stat
|
||||
from tools.build.helpers import has_bin, get_bin
|
||||
|
||||
__author__ = 'ben.vanik@gmail.com (Ben Vanik)'
|
||||
|
||||
|
@ -194,41 +195,6 @@ def print_box(msg):
|
|||
.format('', msg, len(msg) + 2))
|
||||
|
||||
|
||||
def has_bin(binary):
|
||||
"""Checks whether the given binary is present.
|
||||
|
||||
Args:
|
||||
binary: binary name (without .exe, etc).
|
||||
|
||||
Returns:
|
||||
True if the binary exists.
|
||||
"""
|
||||
bin_path = get_bin(binary)
|
||||
if not bin_path:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def get_bin(binary):
|
||||
"""Checks whether the given binary is present and returns the path.
|
||||
|
||||
Args:
|
||||
binary: binary name (without .exe, etc).
|
||||
|
||||
Returns:
|
||||
Full path to the binary or None if not found.
|
||||
"""
|
||||
for path in os.environ['PATH'].split(os.pathsep):
|
||||
path = path.strip('"')
|
||||
exe_file = os.path.join(path, binary)
|
||||
if os.path.isfile(exe_file) and os.access(exe_file, os.X_OK):
|
||||
return exe_file
|
||||
exe_file += '.exe'
|
||||
if os.path.isfile(exe_file) and os.access(exe_file, os.X_OK):
|
||||
return exe_file
|
||||
return None
|
||||
|
||||
|
||||
def shell_call(command, throw_on_error=True, stdout_path=None, stderr_path=None, shell=False):
|
||||
"""Executes a shell command.
|
||||
|
||||
|
|
Loading…
Reference in New Issue