Skip to content
Snippets Groups Projects
Commit 96d2346d authored by Simon Rose's avatar Simon Rose
Browse files

Rewrote the .template/.substitution expansion

This is necessary for the following reason: the previous mechanism used an
eval/call combination that required SUBS and TMPS to be exported on a previous
pass through. This allowed us to use `vpath` for each specific file in order
to locate the correct source files.

In order to avoid that, we add two new ingredients:
* `VPATH` instead of `vpath`, since it allows us to have variables
  that are expanded later
* `.SECONDEXPANSION`, which allows a target (`db_internal`, in this case) to
  perform a second variable expansion at the _end_ of the pass through.

All of this is necessary because the typical module makefile looks like:
```
include driver.makefile

SUBS += ...
```
i.e. `SUBS` and `TMPS` are defined _after_ the inclusion of driver.makefile. If
we don't want to force a re-write of every single module makefile, we needed
to do some of the above changes.
parent d666ced4
No related branches found
No related tags found
No related merge requests found
......@@ -187,9 +187,6 @@ ifndef EPICSVERSION
## RUN 1
# In source directory
export SUBS
export TMPS
debug::
@echo "===================== Pass 1 ====================="
@echo "BUILD_EPICS_VERSIONS = ${BUILD_EPICS_VERSIONS}"
......@@ -302,18 +299,18 @@ db_internal: $(COMMON_DIR)
-include $(COMMON_DIR)/*.db.d
define SUBS_EXPAND
vpath $(notdir $2) $(dir $2)
db_internal: $(COMMON_DIR)/$(notdir $(basename $2).db)
VPATH += $(dir $(TMPS))
VPATH += $(dir $(SUBS))
$(COMMON_DIR)/$(notdir $(basename $2).db): $(notdir $2)
@printf "Inflating database ... %44s >>> %40s \n" "$$^" "$$@"
$(QUIET)$(MSI) -D $$(USR_DBFLAGS) -o $(COMMON_DIR)/$$(notdir $$(basename $2).db) $1 $$^ > $(COMMON_DIR)/$$(notdir $$(basename $2).db).d
$(QUIET)$(MSI) $$(USR_DBFLAGS) -o $(COMMON_DIR)/$$(notdir $$(basename $2).db) $1 $$^
endef
$(COMMON_DIR)/%.db: %.template
@printf "Inflating database ... %44s >>> %40s \n" "$^" "$@"
$(QUIET)$(MSI) -D $(USR_DBFLAGS) -o $(COMMON_DIR)/$(notdir $(basename $@).db) $^ > $(COMMON_DIR)/$(notdir $(basename $@).db).d
$(QUIET)$(MSI) $(USR_DBFLAGS) -o $(COMMON_DIR)/$(notdir $(basename $@).db) $^
$(foreach file,$(SUBS),$(eval $(call SUBS_EXPAND,-S,$(file))))
$(foreach file,$(TMPS),$(eval $(call SUBS_EXPAND,,$(file))))
$(COMMON_DIR)/%.db: %.substitutions
@printf "Inflating database ... %44s >>> %40s \n" "$^" "$@"
$(QUIET)$(MSI) -D $(USR_DBFLAGS) -o $(COMMON_DIR)/$(notdir $(basename $@).db) -S $^ > $(COMMON_DIR)/$(notdir $(basename $@).db).d
$(QUIET)$(MSI) $(USR_DBFLAGS) -o $(COMMON_DIR)/$(notdir $(basename $@).db) -S $^
install build debug::
......@@ -334,6 +331,12 @@ install build debug:: $(COMMON_DIR)
done; \
((failed_builds == 0))
# This has to fit under .SECONDEXPANSION in order to catch TMPS and SUBS, which are typically defined
# _after_ driver.makefile is included.
.SECONDEXPANSION:
db_internal: $$(addprefix $(COMMON_DIR)/,$$(notdir $$(patsubst %.template,%.db,$$(TMPS))))
db_internal: $$(addprefix $(COMMON_DIR)/,$$(notdir $$(patsubst %.substitutions,%.db,$$(SUBS))))
else # T_A
......
......@@ -472,6 +472,42 @@ def test_updated_template_files(wrapper):
assert db_file.read_text() == "record(ai, updated) {}"
def test_expand_db_files(wrapper):
wrapper.add_var_to_makefile("TMPS", "templates/a.template")
wrapper.add_var_to_makefile("SUBS", "b.substitutions")
wrapper.add_var_to_makefile("USR_DBFLAGS", "-I templates")
template_dir = wrapper.module_dir / "templates"
template_dir.mkdir()
template_file = template_dir / "a.template"
template_file_contents = "record (ai, $(P)) {}"
template_file.write_text(template_file_contents)
substitution_file = wrapper.module_dir / "b.substitutions"
substitution_file.write_text(
"""file "a.template"
{
pattern { P }
{ "$(PREF)" }
}
"""
)
base_version = wrapper.get_env_var("EPICS_VERSION_NUMBER")
common_dir = wrapper.module_dir / f"O.{base_version}_Common"
rc, *_ = wrapper.run_make("db_internal")
assert rc == 0
expanded_template_file = common_dir / "a.db"
assert expanded_template_file.read_text() == template_file_contents
expanded_substitution_file = common_dir / "b.db"
assert expanded_substitution_file.read_text() == template_file_contents.replace(
"$(P)", "$(PREF)"
)
@pytest.mark.parametrize(
"installed_archs, param, expected",
[
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment