Repository navigation
Conversation
With a single $, the variables are immediately expanded in $(eval), which means modifications done in util/utils.mk, such as prefixing with gdb or valgrind, don't take effect. Use $$ instead, which causes the expansion to happen when the `open_*/gui_*/web_*` rules are actually triggered instead of when they're generated. Signed-off-by: ctkiku <kim.kuparinen@tuni.fi>
There was a problem hiding this comment.
Code Review
This pull request updates the OPEN_GUI macro in flow/Makefile to escape the OPENROAD command variables with double dollar signs ($$). The reviewer notes that due to the double expansion mechanism of $(eval $(call ...)) in GNU Make, using $$ is insufficient because the variables are defined later in util/utils.mk. To properly defer expansion until recipe execution, the reviewer recommends escaping the variables with four dollar signs ($$$$).
| open_$(1): | ||
| $(2)=$(RESULTS_DIR)/$(1) $(OPENROAD_NO_EXIT_CMD) $(SCRIPTS_DIR)/open.tcl | ||
| $(2)=$(RESULTS_DIR)/$(1) $$(OPENROAD_NO_EXIT_CMD) $(SCRIPTS_DIR)/open.tcl | ||
| gui_$(1): | ||
| $(2)=$(RESULTS_DIR)/$(1) $(OPENROAD_GUI_CMD) $(SCRIPTS_DIR)/open.tcl | ||
| $(2)=$(RESULTS_DIR)/$(1) $$(OPENROAD_GUI_CMD) $(SCRIPTS_DIR)/open.tcl | ||
| web_$(1): | ||
| $(2)=$(RESULTS_DIR)/$(1) $(OPENROAD_WEB_CMD) $(SCRIPTS_DIR)/open.tcl | ||
| $(2)=$(RESULTS_DIR)/$(1) $$(OPENROAD_WEB_CMD) $(SCRIPTS_DIR)/open.tcl |
There was a problem hiding this comment.
In GNU Make, when using $(eval $(call ...)), there is a double expansion process:
$(call ...)expands the macro, which turns$$into$.$(eval ...)expands its argument again before parsing it as makefile syntax.
Because of this double expansion, using $$ (e.g., $$(OPENROAD_NO_EXIT_CMD)) results in $(OPENROAD_NO_EXIT_CMD) being passed to eval, which then immediately expands it at eval time (when the foreach loops are evaluated at lines 876-878). Since util/utils.mk is included at line 927 (after the foreach loops), any modifications to these commands in util/utils.mk still won't take effect.
To truly defer the expansion until the recipe is executed (when the rules are triggered), you need to escape the $ twice by using $$$$ (four dollar signs). This way, call expands $$$$ to $$, eval expands $$ to $, and the final parsed recipe contains $(OPENROAD_NO_EXIT_CMD), which is expanded at execution time.
open_$(1):
$(2)=$(RESULTS_DIR)/$(1) $$$$(OPENROAD_NO_EXIT_CMD) $(SCRIPTS_DIR)/open.tcl
gui_$(1):
$(2)=$(RESULTS_DIR)/$(1) $$$$(OPENROAD_GUI_CMD) $(SCRIPTS_DIR)/open.tcl
web_$(1):
$(2)=$(RESULTS_DIR)/$(1) $$$$(OPENROAD_WEB_CMD) $(SCRIPTS_DIR)/open.tcl
There was a problem hiding this comment.
That doesn't work, as it delays expansion to the shell, so something like echo $(VAR) which tries to launch a subshell for $(VAR) and fails to find a command literally named VAR.
The commit message could maybe be more explicit that the expansion is delayed to the last possible moment still within Make, I guess?
🔍 QoR checkMetrics reflect the PR merge build — i.e. what will land on the target branch. Commit 62 design(s) checked — 0 with regression(s), 2 without a comparable baseline. |
Signed-off-by: Matt Liberty <mliberty@precisioninno.com>
|
Claude's suggestion seems like a better solution:
|
|
In fact, why does |
|
Thanks for asking before moving it! bazel-orfs doesn't use the GDB/VALGRIND switches: it passes I tried the move on nangate45/gcd with a fake Why origin mattered in 72eca88: Two things I noticed along the way, already on master: under |
|
Thanks for the clarifications. I still don't quite understand why the variables have to be unset, seems a bit counter-intuitive to first
Would it make more sense to just remove
|
|
I wonder if we can simply delete the special casing and use FOO_EXE overriding? |
Sorry, what is this referring to? "FOO_EXE overriding" as I read it could be removing GDB/VALGRIND and letting the user override the default |
The first reading. Delete make OPENROAD_EXE="gdb --args openroad" ...
make OPENROAD_EXE="valgrind openroad" ...
make OPENROAD_EXE="perf record -g -- openroad" ...That is the Your analysis found what stood in the way. With The switches themselves date from 2021, when the binary had no variable of its own. I've put this together in #4864 as a draft. It checks the first word of the command with |
With a single
$, the variables are immediately expanded in$(eval), which means modifications done in util/utils.mk, such as prefixing with gdb or valgrind, don't take effect. Use$$instead, which causes the expansion to happen when theopen_*/gui_*/web_*rules are actually triggered instead of when they're generated.