summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2023-04-26 10:04:00 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2023-09-26 09:51:40 +0200
commitbb8acbbc513f1955d9687f5bec04ae5c6a3da537 (patch)
tree3990e68ab7f56432cb31c679b3140be72e0a6540
parent02f48f0479967c7d14428bfddee508da45a04bfe (diff)
build: Use CSafeLoader if available
The CSafeLoader uses the C libyaml libary to considerably speed up the loading of YAML files.
-rwxr-xr-xwscript39
1 files changed, 23 insertions, 16 deletions
diff --git a/wscript b/wscript
index 7b0ff932af..76ddea15d2 100755
--- a/wscript
+++ b/wscript
@@ -1200,7 +1200,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:
@@ -1210,11 +1210,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):
@@ -1233,19 +1233,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:
@@ -1278,6 +1266,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: