--- .gitignore | 1 + wscript | 51 ++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 45 insertions(+), 7 deletions(-)
diff --git a/.gitignore b/.gitignore index d7ca74b338..0ff9d6929e 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ doc .lock* Makefile.in *.pyc +/spec/build/items.cache /testsuites/build/bin/fake-rtems5-g++ /testsuites/build/build /testsuites/build/wscript diff --git a/wscript b/wscript index 785272deb9..101bd9b8e1 100755 --- a/wscript +++ b/wscript @@ -27,6 +27,7 @@ from __future__ import print_function +import pickle import os import re import stat @@ -645,22 +646,58 @@ class BuildItemContext(object): self.objects = objects -def load_items_in_directory(ctx, ctors, path): +def must_update_item_cache(ctx, path, mtime): + try: + names = os.listdir(path) + except Exception as e: + ctx.fatal("Cannot list build specification directory: {}".format(e)) + for name in names: + path2 = os.path.join(path, name) + if name.endswith(".yml") and not name.startswith("."): + mtime2 = os.path.getmtime(path2) + if mtime <= mtime2: + return True + else: + mode = os.lstat(path2).st_mode + if stat.S_ISDIR(mode) and must_update_item_cache(ctx, path2, mtime): + return True + return False + + +def create_cache_from_yaml(ctx, data_by_uid, path): try: names = os.listdir(path) except Exception as e: ctx.fatal("Cannot list build specification directory: {}".format(e)) for name in names: - fullname = os.path.join(path, name) + path2 = os.path.join(path, name) if name.endswith(".yml") and not name.startswith("."): uid = os.path.basename(name).replace(".yml", "") - data = yaml.safe_load(open(fullname, "r").read()) - if data["type"] == "build": - items[uid] = ctors[data["build-type"]](uid, data) + with open(path2, "r") as f: + data_by_uid[uid] = yaml.safe_load(f.read()) else: - mode = os.lstat(fullname).st_mode + mode = os.lstat(path2).st_mode if stat.S_ISDIR(mode): - load_items_in_directory(ctx, ctors, fullname) + create_cache_from_yaml(ctx, data_by_uid, path2) + + +def load_items_in_directory(ctx, ctors, path): + cache_file = path + "/items.cache" + try: + mtime = os.path.getmtime(cache_file) + except: + mtime = 0 + data_by_uid = {} + if must_update_item_cache(ctx, path, mtime): + create_cache_from_yaml(ctx, data_by_uid, path) + with open(cache_file, "wb") as f: + pickle.dump(data_by_uid, f) + else: + with open(cache_file, "rb") as f: + data_by_uid = pickle.load(f) + for uid, data in data_by_uid.items(): + if data["type"] == "build": + items[uid] = ctors[data["build-type"]](uid, data) def load_items(ctx, specs): -- 2.16.4 _______________________________________________ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel