Skip to content

Commit 4a9daf3

Browse files
committed
bazel: re-vendor render_gds PDK_CONFIGS fix (addon UnboundLocalError)
Bumping bazel-orfs to 3a5ddd7 picked up the upstream copy of our layerstack-trim feature, but the upstream commit landed without the PDK_CONFIGS monkey-patch fix that I added locally after upstream sent the PR -- so the merged version still goes through the addon's gdsii_use_custom_config=True path, which is broken: File ".../blendergds/__init__.py", line 613, in import_gdsii colorfile = addon_dir / pdk_info.get('color_path', ...) / ... UnboundLocalError: cannot access local variable 'pdk_info' The addon's import_gdsii skips initialising pdk_info / addon_dir in the custom-config branch but uses them a few lines later for the color_path lookup. Vendor a one-hunk patch on render_gds.py that monkey-patches addon.PDK_CONFIGS[pdk]['config_path'] instead, so the addon's else branch fires normally. Path's absolute-RHS semantic makes `addon_dir / Path(abs_path)` evaluate to the absolute path, so the trim YAML still resolves correctly. Once a fix lands upstream (in bazel-orfs or in the BlenderGDS addon's __init__.py), this can be dropped and bazel-orfs bumped again -- the patches/ directory comes back if we need a vendored fix in the meantime. Signed-off-by: Øyvind Harboe <oyvind@ascenium.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent eafadcd commit 4a9daf3

3 files changed

Lines changed: 61 additions & 0 deletions

File tree

MODULE.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ BAZEL_ORFS_REMOTE = "https://github.com/The-OpenROAD-Project/bazel-orfs.git"
5757
git_override(
5858
module_name = "bazel-orfs",
5959
commit = BAZEL_ORFS_COMMIT,
60+
patch_strip = 1,
61+
patches = [
62+
"//patches/bazel-orfs:0001-render_gds-monkey-patch-PDK_CONFIGS-not-gdsii_use_custom_config.patch",
63+
],
6064
remote = BAZEL_ORFS_REMOTE,
6165
)
6266

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
From 0010e181efa28210dbf7839e6e6131139cc705bd Mon Sep 17 00:00:00 2001
2+
From: =?UTF-8?q?=C3=98yvind=20Harboe?= <oyvind@ascenium.com>
3+
Date: Mon, 18 May 2026 00:06:14 +0200
4+
Subject: [PATCH] render_gds: monkey-patch PDK_CONFIGS instead of
5+
gdsii_use_custom_config
6+
7+
The addon's gdsii_use_custom_config=True branch in import_gdsii skips
8+
initialising pdk_info and addon_dir, both of which are still used a
9+
few lines later to resolve color_path -- so any non-default
10+
layerstack YAML trips UnboundLocalError inside the addon.
11+
12+
Patch the addon's PDK_CONFIGS dict at runtime instead, pointing the
13+
selected PDK's config_path entry at our trimmed YAML. The else
14+
branch then fires normally, pdk_info is set, color_path resolves,
15+
and Path's absolute-RHS semantic makes addon_dir / Path(abs_path)
16+
evaluate to the absolute path.
17+
---
18+
tools/blendergds/render_gds.py | 12 ++++++++++--
19+
1 file changed, 10 insertions(+), 2 deletions(-)
20+
21+
diff --git a/tools/blendergds/render_gds.py b/tools/blendergds/render_gds.py
22+
index cbe116c..b53da1e 100644
23+
--- a/tools/blendergds/render_gds.py
24+
+++ b/tools/blendergds/render_gds.py
25+
@@ -289,11 +289,19 @@ def main():
26+
# in seconds rather than 5-7 minutes + 16 GB RSS. No-op for
27+
# PDKs without a preset and for designs whose full stack is
28+
# already small enough.
29+
+ # We can't go through the addon's `gdsii_use_custom_config = True`
30+
+ # path: that branch in `import_gdsii` skips initialising
31+
+ # `pdk_info` and `addon_dir`, both of which are still used
32+
+ # afterwards to resolve `color_path` -- so a custom YAML trips
33+
+ # `UnboundLocalError: pdk_info` inside the addon. Instead,
34+
+ # monkey-patch PDK_CONFIGS[pdk]['config_path'] to point at the
35+
+ # trimmed YAML (absolute path -- `addon_dir / Path("/abs")`
36+
+ # evaluates to the absolute path in pathlib, so the else branch
37+
+ # in the addon picks it up correctly).
38+
trimmed = _trim_layerstack(addon, addon_root, args.pdk, tmp)
39+
if trimmed is not None:
40+
yaml_path, kept_layers, missing = trimmed
41+
- bpy.context.scene.gdsii_use_custom_config = True
42+
- bpy.context.scene.gdsii_config_path = str(yaml_path)
43+
+ addon.PDK_CONFIGS.setdefault(args.pdk, {})["config_path"] = str(yaml_path)
44+
_log_phase(
45+
"layerstack-trimmed",
46+
extra=(
47+
--
48+
2.51.0
49+

patches/bazel-orfs/BUILD.bazel

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"""Vendored patches applied on top of the bazel-orfs git_override pin.
2+
3+
These are small fixes we keep here to reduce churn while iterating;
4+
when they land upstream, drop the entry from MODULE.bazel and bump
5+
BAZEL_ORFS_COMMIT instead.
6+
"""
7+
8+
exports_files(glob(["*.patch"]))

0 commit comments

Comments
 (0)