Skip to content

Commit 70090bc

Browse files
committed
defaults: canonicalize environment, remove blank env vars
Signed-off-by: Øyvind Harboe <[email protected]>
1 parent 25ef574 commit 70090bc

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

flow/scripts/defaults.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,20 @@
55
import sys
66
import yaml
77

8+
# fewer edge cases as unset env vars are passed in as blank env vars
9+
# from make
10+
env_canonical = {key: value for key, value in os.environ.items() if value != ""}
11+
812
config_py = os.path.join(os.environ["PLATFORM_DIR"], "config.py")
913
if os.path.exists(config_py):
1014
sys.path.append(os.path.dirname(config_py))
1115
import config
1216

13-
platform_defaults = config.get_defaults(os.environ)
17+
get_platform_defaults = config.get_defaults
1418
else:
15-
platform_defaults = {}
19+
20+
def get_platform_defaults(variables):
21+
return {}
1622

1723

1824
def get_num_cores():
@@ -42,7 +48,7 @@ def get_num_cores():
4248

4349

4450
def env_blank(name):
45-
return name not in os.environ or os.environ[name] == ""
51+
return name not in env_canonical or env_canonical[name] == ""
4652

4753

4854
def env_get(name):
@@ -54,7 +60,7 @@ def env_get(name):
5460
"""
5561
if env_blank(name):
5662
raise ValueError(f"Environment variable {name} is not set.")
57-
return os.environ[name]
63+
return env_canonical[name]
5864

5965

6066
def get_time_cmd(time_bin):
@@ -86,7 +92,7 @@ def main():
8692

8793
variables = {
8894
name: value["default"] for name, value in info.items() if "default" in value
89-
} | platform_defaults
95+
}
9096

9197
# 'variables' is a dictionary that contains settings. Historically,
9298
# these settings were managed in variables in the Makefile. We are
@@ -124,6 +130,11 @@ def main():
124130
variables["FLOW_VARIANT"],
125131
)
126132

133+
# the platform overrides the defaults from variables.yaml, but need
134+
# OBJECTS_DIR. make handles such dependencies differently, it has
135+
# late and immediate expansion of variables.
136+
variables |= get_platform_defaults(env_canonical | variables)
137+
127138
if env_blank("NUM_CORES"):
128139
variables["NUM_CORES"] = get_num_cores()
129140
else:

0 commit comments

Comments
 (0)