diff --git a/Makefile b/Makefile index 8cf2f8fb..e5726179 100644 --- a/Makefile +++ b/Makefile @@ -298,11 +298,13 @@ $(OBJDIR)/shared/commands.o: inc/commandslist.h inc/commandslist.h: tools/create_cmd.py $(SOURCES) @echo Generating commands list - @$(PYTHON) tools/create_cmd.py inc/commandslist.h $(SOURCES) + @$(MKDIR) -p $(dir $@) + @$(PYTHON) tools/create_cmd.py $@ $(SOURCES) src/hal_tbl.c: tools/create_hal_tbl.py $(COMPS) @echo Generating HAL table - @$(PYTHON) tools/create_hal_tbl.py src/hal_tbl.c $(COMPS) + @$(MKDIR) -p $(dir $@) + @$(PYTHON) tools/create_hal_tbl.py $@ $(COMPS) $(SRC_COMP_OBJECTS): $(OBJDIR)/src/comps/%.o: inc/comps/%_comp.h @@ -310,14 +312,17 @@ $(SHARED_COMP_OBJECTS): $(OBJDIR)/shared/comps/%.o: inc/shared_comps/%_comp.h inc/comps/%_comp.h: src/comps/%.c @echo Generating H: $< + @$(MKDIR) -p $(dir $@) @$(PYTHON) tools/create_comp_h.py $@ $< inc/shared_comps/%_comp.h: shared/comps/%.c @echo Generating H: $< + @$(MKDIR) -p $(dir $@) @$(PYTHON) tools/create_comp_h.py $@ $< src/conf_templates.c: tools/create_config.py $(CONFIG_TEMPLATES) @echo Generating config + @$(MKDIR) -p $(dir $@) @$(PYTHON) tools/create_config.py src/conf_templates.c $(CONFIG_TEMPLATES) tbl: inc/commandslist.h src/hal_tbl.c src/conf_templates.c diff --git a/stm32f303/Makefile b/stm32f303/Makefile index 6e0d0edf..9aceb369 100644 --- a/stm32f303/Makefile +++ b/stm32f303/Makefile @@ -205,11 +205,13 @@ $(OBJDIR)/shared/commands.o: stm32f303/inc/commandslist.h stm32f303/inc/commandslist.h: tools/create_cmd.py $(SOURCES) @echo Generating commands list - @$(PYTHON) tools/create_cmd.py stm32f303/inc/commandslist.h $(SOURCES) + @$(MKDIR) -p $(dir $@) + @$(PYTHON) tools/create_cmd.py $@ $(SOURCES) stm32f303/src/hal_tbl.c: tools/create_hal_tbl.py $(COMPS) @echo Generating HAL table - @$(PYTHON) tools/create_hal_tbl.py stm32f303/src/hal_tbl.c $(COMPS) + @$(MKDIR) -p $(dir $@) + @$(PYTHON) tools/create_hal_tbl.py $@ $(COMPS) $(SRC_COMP_OBJECTS): $(OBJDIR)/stm32f303/src/comps/%.o: stm32f303/inc/comps/%_comp.h @@ -217,10 +219,12 @@ $(SHARED_COMP_OBJECTS): $(OBJDIR)/shared/comps/%.o: stm32f303/inc/shared_comps/% stm32f303/inc/comps/%_comp.h: stm32f303/src/comps/%.c @echo Generating H: $< + @$(MKDIR) -p $(dir $@) @$(PYTHON) tools/create_comp_h.py $@ $< stm32f303/inc/shared_comps/%_comp.h: shared/comps/%.c @echo Generating H: $< + @$(MKDIR) -p $(dir $@) @$(PYTHON) tools/create_comp_h.py $@ $< tbl: stm32f303/src/hal_tbl.c stm32f303/inc/commandslist.h diff --git a/tools/create_cmd.py b/tools/create_cmd.py index e19ac664..b1aa4c1d 100755 --- a/tools/create_cmd.py +++ b/tools/create_cmd.py @@ -1,7 +1,6 @@ #!/usr/bin/env python import re import sys -import file_updater cmd = [] @@ -12,7 +11,7 @@ for infile in sys.argv[2:]: if match: cmd.append((match.groups(), infile, line_number)) -header = file_updater.FileUpdater(sys.argv[1]) +header = open(sys.argv[1], 'w') header.write("//generated by " + sys.argv[0] + " DO NOT EDIT\n") diff --git a/tools/create_comp_h.py b/tools/create_comp_h.py index 9912aa2d..920263d5 100644 --- a/tools/create_comp_h.py +++ b/tools/create_comp_h.py @@ -1,7 +1,6 @@ #!/usr/bin/env python import re import sys -import file_updater infile = sys.argv[2] with open(sys.argv[2]) as f: # TODO raise error if file cannot be opened instead of silently succeeding @@ -19,7 +18,7 @@ with open(sys.argv[2]) as f: # TODO raise error if file cannot be opened instead if pin: pins.append((pin.groups()[0], int(pin.groups()[1]))) - header = file_updater.FileUpdater(sys.argv[1]) + header = open(sys.argv[1], 'w') header.write("#pragma once\n") header.write("//generated by " + sys.argv[0] + " DO NOT EDIT\n\n") header.write("#include \"hal.h\"\n") diff --git a/tools/create_config.py b/tools/create_config.py index b2704aff..108e5349 100755 --- a/tools/create_config.py +++ b/tools/create_config.py @@ -2,7 +2,6 @@ import re import sys import os -import file_updater config = [] @@ -10,7 +9,7 @@ for infile in sys.argv[2:]: with open(infile) as f: config.append((os.path.splitext(os.path.basename(infile))[0], f.read())) -code = file_updater.FileUpdater(sys.argv[1]) +code = open(sys.argv[1], 'w') code.write("//generated by " + sys.argv[0] + " DO NOT EDIT\n\n") code.write("#include \"config.h\"\n\n") diff --git a/tools/create_hal_tbl.py b/tools/create_hal_tbl.py index 920ff2c0..3ee4d53e 100755 --- a/tools/create_hal_tbl.py +++ b/tools/create_hal_tbl.py @@ -1,11 +1,10 @@ #!/usr/bin/env python import re import sys -import file_updater comps = [] -code = file_updater.FileUpdater(sys.argv[1]) +code = open(sys.argv[1], 'w') for infile in sys.argv[2:]: with open(infile) as f: diff --git a/tools/file_updater.py b/tools/file_updater.py deleted file mode 100644 index c29e6540..00000000 --- a/tools/file_updater.py +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env python -import shutil -import tempfile -import filecmp -import os - -def copyIfDifferent(src, dst_path): - dst = None - try: - dst = open(dst_path, 'r+') - src.seek(0) - if src.read() == dst.read(): - pass#return - dst.seek(0) - except: - pass - if dst is None: - dst = open(dst_path, 'w') - src.seek(0) - shutil.copyfileobj(src, dst) - -class FileUpdater: - def __init__(self, path): - os.makedirs(os.path.dirname(path), exist_ok=True) - self.filePath = path - self.tempFile = tempfile.TemporaryFile(mode='r+') - - def __del__(self): - if not self.tempFile.closed: - self.close() - - def write(self, data): - self.tempFile.write(data) - - def close(self): - copyIfDifferent(self.tempFile, self.filePath) - self.tempFile.close()