1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-30 15:52:12 +01:00

Make sure version-info is always updated when needed

by doing it every time but only writing if different
This commit is contained in:
James Duley 2016-05-14 18:25:22 +01:00
parent 97f5d36fea
commit 88d52c1dc5
2 changed files with 29 additions and 20 deletions

View File

@ -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)" \

View File

@ -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"""