efrocache trial run 2

This commit is contained in:
Eric Froemling 2019-10-12 16:55:47 -07:00
parent 3992db622b
commit 0c3f02af89
2 changed files with 11 additions and 3 deletions

View File

@ -34,7 +34,7 @@ all: help
# Tell make which of these targets don't represent files.
.PHONY: all
build/testfile: $(PROJ_DIR)/.efrocachemap
build/testfile: .efrocachemap
tools/snippets efrocache_get $@

View File

@ -98,7 +98,15 @@ def get_target(path: str) -> None:
def filter_makefile(makefile_dir: str, contents: str) -> str:
"""Filter makefile contents to use efrocache lookups."""
cachemap = '$(PROJ_DIR)/.efrocachemap'
if makefile_dir:
# Assuming just one level deep at the moment; can revisit later.
assert '/' not in makefile_dir
to_proj_root = '..'
else:
to_proj_root = ''
cachemap = os.path.join(to_proj_root, '.efrocachemap')
lines = contents.splitlines()
snippets = 'tools/snippets'
@ -120,7 +128,7 @@ def filter_makefile(makefile_dir: str, contents: str) -> str:
del lines[index:endindex]
lines.insert(index, tname + ': ' + cachemap)
target = (makefile_dir + '/' + '$@') if makefile_dir else '$@'
pre = 'cd $(PROJ_DIR) && ' if makefile_dir else ''
pre = 'cd {to_proj_root} && ' if makefile_dir else ''
lines.insert(index + 1, f'\t{pre}{snippets} efrocache_get {target}')
return '\n'.join(lines) + '\n'