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

Remove record search from expandDBD

See https://github.com/paulscherrerinstitute/require/commit/134aed5a5e618ae12a95134862401f1dcc92c834
for some context. Instead of searching recursively through .dbd files, one
can instead just filter source files for `%Record.(c|cc|cpp)`. This simplifies
the special python/tcl/pl script to handle dbd files.
parent 2ae7937a
No related branches found
No related tags found
1 merge request!135E3-1132: Remove record search from expandDBD
Pipeline #153466 passed
......@@ -219,11 +219,11 @@ DBD_SRCS = $(if ${DBDS},$(filter-out -none-,${DBDS}),$(wildcard menu*.dbd *Recor
DBD_SRCS += ${DBDS_${EPICSVERSION}}
export DBD_SRCS
#record dbd files given in DBDS
RECORDS1 = $(patsubst %Record.dbd, %, $(filter-out dev%, $(filter %Record.dbd, $(notdir ${DBD_SRCS}))))
#record dbd files included by files given in DBDS
RECORDS2 = $(filter-out dev%, $(shell ${MAKEHOME}/expandDBD -r $(addprefix -I, $(sort $(dir ${DBD_SRCS}))) $(realpath ${DBDS}) 2> /dev/null))
RECORDS = $(sort ${RECORDS1} ${RECORDS2})
# Read dbd files from source files. Note that this assumes that any xxxRecord.(c|cpp|...) has
# a corresponding xxxRecord.dbd, which is used to generate xxxRecord.h; this is standard usage
# in EPICS. However, if such a .dbd file does not exist, then the build will fail due to the
# "missing" header file.
RECORDS = $(filter %Record,$(basename $(notdir $(SRCS))))
export RECORDS
MENUS = $(patsubst %.dbd,%.h,$(wildcard menu*.dbd))
......@@ -237,7 +237,8 @@ DBDINSTALLS += $(MENUS)
DBDINSTALLS += $(BPTS)
export DBDINSTALLS
HDRS = ${HEADERS} $(addprefix ${COMMON_DIR}/,$(addsuffix Record.h,${RECORDS}))
HDRS = ${HEADERS}
HDRS += $(RECORDS:%=${COMMON_DIR}/%.h)
HDRS += ${HEADERS_${EPICSVERSION}}
export HDRS
......@@ -576,9 +577,10 @@ debug::
build: MODULEINFOS
build: ${MODULEDBD}
build: $(addprefix ${COMMON_DIR}/,$(addsuffix Record.h,${RECORDS}))
build: ${DEPFILE}
COMMON_INC = ${RECORDS:%=${COMMON_DIR}/%.h}
# Include default EPICS Makefiles (version dependent).
# Avoid library installation when doing 'make build'.
INSTALL_LOADABLE_SHRLIBS=
......
......@@ -58,41 +58,16 @@ def expand_dbd_file(current_file, dbdlines, includes):
print(line)
def parse_record_dbd_file(current_file, dbdlines, includes):
"""Recursively search through .dbd files for xRecord.dbd, and print the record names."""
for line in dbdlines:
if BLANK_LINE_REGEX.match(line):
continue
m = RECORD_REGEX.search(line)
if m:
if find_dbd_file(m.group(1), includes):
print(m.group(2))
else:
print(
"File '{group}' not found".format(group=m.group(1)), file=sys.stderr
)
sys.exit(1)
continue
m = INCLUDE_REGEX.search(line)
if m:
lines = open_dbd_file(current_file, m.group(1), includes)
parse_record_dbd_file(m.group(1), lines, includes)
def handle_dbd_file(dbdfiles, include, record_types):
def handle_dbd_file(dbdfiles, include):
"""Process the .dbd files."""
for dbdfile in dbdfiles:
lines = open_dbd_file("command line", dbdfile, include)
if record_types:
parse_record_dbd_file(dbdfile, lines, include)
else:
expand_dbd_file(dbdfile, lines, include)
expand_dbd_file(dbdfile, lines, include)
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-I", "--include", action="append")
parser.add_argument("-r", "--record-types", action="store_true")
parser.add_argument("dbdfiles", nargs="+")
args = parser.parse_args()
......
......@@ -717,3 +717,17 @@ def test_metadata_not_installed_if_arch_fails(wrapper: Wrapper):
)
assert rc == 2
assert not (wrapper.package_dir / f"{wrapper.name}_meta.yaml").exists()
def test_missing_record_dbd_file_causes_build_failure(wrapper: Wrapper):
wrapper.add_file("fooRecord.c")
wrapper.add_var_to_module_makefile("SOURCES", "fooRecord.c")
rc, _, errs = wrapper.run_make("build")
assert rc != 0
assert re.search(
RE_MISSING_FILE.format(
filename=re.escape(f"../O.{wrapper.base_version}_Common/fooRecord.dbd")
),
errs,
)
......@@ -75,33 +75,3 @@ def test_do_not_skip_repeated_include_common_dbd(tmp_path, expanddbdtcl):
)
assert result.returncode == 0
assert result.stdout == "content\ncontent\n"
def test_record_names_from_dbds(tmp_path, expanddbdtcl):
dbd_a = tmp_path / "a.dbd"
dbd_a.write_text("include aRecord.dbd")
dbd_record = tmp_path / "aRecord.dbd"
dbd_record.touch()
result = subprocess.run(
[expanddbdtcl, "-r", "-I", str(tmp_path), dbd_a],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding="utf-8",
)
assert result.returncode == 0
assert result.stdout.splitlines() == ["a"]
def test_missing_record_names_from_dbds(tmp_path, expanddbdtcl):
dbd_a = tmp_path / "a.dbd"
dbd_a.write_text("include aRecord.dbd")
result = subprocess.run(
[expanddbdtcl, "-r", "-I", str(tmp_path), dbd_a],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding="utf-8",
)
assert result.returncode == 1
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