[Build] Better Android detection in tools/build/premake

This commit is contained in:
Triang3l 2020-11-21 14:43:10 +03:00
parent 3f9e86e785
commit 4786e93c96
1 changed files with 36 additions and 16 deletions

View File

@ -18,18 +18,37 @@ import re
self_path = os.path.dirname(os.path.abspath(__file__)) self_path = os.path.dirname(os.path.abspath(__file__))
root_path = os.path.join(self_path, '..', '..') root_path = os.path.join(self_path, '..', '..')
premake_external_path = os.path.join(root_path, 'third_party', 'premake-core') premake_submodule_path = os.path.join(root_path, 'third_party', 'premake-core')
# On Android, the repository may be cloned to the external storage, premake_path = premake_submodule_path
# which doesn't support executables in it.
# In this case, premake-core needs to be checked out in the internal storage,
# which supports executables, with all the permissions as set in its repository. def setup_premake_path_override():
# On Termux, the home directory is in the internal storage - use it for executing. global premake_path
# If xenia-build doesn't have execute permissions, Xenia is in the external storage now. premake_path = premake_submodule_path
premake_path = premake_external_path if sys.platform == 'linux':
if 'ANDROID_ROOT' in os.environ: # On Android, the repository may be cloned to the external storage, which
xb_file = os.path.join(root_path, 'xenia-build') # doesn't support executables in it.
if os.path.isfile(xb_file) and not os.access(xb_file, os.X_OK) and 'HOME' in os.environ: # In this case, premake-core needs to be checked out in the internal
premake_path = os.path.join(os.environ['HOME'], 'xenia', 'third_party', 'premake-core') # storage, which supports executables, with all the permissions as set in
# its repository.
# On Termux, the home directory is in the internal storage - use it for
# executing.
# If xenia-build doesn't have execute permissions, Xenia is in the external
# storage now.
try:
popen = subprocess.Popen(
['uname', '-o'], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL,
universal_newlines=True)
if popen.communicate()[0] == 'Android\n':
xb_file = os.path.join(root_path, 'xenia-build')
if (os.path.isfile(xb_file) and not os.access(xb_file, os.X_OK) and
'HOME' in os.environ):
premake_path = os.path.join(
os.environ['HOME'], 'xenia', 'third_party', 'premake-core')
except Exception:
pass
setup_premake_path_override()
def main(): def main():
@ -108,13 +127,14 @@ def build_premake():
def clone_premake_to_internal_storage(): def clone_premake_to_internal_storage():
"""Clones premake to the Android internal storage so it can be executed. """Clones premake to the Android internal storage so it can be executed.
""" """
# premake_path is initialized to a value different than premake_external_path # premake_path is initialized to a value different than premake_submodule_path
# if running from the Android external storage, and may not exist yet. # if running from the Android external storage, and may not exist yet.
if premake_path == premake_external_path: if premake_path == premake_submodule_path:
return return
# Ensure the submodule has been checked out. # Ensure the submodule has been checked out.
if not os.path.exists(os.path.join(premake_external_path, 'scripts', 'package.lua')): if not os.path.exists(
os.path.join(premake_submodule_path, 'scripts', 'package.lua')):
print('third_party/premake-core was not present; run xb setup...') print('third_party/premake-core was not present; run xb setup...')
sys.exit(1) sys.exit(1)
return return
@ -127,7 +147,7 @@ def clone_premake_to_internal_storage():
'git', 'git',
'clone', 'clone',
'--recurse-submodules', '--recurse-submodules',
premake_external_path, premake_submodule_path,
premake_path, premake_path,
]) ])