uorb topic header generator: only create new files if the file content really changed

This commit is contained in:
Thomas Gubler
2014-12-04 10:39:24 +01:00
parent 83d97fd1c2
commit 8e8f84bde0
2 changed files with 90 additions and 36 deletions
+4 -1
View File
@@ -227,12 +227,15 @@ updatesubmodules:
MSG_DIR = $(PX4_BASE)msg/px4_msgs MSG_DIR = $(PX4_BASE)msg/px4_msgs
MSG_TEMPLATE_DIR = $(PX4_BASE)msg/templates MSG_TEMPLATE_DIR = $(PX4_BASE)msg/templates
TOPICS_DIR = $(PX4_BASE)src/modules/uORB/topics TOPICS_DIR = $(PX4_BASE)src/modules/uORB/topics
TOPICS_TEMPORARY_DIR = $(BUILD_DIR)topics_temporary
.PHONY: generateuorbtopicheaders .PHONY: generateuorbtopicheaders
generateuorbtopicheaders: generateuorbtopicheaders:
@$(ECHO) "Generating uORB topic headers" @$(ECHO) "Generating uORB topic headers"
$(Q) ($(PX4_BASE)/Tools/px_generate_uorb_topic_headers.py -d $(MSG_DIR) \ $(Q) ($(PX4_BASE)/Tools/px_generate_uorb_topic_headers.py -d $(MSG_DIR) \
-o $(TOPICS_DIR) -e $(MSG_TEMPLATE_DIR)) -o $(TOPICS_DIR) -e $(MSG_TEMPLATE_DIR) -t $(TOPICS_TEMPORARY_DIR))
# clean up temporary files
$(Q) (rm -r $(TOPICS_TEMPORARY_DIR))
# #
# Testing targets # Testing targets
+54 -3
View File
@@ -39,6 +39,8 @@ message files
""" """
from __future__ import print_function from __future__ import print_function
import os import os
import shutil
import filecmp
import argparse import argparse
import genmsg.template_tools import genmsg.template_tools
@@ -76,7 +78,46 @@ def convert_dir(inputdir, outputdir, templatedir):
for f in os.listdir(inputdir): for f in os.listdir(inputdir):
fn = os.path.join(inputdir, f) fn = os.path.join(inputdir, f)
if os.path.isfile(fn): if os.path.isfile(fn):
convert_file(fn, outputdir, templatedir, includepath) convert_file(
fn,
outputdir,
templatedir,
includepath)
def copy_changed(inputdir, outputdir):
"""
Copies files from inputdir to outputdir if they don't exist in
ouputdir or if their content changed
"""
for f in os.listdir(inputdir):
fni = os.path.join(inputdir, f)
if os.path.isfile(fni):
# Check if f exists in outpoutdir, copy the file if not
fno = os.path.join(outputdir, f)
if not os.path.isfile(fno):
shutil.copy(fni, fno)
print("{0}: new header file".format(f))
continue
# The file exists in inputdir and outputdir
# only copy if contents do not match
if not filecmp.cmp(fni, fno):
shutil.copy(fni, fno)
print("{0}: updated".format(f))
continue
print("{0}: unchanged".format(f))
def convert_dir_save(inputdir, outputdir, templatedir, temporarydir):
"""
Converts all .msg files in inputdir to uORB header files
Unchanged existing files are not overwritten.
"""
# Create new headers in temporary output directory
convert_dir(inputdir, temporarydir, templatedir)
# Copy changed headers from temporary dir to output dir
copy_changed(temporarydir, outputdir)
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
@@ -89,10 +130,20 @@ if __name__ == "__main__":
help='directory with template files',) help='directory with template files',)
parser.add_argument('-o', dest='outputdir', parser.add_argument('-o', dest='outputdir',
help='output directory for header files') help='output directory for header files')
parser.add_argument('-t', dest='temporarydir',
help='temporary directory')
args = parser.parse_args() args = parser.parse_args()
if args.file is not None: if args.file is not None:
for f in args.file: for f in args.file:
convert_file(f, args.outputdir, args.templatedir, incl_default) convert_file(
f,
args.outputdir,
args.templatedir,
incl_default)
elif args.dir is not None: elif args.dir is not None:
convert_dir(args.dir, args.outputdir, args.templatedir) convert_dir_save(
args.dir,
args.outputdir,
args.templatedir,
args.temporarydir)