diff --git a/tools/build/premake b/tools/build/premake index 2b20c732f..e2bbba972 100644 --- a/tools/build/premake +++ b/tools/build/premake @@ -15,7 +15,7 @@ import subprocess import pathlib import sys import re -from helpers import is_executable +from helpers import is_executable, get_bin, has_bin self_path = os.path.dirname(os.path.abspath(__file__)) @@ -54,26 +54,32 @@ setup_premake_path_override() def main(): - # First try the freshly-built premake. - premake5_bin = os.path.join(premake_path, 'bin', 'release', 'premake5') - if not is_executable(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 is_executable(premake5_bin): - # Still no valid binary, so build it. + 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 is_executable(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 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) if sys.platform == 'win32': # Append the executable extension on windows. @@ -91,6 +97,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()