mirror of
https://github.com/xenia-project/xenia.git
synced 2025-12-06 07:12:03 +01:00
[tools/build/premake.py] Formatting
This commit is contained in:
parent
7f7e4fd381
commit
3b3c41ab2a
|
|
@ -5,27 +5,26 @@
|
||||||
"""Premake trampoline script.
|
"""Premake trampoline script.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__author__ = 'ben.vanik@gmail.com (Ben Vanik)'
|
__author__ = "ben.vanik@gmail.com (Ben Vanik)"
|
||||||
|
|
||||||
|
|
||||||
import json
|
from json import loads as jsonloads
|
||||||
import os
|
import os
|
||||||
import shutil
|
from shutil import rmtree
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
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_submodule_path = os.path.join(root_path, 'third_party', 'premake-core')
|
premake_submodule_path = os.path.join(root_path, "third_party", "premake-core")
|
||||||
premake_path = premake_submodule_path
|
premake_path = premake_submodule_path
|
||||||
|
|
||||||
|
|
||||||
def setup_premake_path_override():
|
def setup_premake_path_override():
|
||||||
global premake_path
|
global premake_path
|
||||||
premake_path = premake_submodule_path
|
premake_path = premake_submodule_path
|
||||||
if sys.platform == 'linux':
|
if sys.platform == "linux":
|
||||||
# On Android, the repository may be cloned to the external storage, which
|
# On Android, the repository may be cloned to the external storage, which
|
||||||
# doesn't support executables in it.
|
# doesn't support executables in it.
|
||||||
# In this case, premake-core needs to be checked out in the internal
|
# In this case, premake-core needs to be checked out in the internal
|
||||||
|
|
@ -37,14 +36,13 @@ def setup_premake_path_override():
|
||||||
# storage now.
|
# storage now.
|
||||||
try:
|
try:
|
||||||
popen = subprocess.Popen(
|
popen = subprocess.Popen(
|
||||||
['uname', '-o'], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL,
|
["uname", "-o"], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL,
|
||||||
universal_newlines=True)
|
text=True)
|
||||||
if popen.communicate()[0] == 'Android\n':
|
if popen.communicate()[0] == "Android\n":
|
||||||
xb_file = os.path.join(root_path, 'xenia-build.py')
|
xb_file = os.path.join(root_path, "xenia-build.py")
|
||||||
if (os.path.isfile(xb_file) and not os.access(xb_file, os.X_OK) and
|
if (os.path.isfile(xb_file) and not os.access(xb_file, os.X_OK) and
|
||||||
'HOME' in os.environ):
|
"HOME" in os.environ):
|
||||||
premake_path = os.path.join(
|
premake_path = os.path.join(os.environ["HOME"], ".xenia-build", "premake-core")
|
||||||
os.environ['HOME'], '.xenia-build', 'premake-core')
|
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
@ -53,33 +51,32 @@ setup_premake_path_override()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# First try the freshly-built premake.
|
# First try the freshly-built premake.
|
||||||
premake5_bin = os.path.join(premake_path, 'bin', 'release', 'premake5')
|
premake5_bin = os.path.join(premake_path, "bin", "release", "premake5")
|
||||||
if not has_bin(premake5_bin):
|
if not has_bin(premake5_bin):
|
||||||
# No fresh build, so fallback to checked in copy (which we may not have).
|
# No fresh build, so fallback to checked in copy (which we may not have).
|
||||||
premake5_bin = os.path.join(self_path, 'bin', 'premake5')
|
premake5_bin = os.path.join(self_path, "bin", "premake5")
|
||||||
if not has_bin(premake5_bin):
|
if not has_bin(premake5_bin):
|
||||||
# Still no valid binary, so build it.
|
# Still no valid binary, so build it.
|
||||||
print('premake5 executable not found, attempting build...')
|
print("premake5 executable not found, attempting build...")
|
||||||
build_premake()
|
build_premake()
|
||||||
premake5_bin = os.path.join(premake_path, 'bin', 'release', 'premake5')
|
premake5_bin = os.path.join(premake_path, "bin", "release", "premake5")
|
||||||
if not has_bin(premake5_bin):
|
if not has_bin(premake5_bin):
|
||||||
# Nope, boned.
|
# Nope, boned.
|
||||||
print('ERROR: cannot build premake5 executable.')
|
print("ERROR: cannot build premake5 executable.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Ensure the submodule has been checked out.
|
# Ensure the submodule has been checked out.
|
||||||
if not os.path.exists(os.path.join(premake_path, 'scripts', 'package.lua')):
|
if not os.path.exists(os.path.join(premake_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
|
|
||||||
|
|
||||||
if sys.platform == 'win32':
|
if sys.platform == "win32":
|
||||||
# Append the executable extension on windows.
|
# Append the executable extension on windows.
|
||||||
premake5_bin = premake5_bin + '.exe'
|
premake5_bin += ".exe"
|
||||||
|
|
||||||
return_code = shell_call([
|
return_code = shell_call([
|
||||||
premake5_bin,
|
premake5_bin,
|
||||||
'--scripts=%s' % (premake_path),
|
f"--scripts={premake_path}",
|
||||||
] + sys.argv[1:],
|
] + sys.argv[1:],
|
||||||
throw_on_error=False)
|
throw_on_error=False)
|
||||||
|
|
||||||
|
|
@ -94,31 +91,31 @@ def build_premake():
|
||||||
cwd = os.getcwd()
|
cwd = os.getcwd()
|
||||||
try:
|
try:
|
||||||
os.chdir(premake_path)
|
os.chdir(premake_path)
|
||||||
if sys.platform == 'darwin':
|
if sys.platform == "darwin":
|
||||||
subprocess.call([
|
subprocess.call([
|
||||||
'make',
|
"make",
|
||||||
'-f', 'Bootstrap.mak',
|
"-f", "Bootstrap.mak",
|
||||||
'osx',
|
"osx",
|
||||||
], shell=False)
|
])
|
||||||
elif sys.platform == 'win32':
|
elif sys.platform == "win32":
|
||||||
# Grab Visual Studio version and execute shell to set up environment.
|
# Grab Visual Studio version and execute shell to set up environment.
|
||||||
vs_version = import_vs_environment()
|
vs_version = import_vs_environment()
|
||||||
if vs_version is None:
|
if not vs_version:
|
||||||
print('ERROR: Visual Studio not found!')
|
print("ERROR: Visual Studio not found!")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
return
|
return
|
||||||
|
|
||||||
subprocess.call([
|
subprocess.call([
|
||||||
'nmake',
|
"nmake",
|
||||||
'-f', 'Bootstrap.mak',
|
"-f", "Bootstrap.mak",
|
||||||
'windows',
|
"windows",
|
||||||
], shell=False)
|
])
|
||||||
else:
|
else:
|
||||||
subprocess.call([
|
subprocess.call([
|
||||||
'make',
|
"make",
|
||||||
'-f', 'Bootstrap.mak',
|
"-f", "Bootstrap.mak",
|
||||||
'linux',
|
"linux",
|
||||||
], shell=False)
|
])
|
||||||
finally:
|
finally:
|
||||||
os.chdir(cwd)
|
os.chdir(cwd)
|
||||||
pass
|
pass
|
||||||
|
|
@ -134,19 +131,18 @@ def clone_premake_to_internal_storage():
|
||||||
|
|
||||||
# Ensure the submodule has been checked out.
|
# Ensure the submodule has been checked out.
|
||||||
if not os.path.exists(
|
if not os.path.exists(
|
||||||
os.path.join(premake_submodule_path, 'scripts', 'package.lua')):
|
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
|
|
||||||
|
|
||||||
# Create or refresh premake-core in the internal storage.
|
# Create or refresh premake-core in the internal storage.
|
||||||
print('Cloning premake5 to the internal storage...')
|
print("Cloning premake5 to the internal storage...")
|
||||||
shutil.rmtree(premake_path, ignore_errors=True)
|
rmtree(premake_path, ignore_errors=True)
|
||||||
os.makedirs(premake_path)
|
os.makedirs(premake_path)
|
||||||
shell_call([
|
shell_call([
|
||||||
'git',
|
"git",
|
||||||
'clone',
|
"clone",
|
||||||
'--recurse-submodules',
|
"--depth=1",
|
||||||
premake_submodule_path,
|
premake_submodule_path,
|
||||||
premake_path,
|
premake_path,
|
||||||
])
|
])
|
||||||
|
|
@ -156,12 +152,12 @@ def has_bin(bin):
|
||||||
"""Checks whether the given binary is present.
|
"""Checks whether the given binary is present.
|
||||||
"""
|
"""
|
||||||
for path in os.environ["PATH"].split(os.pathsep):
|
for path in os.environ["PATH"].split(os.pathsep):
|
||||||
if sys.platform == 'win32':
|
if sys.platform == "win32":
|
||||||
exe_file = os.path.join(path, bin + '.exe')
|
exe_file = os.path.join(path, f"{bin}.exe")
|
||||||
if os.path.isfile(exe_file) and os.access(exe_file, os.X_OK):
|
if os.path.isfile(exe_file) and os.access(exe_file, os.X_OK):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
path = path.strip('"')
|
path = path.strip("\"")
|
||||||
exe_file = os.path.join(path, bin)
|
exe_file = os.path.join(path, bin)
|
||||||
if os.path.isfile(exe_file) and os.access(exe_file, os.X_OK):
|
if os.path.isfile(exe_file) and os.access(exe_file, os.X_OK):
|
||||||
return True
|
return True
|
||||||
|
|
@ -182,10 +178,10 @@ def shell_call(command, throw_on_error=True, stdout_path=None, stderr_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
|
stderr_file = None
|
||||||
if stderr_path:
|
if stderr_path:
|
||||||
stderr_file = open(stderr_path, 'w')
|
stderr_file = open(stderr_path, "w")
|
||||||
result = 0
|
result = 0
|
||||||
try:
|
try:
|
||||||
if throw_on_error:
|
if throw_on_error:
|
||||||
|
|
@ -207,61 +203,70 @@ def import_vs_environment():
|
||||||
interesting environment variables into os.environ.
|
interesting environment variables into os.environ.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
A version such as 2015 or None if no installation is found.
|
A version such as 2022 or None if no installation is found.
|
||||||
"""
|
"""
|
||||||
version = 0
|
|
||||||
|
if sys.platform != "win32":
|
||||||
|
return None
|
||||||
|
|
||||||
|
version = None
|
||||||
install_path = None
|
install_path = None
|
||||||
env_tool_args = None
|
env_tool_args = None
|
||||||
|
|
||||||
vswhere = subprocess.check_output('tools/vswhere/vswhere.exe -version "[15,)" -latest -format json -utf8', shell=False, universal_newlines=True, encoding="utf-8")
|
vswhere = subprocess.check_output(
|
||||||
|
"tools/vswhere/vswhere.exe -version \"[17,)\" -latest -prerelease -format json -utf8 -products"
|
||||||
|
" Microsoft.VisualStudio.Product.Enterprise"
|
||||||
|
" Microsoft.VisualStudio.Product.Professional"
|
||||||
|
" Microsoft.VisualStudio.Product.Community"
|
||||||
|
" Microsoft.VisualStudio.Product.BuildTools",
|
||||||
|
encoding="utf-8",
|
||||||
|
)
|
||||||
if vswhere:
|
if vswhere:
|
||||||
vswhere = json.loads(vswhere)
|
vswhere = jsonloads(vswhere)
|
||||||
if vswhere and len(vswhere) > 0:
|
if vswhere and len(vswhere) > 0:
|
||||||
version = int(vswhere[0].get("catalog", {}).get("productLineVersion", 2017))
|
version = int(vswhere[0].get("catalog", {}).get("productLineVersion", 2022))
|
||||||
install_path = vswhere[0].get("installationPath", None)
|
install_path = vswhere[0].get("installationPath", None)
|
||||||
|
|
||||||
if version < 2017:
|
vsdevcmd_path = os.path.join(install_path, "Common7", "Tools", "VsDevCmd.bat")
|
||||||
if 'VS140COMNTOOLS' in os.environ:
|
if os.access(vsdevcmd_path, os.X_OK):
|
||||||
version = 2015
|
env_tool_args = [vsdevcmd_path, "-arch=amd64", "-host_arch=amd64", "&&", "set"]
|
||||||
vcvars_path = os.environ['VS140COMNTOOLS']
|
|
||||||
vcvars_path = os.path.join(tools_path, '..\\..\\vc\\vcvarsall.bat')
|
|
||||||
env_tool_args = [vcvars_path, 'x64', '&&', 'set']
|
|
||||||
else:
|
else:
|
||||||
vsdevcmd_path = os.path.join(install_path, 'Common7\\Tools\\VsDevCmd.bat')
|
vcvars_path = os.path.join(install_path, "VC", "Auxiliary", "Build", "vcvarsall.bat")
|
||||||
env_tool_args = [vsdevcmd_path, '-arch=amd64', '-host_arch=amd64']
|
env_tool_args = [vcvars_path, "x64", "&&", "set"]
|
||||||
|
|
||||||
if version == 0:
|
if not version:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
import_subprocess_environment(env_tool_args)
|
import_subprocess_environment(env_tool_args)
|
||||||
os.environ['VSVERSION'] = str(version)
|
os.environ["VSVERSION"] = f"{version}"
|
||||||
return version
|
return version
|
||||||
|
|
||||||
|
|
||||||
def import_subprocess_environment(args):
|
def import_subprocess_environment(args):
|
||||||
popen = subprocess.Popen(
|
popen = subprocess.Popen(
|
||||||
args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
|
args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
|
||||||
variables, _ = popen.communicate()
|
variables, _ = popen.communicate()
|
||||||
envvars_to_save = (
|
envvars_to_save = (
|
||||||
'devenvdir',
|
"devenvdir",
|
||||||
'include',
|
"include",
|
||||||
'lib',
|
"lib",
|
||||||
'libpath',
|
"libpath",
|
||||||
'path',
|
"path",
|
||||||
'pathext',
|
"pathext",
|
||||||
'systemroot',
|
"systemroot",
|
||||||
'temp',
|
"temp",
|
||||||
'tmp',
|
"tmp",
|
||||||
'windowssdkdir',
|
"vcinstalldir",
|
||||||
|
"windowssdkdir",
|
||||||
)
|
)
|
||||||
for line in variables.splitlines():
|
for line in variables.splitlines():
|
||||||
for envvar in envvars_to_save:
|
for envvar in envvars_to_save:
|
||||||
if re.match(envvar + '=', line.lower()):
|
if f"{envvar}=" in line.lower():
|
||||||
var, setting = line.split('=', 1)
|
var, setting = line.split("=", 1)
|
||||||
if envvar == 'path':
|
if envvar == "path":
|
||||||
setting = os.path.dirname(sys.executable) + os.pathsep + setting
|
setting = f"{os.path.dirname(sys.executable)}{os.pathsep}{setting}"
|
||||||
os.environ[var.upper()] = setting
|
os.environ[var.upper()] = setting
|
||||||
break
|
break
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue