1
0
forked from Mirror/wren

fix util/generate_project.py

- fix premake args being incorrect
- remove platform assumptions, making it portable
- start with a best guess based on project layout
- use fallback if not specified or not found
- display errors/help if not found
This commit is contained in:
underscorediscovery
2020-06-14 19:44:58 -07:00
parent de6a312868
commit 30b2ebd3f7

View File

@ -3,26 +3,48 @@
import sys
from os import getenv, path
from subprocess import PIPE, run
import platform
PREMAKE_DIR = path.join(path.dirname(__file__), "../projects/premake")
# Default binary name
PREMAKE_BIN = "premake5"
if platform.system() == "Windows":
PREMAKE_BIN += ".exe"
def has(prog):
return run(["command", "-v", prog], stdout=PIPE, stderr=PIPE).returncode == 0
# We try the env first, as that's absolute.
# If not found we try the 'intended' approach,
# of placing a premake binary alongside premake5.lua.
# If that isn't found, attempt the plain binary name.
premake = getenv("WREN_PREMAKE", None)
if premake is None:
premake = PREMAKE_BIN
premake_local = path.join(PREMAKE_DIR, PREMAKE_BIN)
if path.isfile(premake_local):
print("Using local premake in 'projects/premake' ...")
premake = premake_local
else:
print("Using premake from 'WREN_PREMAKE' env ...")
def run_premake(action, os):
run([premake, action, os], cwd=PREMAKE_DIR)
run([premake, action, "--os=" + os], cwd=PREMAKE_DIR)
try:
premake = getenv("PREMAKE", "premake5")
if not has(premake):
print("error: {} is not found", premake, file=sys.stderr)
exit(1)
run_premake("gmake2", "bsd")
run_premake("gmake2", "linux")
run_premake("vs2017", "windows")
run_premake("vs2019", "windows")
run_premake("gmake2", "macosx")
run_premake("xcode4", "macosx")
run_premake("gmake2", "bsd")
run_premake("gmake2", "linux")
run_premake("gmake2", "macosx")
run_premake("vs2017", "windows")
run_premake("vs2019", "windows")
run_premake("xcode4", "macosx")
except Exception as e:
print("Unable to run premake, while trying the binary '" + premake + "' ...")
print(" reason: " + str(e))
print("\nIf premake can't be found, possible options are:")
print("- Set the env variable 'WREN_PREMAKE' to the path to a premake binary")
print("- Place a premake5 binary for your host platform in projects/premake")
print("- Add a location with a premake5 binary to the PATH")
exit(1)