Skip to content

Commit 8ea9f34

Browse files
oharboeclaude
andcommitted
flow: the OPENROAD_EXE and YOSYS_EXE checks split the command as the shell does
check-openroad and check-yosys took the command's first word with make's firstword, which splits on spaces before the shell reads quotes and escapes. A quoted path with a space in it, as the executable or as a wrapper, failed the check although the recipe runs it; test -x accepted a quoted single executable before OPENROAD_EXE became a command. Both checks now take the shell's first argument: the command is split by `set --` in the check's shell, as a recipe splits it, and that argument is looked up with command -v. test_openroad_exe.py checks a quoted executable and a quoted wrapper path with a space in it for OPENROAD_EXE and YOSYS_EXE, that the same commands with a missing directory still fail, and that the recipe runs the quoted wrapper. The quoted cases failed before this change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent 1442445 commit 8ea9f34

2 files changed

Lines changed: 41 additions & 2 deletions

File tree

‎flow/scripts/variables.mk‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ export OPENSTA_EXE ?= $(abspath $(FLOW_HOME)/../tools/install/OpenROAD/bin/sta)
131131
# come first, as in OPENROAD_EXE="gdb --args openroad" or
132132
# OPENROAD_EXE="valgrind openroad". The check is on the program the command
133133
# starts with, a path or a name on PATH. The binary is the last word.
134-
OPENROAD_IS_VALID := $(if $(OPENROAD_EXE),$(shell command -v $(firstword $(OPENROAD_EXE)) >/dev/null && echo "true"),)
134+
# The shell splits the command, as a recipe does, so a quoted path with
135+
# spaces in it is one program: OPENROAD_EXE="'/opt/my tools/openroad'".
136+
command_is_valid = $(if $(1),$(shell set -- $(1) && command -v "$$1" >/dev/null && echo "true"),)
137+
OPENROAD_IS_VALID := $(call command_is_valid,$(OPENROAD_EXE))
135138

136139
export OPENROAD_ARGS = -no_init -threads $(NUM_CORES) $(OR_ARGS)
137140
export OPENROAD_CMD = $(OPENROAD_EXE) -exit $(OPENROAD_ARGS)
@@ -141,7 +144,7 @@ export OPENROAD_WEB_CMD = $(OPENROAD_EXE) -web -threads $(NUM_CORES) $(OR_ARGS)
141144

142145
export YOSYS_EXE ?= $(abspath $(FLOW_HOME)/../tools/install/yosys/bin/yosys)
143146

144-
YOSYS_IS_VALID := $(if $(YOSYS_EXE),$(shell command -v $(firstword $(YOSYS_EXE)) >/dev/null && echo "true"),)
147+
YOSYS_IS_VALID := $(call command_is_valid,$(YOSYS_EXE))
145148

146149
KEPLER_FORMAL_EXE ?= $(abspath $(FLOW_HOME)/../tools/install/kepler-formal/bin/kepler-formal)
147150
export KEPLER_FORMAL_EXE

‎flow/test/test_openroad_exe.py‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,42 @@ def test_wrapped_yosys_passes_the_check(self):
110110
result, _ = self.make("check-yosys", f"YOSYS_EXE={self.wrapper} {yosys}")
111111
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
112112

113+
def test_quoted_paths_pass_the_check(self):
114+
# the shell splits the command, so a quoted path with spaces in it
115+
# is one program, as the executable or as the wrapper
116+
spaced = os.path.join(self.tmp_dir.name, "with space")
117+
os.makedirs(spaced)
118+
openroad = os.path.join(spaced, "openroad")
119+
yosys = os.path.join(spaced, "yosys")
120+
wrapper = os.path.join(spaced, "wrapper")
121+
for link, target in ((openroad, self.openroad), (wrapper, self.wrapper)):
122+
os.symlink(target, link)
123+
os.symlink(self.script("yosys", "true\n"), yosys)
124+
for check, variable, binary in (
125+
("check-openroad", "OPENROAD_EXE", openroad),
126+
("check-yosys", "YOSYS_EXE", yosys),
127+
):
128+
for command in (f"'{binary}'", f"'{wrapper}' '{binary}'"):
129+
with self.subTest(check=check, command=command):
130+
result, _ = self.make(check, f"{variable}={command}")
131+
self.assertEqual(
132+
result.returncode, 0, result.stdout + result.stderr
133+
)
134+
missing = command.replace("with space", "no such")
135+
result, _ = self.make(check, f"{variable}={missing}")
136+
self.assertNotEqual(result.returncode, 0)
137+
138+
def test_quoted_path_runs(self):
139+
# the recipe runs the quoted path the check accepted
140+
spaced = os.path.join(self.tmp_dir.name, "with space")
141+
os.makedirs(spaced)
142+
wrapper = os.path.join(spaced, "wrapper")
143+
os.symlink(self.wrapper, wrapper)
144+
result, calls = self.make(
145+
"command", f"OPENROAD_EXE='{wrapper}' {self.openroad}"
146+
)
147+
self.assert_wrapped_once(result, calls)
148+
113149
def test_top_level_rule_runs_the_command_once(self):
114150
for how in ("command line", "environment"):
115151
with self.subTest(how):

0 commit comments

Comments
 (0)