improved build time by having Python generated code preserve it's modification date when it's content isn't changing

This commit is contained in:
Forest Darling
2020-09-16 03:10:53 -05:00
parent a8506ca21f
commit a0fa67fdcc
6 changed files with 70 additions and 24 deletions
+2 -2
View File
@@ -295,8 +295,8 @@ src/conf_templates.c: tbl
tbl:
@echo Generating tables
@$(PYTHON) tools/create_hal_tbl.py . $(COMPS)
@$(PYTHON) tools/create_config.py conf/template/* > src/conf_templates.c
@$(PYTHON) tools/create_cmd.py $(SOURCES) > inc/commandslist.h
@$(PYTHON) tools/create_config.py src/conf_templates.c conf/template/*
@$(PYTHON) tools/create_cmd.py inc/commandslist.h $(SOURCES)
#build f4 bootloader
boot:
+1 -1
View File
@@ -201,7 +201,7 @@ tbl:
@echo Generating tables
@$(PYTHON) tools/create_hal_tbl.py stm32f303/ $(COMPS)
#shared/comps/*.c src/comps/hw/*.c src/comps/*.c
@$(PYTHON) tools/create_cmd.py $(SOURCES) > stm32f303/inc/commandslist.h
@$(PYTHON) tools/create_cmd.py stm32f303/inc/commandslist.h $(SOURCES)
# Target: clean project
#
+12 -7
View File
@@ -1,24 +1,29 @@
#!/usr/bin/env python
import re
import sys
import file_updater
cmd = []
for infile in sys.argv[1:]:
for infile in sys.argv[2:]:
with open(infile) as f:
for line_number, line in enumerate(f):
match = re.search('COMMAND\("(\w*)", *(\w*), *"([^"]*)"\);', line)
if match:
cmd.append((match.groups(), infile, line_number))
print ("//generated by " + sys.argv[0] + " DO NOT EDIT")
header = file_updater.FileUpdater(sys.argv[1])
header.write("//generated by " + sys.argv[0] + " DO NOT EDIT\n")
for (name, ptr, doc), file_name, line_number in cmd:
print ("extern void " + ptr + "(char *); // found in " + file_name + " line: " + str(line_number + 1))
header.write("extern void " + ptr + "(char *); // found in " + file_name + " line: " + str(line_number + 1) + "\n")
print ("\n")
header.write("\n\n")
print ("cmd_t cmd[] = {")
header.write("cmd_t cmd[] = {\n")
for (name, ptr, doc), file_name, line_number in cmd:
print (" {\"" + name + "\", \"" + doc + "\", " + ptr + "}, // found in " + file_name + " line: " + str(line_number + 1))
print ("};")
header.write(" {\"" + name + "\", \"" + doc + "\", " + ptr + "}, // found in " + file_name + " line: " + str(line_number + 1) + "\n")
header.write("};\n")
header.close()
+16 -11
View File
@@ -2,24 +2,29 @@
import re
import sys
import os
import file_updater
config = []
for infile in sys.argv[1:]:
for infile in sys.argv[2:]:
with open(infile) as f:
config.append((os.path.splitext(os.path.basename(infile))[0], f.read()))
print ("//generated by " + sys.argv[0] + " DO NOT EDIT\n")
print ("#include \"config.h\"\n")
print ("const uint32_t num_of_config_templates = " + str(len(config)) + ";\n")
code = file_updater.FileUpdater(sys.argv[1])
print ("config_template_t config_templates[] = {")
code.write("//generated by " + sys.argv[0] + " DO NOT EDIT\n\n")
code.write("#include \"config.h\"\n\n")
code.write("const uint32_t num_of_config_templates = " + str(len(config)) + ";\n\n")
code.write("config_template_t config_templates[] = {\n")
for index, (file_name, content) in enumerate(config):
print ("{")
print (".name = \"" + file_name + "\",")
print (".config = \"\\")
code.write("{\n")
code.write(".name = \"" + file_name + "\",\n")
code.write(".config = \"\\\n")
for line in content.splitlines():
print (line + "\\n\\")
print ("\"\n},\n")
print ("};")
code.write(line + "\\n\\\n")
code.write("\"\n},\n\n")
code.write("};\n")
code.close()
+4 -3
View File
@@ -1,11 +1,12 @@
#!/usr/bin/env python
import re
import sys
import file_updater
comps = []
header = open(sys.argv[1] + '/inc/hal_tbl.h', 'w')
code = open(sys.argv[1] + '/src/hal_tbl.c', 'w')
header = file_updater.FileUpdater(sys.argv[1] + '/inc/hal_tbl.h')
code = file_updater.FileUpdater(sys.argv[1] + '/src/hal_tbl.c')
for infile in sys.argv[2:]:
with open(infile) as f:
@@ -65,7 +66,7 @@ for comp_name, pins, file_name in comps:
header.write("extern const hal_comp_t " + comp_name + "_comp_struct; // found in " + file_name + "\n")
code.write("#include \"hal.h\"\n")
code.write("#include \"hal.h\"\n\n")
code.write("//generated by " + sys.argv[0] + " DO NOT EDIT\n\n")
code.write("const hal_comp_t * comps[] = {\n")
for comp_name, pins, file_name in comps:
+35
View File
@@ -0,0 +1,35 @@
#!/usr/bin/env python
import shutil
import tempfile
import filecmp
def copyIfDifferent(src, dst_path):
dst = None
try:
dst = open(dst_path, 'rw+b')
src.seek(0)
if src.read() == dst.read():
return
dst.seek(0)
except:
pass
if dst is None:
dst = open(dst_path, 'w+b')
src.seek(0)
shutil.copyfileobj(src, dst)
class FileUpdater:
def __init__(self, path):
self.filePath = path
self.tempFile = tempfile.TemporaryFile(mode='rw+b')
def __del__(self):
if not self.tempFile.closed:
self.close()
def write(self, str):
self.tempFile.write(str)
def close(self):
copyIfDifferent(self.tempFile, self.filePath)
self.tempFile.close()