Changeset View
Changeset View
Standalone View
Standalone View
tools/build/make.py
Show First 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | if not os.path.isfile(guess): | ||||
sys.exit("Could not infer value for $" + varname + ": " + guess + | sys.exit("Could not infer value for $" + varname + ": " + guess + | ||||
" does not exist") | " does not exist") | ||||
new_env_vars[varname] = guess | new_env_vars[varname] = guess | ||||
debug("Inferred", varname, "as", guess) | debug("Inferred", varname, "as", guess) | ||||
global parsed_args | global parsed_args | ||||
if parsed_args.debug: | if parsed_args.debug: | ||||
run([guess, "--version"]) | run([guess, "--version"]) | ||||
def check_xtool_make_env_var(varname, binary_name): | def check_xtool_make_env_var(varname, binary_name): | ||||
Lint: PEP8 E302: expected 2 blank lines, found 1 | |||||
# Avoid calling brew --prefix on macOS if all variables are already set: | # Avoid calling brew --prefix on macOS if all variables are already set: | ||||
if os.getenv(varname): | if os.getenv(varname): | ||||
return | return | ||||
global parsed_args | global parsed_args | ||||
if parsed_args.cross_bindir is None: | if parsed_args.cross_bindir is None: | ||||
parsed_args.cross_bindir = default_cross_toolchain() | parsed_args.cross_bindir = default_cross_toolchain() | ||||
return check_required_make_env_var(varname, binary_name, | return check_required_make_env_var(varname, binary_name, | ||||
parsed_args.cross_bindir) | parsed_args.cross_bindir) | ||||
def default_cross_toolchain(): | def default_cross_toolchain(): | ||||
Lint: PEP8 E302 expected 2 blank lines, found 1 Lint: PEP8 E302: expected 2 blank lines, found 1 | |||||
# default to homebrew-installed clang on MacOS if available | # default to homebrew-installed clang on MacOS if available | ||||
if sys.platform.startswith("darwin"): | if sys.platform.startswith("darwin"): | ||||
if shutil.which("brew"): | if shutil.which("brew"): | ||||
llvm_dir = subprocess.run(["brew", "--prefix", "llvm"], | llvm_dir = subprocess.run(["brew", "--prefix", "llvm"], | ||||
capture_output=True).stdout.strip() | capture_output=True).stdout.strip() | ||||
debug("Inferred LLVM dir as", llvm_dir) | debug("Inferred LLVM dir as", llvm_dir) | ||||
try: | try: | ||||
if llvm_dir and Path(llvm_dir.decode("utf-8"), "bin").exists(): | if llvm_dir and Path(llvm_dir.decode("utf-8"), "bin").exists(): | ||||
Show All 22 Lines | if __name__ == "__main__": | ||||
parser.add_argument("--host-compiler-type", choices=("cc", "clang", "gcc"), | parser.add_argument("--host-compiler-type", choices=("cc", "clang", "gcc"), | ||||
default="cc", | default="cc", | ||||
help="Compiler type to find in --host-bindir (only " | help="Compiler type to find in --host-bindir (only " | ||||
"needed if CC/CPP/CXX are not set). ") | "needed if CC/CPP/CXX are not set). ") | ||||
parser.add_argument("--debug", action="store_true", | parser.add_argument("--debug", action="store_true", | ||||
help="Print information on inferred env vars") | help="Print information on inferred env vars") | ||||
parser.add_argument("--bootstrap-toolchain", action="store_true", | parser.add_argument("--bootstrap-toolchain", action="store_true", | ||||
help="Bootstrap the toolchain instead of using an " | help="Bootstrap the toolchain instead of using an " | ||||
"external one (experimetal and not recommended)") | "external one (experimental and not recommended)") | ||||
parser.add_argument("--clean", action="store_true", | parser.add_argument("--clean", action="store_true", | ||||
help="Do a clean rebuild instead of building with " | help="Do a clean rebuild instead of building with " | ||||
"-DWITHOUT_CLEAN") | "-DWITHOUT_CLEAN") | ||||
parser.add_argument("--no-clean", action="store_false", dest="clean", | parser.add_argument("--no-clean", action="store_false", dest="clean", | ||||
help="Do a clean rebuild instead of building with " | help="Do a clean rebuild instead of building with " | ||||
"-DWITHOUT_CLEAN") | "-DWITHOUT_CLEAN") | ||||
try: | try: | ||||
import argcomplete # bash completion: | import argcomplete # bash completion: | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | if __name__ == "__main__": | ||||
debug("Adding -DWITH_AUTO_OBJ") | debug("Adding -DWITH_AUTO_OBJ") | ||||
bmake_args.append("-DWITH_AUTO_OBJ") | bmake_args.append("-DWITH_AUTO_OBJ") | ||||
if parsed_args.clean is False: | if parsed_args.clean is False: | ||||
bmake_args.append("-DWITHOUT_CLEAN") | bmake_args.append("-DWITHOUT_CLEAN") | ||||
if (parsed_args.clean is None and not is_make_var_set("NO_CLEAN") | if (parsed_args.clean is None and not is_make_var_set("NO_CLEAN") | ||||
and not is_make_var_set("WITHOUT_CLEAN")): | and not is_make_var_set("WITHOUT_CLEAN")): | ||||
# Avoid accidentally deleting all of the build tree and wasting lots of | # Avoid accidentally deleting all of the build tree and wasting lots of | ||||
# time cleaning directories instead of just doing a rm -rf ${.OBJDIR} | # time cleaning directories instead of just doing a rm -rf ${.OBJDIR} | ||||
want_clean = input("You did not set -DWITHOUT_CLEAN/--clean/--no-clean." | want_clean = input("You did not set -DWITHOUT_CLEAN/--clean/--no-clean." | ||||
Lint: PEP8 E501 line too long (80 > 79 characters) Lint: PEP8 E501: line too long (80 > 79 characters) | |||||
" Did you really mean to do a clean build? y/[N] ") | " Did you really mean to do a clean build? y/[N] ") | ||||
if not want_clean.lower().startswith("y"): | if not want_clean.lower().startswith("y"): | ||||
bmake_args.append("-DWITHOUT_CLEAN") | bmake_args.append("-DWITHOUT_CLEAN") | ||||
env_cmd_str = " ".join( | env_cmd_str = " ".join( | ||||
shlex.quote(k + "=" + v) for k, v in new_env_vars.items()) | shlex.quote(k + "=" + v) for k, v in new_env_vars.items()) | ||||
make_cmd_str = " ".join( | make_cmd_str = " ".join( | ||||
shlex.quote(s) for s in [str(bmake_binary)] + bmake_args) | shlex.quote(s) for s in [str(bmake_binary)] + bmake_args) | ||||
debug("Running `env ", env_cmd_str, " ", make_cmd_str, "`", sep="") | debug("Running `env ", env_cmd_str, " ", make_cmd_str, "`", sep="") | ||||
os.environ.update(new_env_vars) | os.environ.update(new_env_vars) | ||||
os.chdir(str(source_root)) | os.chdir(str(source_root)) | ||||
os.execv(str(bmake_binary), [str(bmake_binary)] + bmake_args) | os.execv(str(bmake_binary), [str(bmake_binary)] + bmake_args) |
expected 2 blank lines, found 1