Skip to content

Commit ce1c3a9

Browse files
oharboeclaude
andcommitted
flow: keep $(PLATFORM_DIR) and $(PLATFORM) unexpanded in config.py output
config.py now outputs $(PLATFORM_DIR)/... and $(PLATFORM) in values instead of baking in absolute paths. Consumers expand on their end: - Make: $(eval) expands naturally - bazel-orfs: Python substitution when the rule executes Glob results are expanded at runtime for filesystem access, then unexpanded in output. to_dict() still returns expanded paths for unit test assertions. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent 081361e commit ce1c3a9

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

‎flow/scripts/platform_config_utils.py‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ def __init__(self, platform_dir=None):
3131
os.path.abspath(sys._getframe(1).f_globals["__file__"])
3232
),
3333
)
34+
self.platform = os.environ.get(
35+
"PLATFORM", os.path.basename(self.platform_dir)
36+
)
3437
self._vars = [] # ordered list of (key, value, conditional)
3538
self._index = {} # key -> index in _vars for fast lookup
3639

@@ -85,6 +88,29 @@ def wildcard_glob(self, pattern):
8588
"""glob.glob(pattern) -- replaces $(wildcard ...)"""
8689
return " ".join(glob.glob(pattern))
8790

91+
def _unexpand(self, value):
92+
"""Replace expanded paths with Make variable references.
93+
94+
Consumers expand these on their end:
95+
- Make: $(eval) expands $(PLATFORM_DIR) and $(PLATFORM)
96+
- bazel-orfs: Python substitution when the rule executes
97+
"""
98+
# Replace platform_dir first (longer, more specific)
99+
value = value.replace(self.platform_dir, "$(PLATFORM_DIR)")
100+
# Replace platform name within $(PLATFORM_DIR)/... paths only
101+
# e.g. $(PLATFORM_DIR)/sky130hd.lyt -> $(PLATFORM_DIR)/$(PLATFORM).lyt
102+
if self.platform:
103+
value = value.replace(
104+
"$(PLATFORM_DIR)/" + self.platform,
105+
"$(PLATFORM_DIR)/$(PLATFORM)",
106+
)
107+
# Also in subdirectories: $(PLATFORM_DIR)/drc/sky130hd.lydrc
108+
value = value.replace(
109+
"/" + self.platform + ".",
110+
"/$(PLATFORM).",
111+
)
112+
return value
113+
88114
def output_make(self):
89115
"""Print Make-compatible output lines.
90116
@@ -93,14 +119,15 @@ def output_make(self):
93119
"""
94120
for key, value, conditional in self._vars:
95121
op = "?=" if conditional else "="
122+
value = self._unexpand(value)
96123
encoded = value.replace(" ", "__SPACE__")
97124
print(f"export {key}{op}{encoded}")
98125

99126
def output_json(self):
100127
"""Print flat JSON dict for bazel-orfs or other consumers."""
101128
result = {}
102129
for key, value, _conditional in self._vars:
103-
result[key] = value
130+
result[key] = self._unexpand(value)
104131
json.dump(result, sys.stdout, indent=2)
105132
print() # trailing newline
106133

0 commit comments

Comments
 (0)