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 20 Lines | parser.add_argument("--cross-compiler-type", choices=("clang", "gcc"), | ||||||||
"needed if XCC/XCPP/XLD are not set)" | "needed if XCC/XCPP/XLD are not set)" | ||||||||
"Note: using CC is currently highly experimental") | "Note: using CC is currently highly experimental") | ||||||||
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", | |||||||||
help="Bootstrap the toolchain instead of using an " | |||||||||
"external one (experimental and not recommended)") | |||||||||
Done Inline Actions
jrtc27: | |||||||||
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 All 13 Lines | if __name__ == "__main__": | ||||||||
source_root = Path(__file__).absolute().parent.parent.parent | source_root = Path(__file__).absolute().parent.parent.parent | ||||||||
new_env_vars = {} | new_env_vars = {} | ||||||||
if not sys.platform.startswith("freebsd"): | if not sys.platform.startswith("freebsd"): | ||||||||
if not is_make_var_set("TARGET") or not is_make_var_set("TARGET_ARCH"): | if not is_make_var_set("TARGET") or not is_make_var_set("TARGET_ARCH"): | ||||||||
if "universe" not in sys.argv and "tinderbox" not in sys.argv: | if "universe" not in sys.argv and "tinderbox" not in sys.argv: | ||||||||
sys.exit("TARGET= and TARGET_ARCH= must be set explicitly " | sys.exit("TARGET= and TARGET_ARCH= must be set explicitly " | ||||||||
"when building on non-FreeBSD") | "when building on non-FreeBSD") | ||||||||
if not parsed_args.bootstrap_toolchain: | |||||||||
# infer values for CC/CXX/CPP | # infer values for CC/CXX/CPP | ||||||||
if parsed_args.host_compiler_type == "gcc": | if parsed_args.host_compiler_type == "gcc": | ||||||||
default_cc, default_cxx, default_cpp = ("gcc", "g++", "cpp") | default_cc, default_cxx, default_cpp = ("gcc", "g++", "cpp") | ||||||||
# FIXME: this should take values like `clang-9` and then look for | # FIXME: this should take values like `clang-9` and then look for | ||||||||
# clang-cpp-9, etc. Would alleviate the need to set the bindir on | # clang-cpp-9, etc. Would alleviate the need to set the bindir on | ||||||||
# ubuntu/debian at least. | # ubuntu/debian at least. | ||||||||
elif parsed_args.host_compiler_type == "clang": | elif parsed_args.host_compiler_type == "clang": | ||||||||
default_cc, default_cxx, default_cpp = ( | default_cc, default_cxx, default_cpp = ( | ||||||||
▲ Show 20 Lines • Show All 41 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) | |||||||||
dimUnsubmitted Not Done Inline ActionsPedantic note, maybe chop off one character more to have the PEP checker stop complaining? :) dim: Pedantic note, maybe chop off one character more to have the PEP checker stop complaining? :) | |||||||||
arichardsonAuthorUnsubmitted Done Inline ActionsWill push a pep8 fix commit for that script shortly. arichardson: Will push a pep8 fix commit for that script shortly. | |||||||||
" 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