Skip to content

Commit d605df7

Browse files
committed
fix(generate_klayout_tech): drop realpath() — breaks Bazel sandbox
os.path.realpath() follows symlinks. Inside a Bazel sandbox, the bazel-out/ tree is symlinked from the sandbox back to the bare execroot; realpath resolves through that symlink and yields the bare-execroot path, not the sandbox path. That alone doesn't matter for os.path.relpath(a, b) when both operands are realpath'd from the same sandbox — the relative result is unchanged. But the resulting <lef-files> path in the generated klayout.lyt is later resolved by klayout against the LYT file's location. Klayout opens the LYT (also through a symlink), resolves through to the bare execroot, and then looks for the sibling klayout_tech.lef at the bare-execroot path — where the in-flight file does not exist during action execution (only the sandbox copy does), so def2stream fails with errno=2. Fix: don't realpath. os.path.relpath produces the correct relative path from sandbox-relative inputs directly. Map files keep their absolute form via abspath for the unchanged-under-non-sandbox case. Surfaced for the first time on bazelisk build //flow/designs/sky130hd/gcd:gcd_final_blender_html — the orfs_blender macro is the first bazel-side consumer of orfs_gds (klayout def2stream), so the latent path bug had no prior trigger. Mirrors bazel-orfs's patches/0037-fix-generate_klayout_tech-drop-realpath.patch into ORFS directly so bazel-orfs no longer needs to carry it. Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent 2f6e9c9 commit d605df7

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

flow/util/generate_klayout_tech.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,15 @@ def generate_klayout_tech(
5151
with open(template_lyt, "r") as f:
5252
content = f.read()
5353

54-
# Both modes use relative paths from reference_dir, matching the
55-
# original sed-based behavior which always uses realpath --relative-to.
56-
resolved_lefs = [
57-
os.path.relpath(os.path.realpath(f), os.path.realpath(reference_dir))
58-
for f in lef_files
59-
]
54+
# Compute relpath without realpath(): under a Bazel sandbox, bazel-out/
55+
# entries are symlinks to the bare execroot; realpath follows them and
56+
# makes the generated LYT reference files at the bare-execroot path,
57+
# where in-flight outputs do not exist during action execution.
58+
resolved_lefs = [os.path.relpath(f, reference_dir) for f in lef_files]
6059

6160
content = replace_lef_files(content, resolved_lefs)
6261

63-
resolved_maps = [os.path.realpath(f) for f in map_files]
62+
resolved_maps = [os.path.abspath(f) for f in map_files]
6463
content = replace_map_files(content, resolved_maps)
6564

6665
with open(output_lyt, "w") as f:

0 commit comments

Comments
 (0)