@@ -71,40 +71,50 @@ export NUM_CORES
7171# -------------------------------------------------------------------------------
7272# setup all commands used within this flow
7373#
74- # HERE BE DRAGONS: use bare `export VAR`, never `export VAR := $(VAR)`.
74+ # Nix and Bazel (or whatever else environment) should explicitly set the
75+ # variables OPENROAD_EXE, OPENSTA_EXE, YOSYS_EXE and PYTHON_EXE to point to
76+ # installed tools. If those are not defined, tools built by ORFS are used and
77+ # referred to by absolute paths.
7578#
76- # `export VAR := $(VAR)` rebinds the variable to origin "file", which makes
77- # get_variables (below) include it in UNSET_VARIABLES_NAMES. UNSET_AND_MAKE
78- # then unsets it before the sub-make runs, so any `?=` fallback here fires
79- # with the wrong value in the sub-make (e.g. the in-tree tools/install path
80- # that does not exist in a Bazel sandbox). A bare `export` preserves the
81- # original origin (environment when bazel-orfs supplies it, file when the
82- # local default fills in), so the value survives UNSET_VARS.
83- PYTHON_EXE ?= $(shell command -v python3)
79+ # Avoid exporting deferred shell commands, for example something like
80+ #
81+ # export PYTHON_EXE ?= $(shell command -v python3)
82+ #
83+ # causes Make to start up a new shell whenever PYTHON_EXE is expanded. An
84+ # annoying side-effect of this is that whenever a shell is launched, all
85+ # exported variables are expanded, which causes PYTHON_EXE to launch a shell,
86+ # which causes other exported variables to be expanded, and if those launch
87+ # shells, PYTHON_EXE is re-expanded which launches a shell, and so on.
88+ #
89+ # This is not an infinite loop, as there are rules in place to stop expansion
90+ # under certain circumstances, but the effect is nonetheless cumulative.
91+ # Previous versions of this file caused ~28k shell instances to be spawned for
92+ # `make DESIGN_CONFIG=... clean_all`, which could be reduced to 41.
93+ #
94+ # The 'obvious' solution here is to just run each shell command once by forcing
95+ # an immediate expansion with `:=`, something like
96+ #
97+ # PYTHON_EXE ?= $(shell command -v python3)
98+ # export PYTHON_EXE := $(PYTHON_EXE)
99+ #
100+ # but this changes 'where' PYTHON_EXE was defined, command line/environment
101+ # versus in a file, which messes with `get_variables` and causes command
102+ # line/environment variables to not be propagated to submakes.
103+ #
104+ # Python is not built by ORFS, and as such its absolute path has to be fetched
105+ # from the environment. Use `ifeq ($(origin PYTHON_EXE), undefined)` to check if
106+ # the variable hasn't been defined yet and run a single shell instance to fetch
107+ # the absolute path if so. The other tools should've been built by ORFS, and can
108+ # use a pre-specified path, which we can just use ?= for.
109+ ifeq ($(origin PYTHON_EXE ) , undefined)
110+ PYTHON_EXE := $(shell command -v python3)
111+ endif
84112export PYTHON_EXE
85113
86114export RUN_CMD = $(PYTHON_EXE ) $(FLOW_HOME ) /scripts/run_command.py
87115
88- # The following determine the executable location for each tool used by this flow.
89- # Priority is given to
90- # 1 user explicit set with variable in Makefile or command line, for instance setting OPENROAD_EXE
91- # 2 either
92- # 2.1 if in Nix shell: openroad, yosys from the environment
93- # 2.2 ORFS compiled tools: openroad, yosys
94- ifneq (${IN_NIX_SHELL},)
95- OPENROAD_EXE ?= $(shell command -v openroad)
96- else
97- OPENROAD_EXE ?= $(abspath $(FLOW_HOME ) /../tools/install/OpenROAD/bin/openroad)
98- endif
99- ifneq (${IN_NIX_SHELL},)
100- OPENSTA_EXE ?= $(shell command -v sta)
101- else
102- OPENSTA_EXE ?= $(abspath $(FLOW_HOME ) /../tools/install/OpenROAD/bin/sta)
103- endif
104-
105- # See dragons comment near PYTHON_EXE: bare `export`, not `export VAR := $(VAR)`.
106- export OPENROAD_EXE
107- export OPENSTA_EXE
116+ export OPENROAD_EXE ?= $(abspath $(FLOW_HOME ) /../tools/install/OpenROAD/bin/openroad)
117+ export OPENSTA_EXE ?= $(abspath $(FLOW_HOME ) /../tools/install/OpenROAD/bin/sta)
108118
109119OPENROAD_IS_VALID := $(if $(OPENROAD_EXE ) ,$(shell test -x $(OPENROAD_EXE ) && echo "true") ,)
110120
@@ -114,14 +124,7 @@ export OPENROAD_NO_EXIT_CMD = $(OPENROAD_EXE) $(OPENROAD_ARGS)
114124export OPENROAD_GUI_CMD = $(OPENROAD_EXE ) -gui -threads $(NUM_CORES ) $(OR_ARGS )
115125export OPENROAD_WEB_CMD = $(OPENROAD_EXE ) -web -threads $(NUM_CORES ) $(OR_ARGS )
116126
117- ifneq (${IN_NIX_SHELL},)
118- YOSYS_EXE ?= $(shell command -v yosys)
119- else
120- YOSYS_EXE ?= $(abspath $(FLOW_HOME ) /../tools/install/yosys/bin/yosys)
121- endif
122-
123- # See dragons comment near PYTHON_EXE: bare `export`, not `export VAR := $(VAR)`.
124- export YOSYS_EXE
127+ export YOSYS_EXE ?= $(abspath $(FLOW_HOME ) /../tools/install/yosys/bin/yosys)
125128
126129YOSYS_IS_VALID := $(if $(YOSYS_EXE ) ,$(shell test -x $(YOSYS_EXE ) && echo "true") ,)
127130
0 commit comments