diff options
Diffstat (limited to 'SConstruct')
-rw-r--r-- | SConstruct | 162 |
1 files changed, 26 insertions, 136 deletions
diff --git a/SConstruct b/SConstruct index 515cad57d0..27e6c5f2d3 100644 --- a/SConstruct +++ b/SConstruct @@ -8,6 +8,7 @@ import glob import os import pickle import sys +from collections import OrderedDict # Local import methods @@ -180,18 +181,22 @@ for k in platform_opts.keys(): for o in opt_list: opts.Add(o) +# Update the environment now as the "custom_modules" option may be +# defined in a file rather than specified via the command line. +opts.Update(env_base) + # Detect modules. -modules_detected = {} +modules_detected = OrderedDict() module_search_paths = ["modules"] # Built-in path. -if ARGUMENTS.get("custom_modules"): - paths = ARGUMENTS.get("custom_modules").split(",") +if env_base["custom_modules"]: + paths = env_base["custom_modules"].split(",") for p in paths: try: module_search_paths.append(methods.convert_custom_modules_path(p)) except ValueError as e: print(e) - sys.exit(255) + Exit(255) for path in module_search_paths: # Note: custom modules can override built-in ones. @@ -216,8 +221,9 @@ for name, path in modules_detected.items(): methods.write_modules(modules_detected) -opts.Update(env_base) # update environment -Help(opts.GenerateHelpText(env_base)) # generate help +# Update the environment again after all the module options are added. +opts.Update(env_base) +Help(opts.GenerateHelpText(env_base)) # add default include paths @@ -392,7 +398,7 @@ if selected_platform in platform_list: 'newer GCC version, or Clang 6 or later by passing "use_llvm=yes" ' "to the SCons command line." ) - sys.exit(255) + Exit(255) elif cc_version_major < 7: print( "Detected GCC version older than 7, which does not fully support " @@ -400,7 +406,7 @@ if selected_platform in platform_list: 'version, or Clang 6 or later by passing "use_llvm=yes" to the ' "SCons command line." ) - sys.exit(255) + Exit(255) elif methods.using_clang(env): # Apple LLVM versions differ from upstream LLVM version \o/, compare # in https://en.wikipedia.org/wiki/Xcode#Toolchain_versions @@ -411,19 +417,19 @@ if selected_platform in platform_list: "Detected Clang version older than 6, which does not fully support " "C++17. Supported versions are Clang 6 and later." ) - sys.exit(255) + Exit(255) elif not vanilla and cc_version_major < 10: print( "Detected Apple Clang version older than 10, which does not fully " "support C++17. Supported versions are Apple Clang 10 and later." ) - sys.exit(255) + Exit(255) elif cc_version_major < 6: print( "Detected Clang version older than 6, which does not fully support " "C++17. Supported versions are Clang 6 and later." ) - sys.exit(255) + Exit(255) # Configure compiler warnings if env.msvc: @@ -496,7 +502,7 @@ if selected_platform in platform_list: if env["target"] == "release": if env["tools"]: print("Tools can only be built with targets 'debug' and 'release_debug'.") - sys.exit(255) + Exit(255) suffix += ".opt" env.Append(CPPDEFINES=["NDEBUG"]) @@ -523,11 +529,11 @@ if selected_platform in platform_list: sys.path.remove(tmppath) sys.modules.pop("detect") - modules_enabled = {} + modules_enabled = OrderedDict() env.module_icons_paths = [] env.doc_class_path = {} - for name, path in sorted(modules_detected.items()): + for name, path in modules_detected.items(): if not env["module_" + name + "_enabled"]: continue sys.path.insert(0, path) @@ -585,7 +591,7 @@ if selected_platform in platform_list: "Build option 'disable_3d=yes' cannot be used with 'tools=yes' (editor), " "only with 'tools=no' (export template)." ) - sys.exit(255) + Exit(255) else: env.Append(CPPDEFINES=["_3D_DISABLED"]) if env["disable_advanced_gui"]: @@ -594,7 +600,7 @@ if selected_platform in platform_list: "Build option 'disable_advanced_gui=yes' cannot be used with 'tools=yes' (editor), " "only with 'tools=no' (export template)." ) - sys.exit(255) + Exit(255) else: env.Append(CPPDEFINES=["ADVANCED_GUI_DISABLED"]) if env["minizip"]: @@ -608,7 +614,7 @@ if selected_platform in platform_list: "Build option 'module_" + x + "_enabled=no' cannot be used with 'tools=yes' (editor), " "only with 'tools=no' (export template)." ) - sys.exit(255) + Exit(255) if not env["verbose"]: methods.no_verbose(sys, env) @@ -684,126 +690,10 @@ elif selected_platform != "": if selected_platform == "list": # Exit early to suppress the rest of the built-in SCons messages - sys.exit(0) + Exit() else: - sys.exit(255) + Exit(255) # The following only makes sense when the env is defined, and assumes it is if "env" in locals(): - screen = sys.stdout - # Progress reporting is not available in non-TTY environments since it - # messes with the output (for example, when writing to a file) - show_progress = env["progress"] and sys.stdout.isatty() - node_count = 0 - node_count_max = 0 - node_count_interval = 1 - node_count_fname = str(env.Dir("#")) + "/.scons_node_count" - - import time, math - - class cache_progress: - # The default is 1 GB cache and 12 hours half life - def __init__(self, path=None, limit=1073741824, half_life=43200): - self.path = path - self.limit = limit - self.exponent_scale = math.log(2) / half_life - if env["verbose"] and path != None: - screen.write( - "Current cache limit is {} (used: {})\n".format( - self.convert_size(limit), self.convert_size(self.get_size(path)) - ) - ) - self.delete(self.file_list()) - - def __call__(self, node, *args, **kw): - global node_count, node_count_max, node_count_interval, node_count_fname, show_progress - if show_progress: - # Print the progress percentage - node_count += node_count_interval - if node_count_max > 0 and node_count <= node_count_max: - screen.write("\r[%3d%%] " % (node_count * 100 / node_count_max)) - screen.flush() - elif node_count_max > 0 and node_count > node_count_max: - screen.write("\r[100%] ") - screen.flush() - else: - screen.write("\r[Initial build] ") - screen.flush() - - def delete(self, files): - if len(files) == 0: - return - if env["verbose"]: - # Utter something - screen.write("\rPurging %d %s from cache...\n" % (len(files), len(files) > 1 and "files" or "file")) - [os.remove(f) for f in files] - - def file_list(self): - if self.path is None: - # Nothing to do - return [] - # Gather a list of (filename, (size, atime)) within the - # cache directory - file_stat = [(x, os.stat(x)[6:8]) for x in glob.glob(os.path.join(self.path, "*", "*"))] - if file_stat == []: - # Nothing to do - return [] - # Weight the cache files by size (assumed to be roughly - # proportional to the recompilation time) times an exponential - # decay since the ctime, and return a list with the entries - # (filename, size, weight). - current_time = time.time() - file_stat = [(x[0], x[1][0], (current_time - x[1][1])) for x in file_stat] - # Sort by the most recently accessed files (most sensible to keep) first - file_stat.sort(key=lambda x: x[2]) - # Search for the first entry where the storage limit is - # reached - sum, mark = 0, None - for i, x in enumerate(file_stat): - sum += x[1] - if sum > self.limit: - mark = i - break - if mark is None: - return [] - else: - return [x[0] for x in file_stat[mark:]] - - def convert_size(self, size_bytes): - if size_bytes == 0: - return "0 bytes" - size_name = ("bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB") - i = int(math.floor(math.log(size_bytes, 1024))) - p = math.pow(1024, i) - s = round(size_bytes / p, 2) - return "%s %s" % (int(s) if i == 0 else s, size_name[i]) - - def get_size(self, start_path="."): - total_size = 0 - for dirpath, dirnames, filenames in os.walk(start_path): - for f in filenames: - fp = os.path.join(dirpath, f) - total_size += os.path.getsize(fp) - return total_size - - def progress_finish(target, source, env): - global node_count, progressor - with open(node_count_fname, "w") as f: - f.write("%d\n" % node_count) - progressor.delete(progressor.file_list()) - - try: - with open(node_count_fname) as f: - node_count_max = int(f.readline()) - except: - pass - - cache_directory = os.environ.get("SCONS_CACHE") - # Simple cache pruning, attached to SCons' progress callback. Trim the - # cache directory to a size not larger than cache_limit. - cache_limit = float(os.getenv("SCONS_CACHE_LIMIT", 1024)) * 1024 * 1024 - progressor = cache_progress(cache_directory, cache_limit) - Progress(progressor, interval=node_count_interval) - - progress_finish_command = Command("progress_finish", [], progress_finish) - AlwaysBuild(progress_finish_command) + methods.show_progress(env) |