diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2023-04-26 10:04:00 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2023-12-19 08:26:46 +0100 |
commit | 7752948f10db500e816503990c885db3a9a45635 (patch) | |
tree | 39931a72f4bf126a5e75f130c1b40b6d9235b05a | |
parent | 20d2eaea3fa0e1c1f90df05e10184e551b807722 (diff) |
build: Use CSafeLoader if available
The CSafeLoader uses the C libyaml libary to considerably speed up the
loading of YAML files.
-rwxr-xr-x | wscript | 39 |
1 files changed, 23 insertions, 16 deletions
@@ -1202,7 +1202,7 @@ def must_update_item_cache(ctx, path, cache_file): return is_one_item_newer(ctx, path, mtime) -def load_from_yaml(load, ctx, data_by_uid, base, path): +def load_from_yaml(ctx, data_by_uid, base, path): try: names = os.listdir(path) except Exception as e: @@ -1212,11 +1212,11 @@ def load_from_yaml(load, ctx, data_by_uid, base, path): if name.endswith(".yml") and not name.startswith("."): uid = "/" + os.path.relpath(path2, base).replace(".yml", "") with open(path2, "r") as f: - data_by_uid[uid] = load(f.read()) + data_by_uid[uid] = load(f.read(), SafeLoader) else: mode = os.lstat(path2).st_mode if stat.S_ISDIR(mode): - load_from_yaml(load, ctx, data_by_uid, base, path2) + load_from_yaml(ctx, data_by_uid, base, path2) def load_items_in_directory(ctx, ctors, path): @@ -1235,19 +1235,7 @@ def load_items_in_directory(ctx, ctors, path): "Regenerate build specification cache (needs a couple of seconds)..." ) - # - # Do not use a system provided yaml module and instead import it from - # the project. This reduces the host system requirements to a simple - # Python 2.7 or 3 installation without extra modules. - # - if sys.version_info[0] == 2: - yaml_path = "yaml/lib" - else: - yaml_path = "yaml/lib3" - sys.path += [yaml_path] - from yaml import safe_load - - load_from_yaml(safe_load, ctx, data_by_uid, path, path) + load_from_yaml(ctx, data_by_uid, path, path) with open(cache_file, "wb") as f: pickle.dump(data_by_uid, f) else: @@ -1280,6 +1268,25 @@ def load_items(ctx, specs): load_items_in_directory(ctx, ctors, path) +try: + # + # Try to use the system-provided yaml module with libyaml support. + # + from yaml import load, CSafeLoader as SafeLoader +except ImportError: + # + # Fall back to the Python implementation provided by the project. This + # reduces the host system requirements to a simple Python 2.7 or 3 + # installation without extra modules. + # + if sys.version_info[0] == 2: + yaml_path = "yaml/lib" + else: + yaml_path = "yaml/lib3" + sys.path += [yaml_path] + from yaml import load, SafeLoader + + def load_items_from_options(ctx): specs = ctx.options.rtems_specs if specs is not None: |