Merge pull request #109 from fdarling/fast_make

removed need for file_updater.py
This commit is contained in:
Nico Stute
2020-09-28 13:00:21 +02:00
committed by GitHub
7 changed files with 17 additions and 49 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -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()