From 88d52c1dc5f27b365e513c36fbc1c6b8f6a25a76 Mon Sep 17 00:00:00 2001 From: James Duley Date: Sat, 14 May 2016 18:25:22 +0100 Subject: [PATCH] Make sure version-info is always updated when needed by doing it every time but only writing if different --- Makefile | 6 +++-- make/scripts/version-info.py | 43 +++++++++++++++++++++--------------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index dde9d8cb3..21490caee 100644 --- a/Makefile +++ b/Makefile @@ -376,10 +376,12 @@ include $(ROOT_DIR)/package/$(UNAME).mk # Source for distribution # ############################## -$(DIST_VER_INFO): .git/index | $(DIST_DIR) +FORCE: + +$(DIST_VER_INFO): FORCE | $(DIST_DIR) $(V1) $(VERSION_INFO) --jsonpath="$(DIST_DIR)" -$(DIST_TAR): $(DIST_VER_INFO) .git/index | $(DIST_DIR) +$(DIST_TAR): $(DIST_VER_INFO) | $(DIST_DIR) @$(ECHO) " SOURCE FOR DISTRIBUTION $(call toprel, $(DIST_TAR))" $(V1) git archive --prefix="$(PACKAGE_NAME)/" -o "$(DIST_TAR)" HEAD $(V1) tar --append --file="$(DIST_TAR)" \ diff --git a/make/scripts/version-info.py b/make/scripts/version-info.py index 47d94a1ce..a06e96b21 100644 --- a/make/scripts/version-info.py +++ b/make/scripts/version-info.py @@ -252,8 +252,29 @@ class Repo: json_data['dirty'] = False json_path = os.path.join(path, 'version-info.json') - with open(json_path, 'w') as json_file: - json.dump(json_data, json_file) + + write_if_different(json_path, json.dumps(json_data)) + + +def write_if_different(out_name, out): + """Write ouput to file only if it differs from current""" + + # Check if output file already exists + try: + of = open(out_name, "rb") + except IOError: + # No file - create new + of = open(out_name, "wb") + of.write(out) + of.close() + else: + # File exists - overwite only if content is different + inp = of.read() + of.close() + if inp != out: + of = open(out_name, "wb") + of.write(out) + of.close() def escape_dict(dictionary): """Escapes dictionary values for C""" @@ -300,22 +321,8 @@ def file_from_template(tpl_name, out_name, dictionary): # Replace placeholders using dictionary out = Template(tpl).substitute(dictionary) - # Check if output file already exists - try: - of = open(out_name, "rb") - except IOError: - # No file - create new - of = open(out_name, "wb") - of.write(out) - of.close() - else: - # File exists - overwite only if content is different - inp = of.read() - of.close() - if inp != out: - of = open(out_name, "wb") - of.write(out) - of.close() + write_if_different(out_name, out) + def sha1(file): """Provides C source representation of sha1 sum of file"""