Skip to content

Commit f183165

Browse files
committed
fix(generate_klayout_tech): write absolute LEF paths — klayout sandbox
The previous switch to relpath (commit 01652ca) cleaned up the content but did not actually fix def2stream's errno=2 under a Bazel sandbox. Investigation via strace shows klayout's Layout.read(def, layout_options) opens the input DEF (a sandbox symlink to the bare execroot, staged from orfs_final), realpath's it to the bare-execroot results dir, and then resolves <lef-files> relative paths against THAT dir. Sibling intermediates like objects/klayout_tech.lef only exist in the per-action sandbox, not at the bare execroot, so the lookup lands at .../execroot/_main/bazel-out/.../klayout_tech.lef and fails with errno=2. Declaring klayout_tech.lef as a Bazel output of orfs_gds doesn't help -- Bazel only materialises declared outputs at the bare execroot at action completion, not while the action is still running and klayout is reading them. Plain abspath (NOT realpath -- realpath would chase Bazel input-file symlinks back out to the bare execroot for any input already at the bare execroot) writes the in-sandbox absolute LEF path into the LYT. KLayout opens that absolute path directly with no relative-path resolution involved, so the sibling lookup never escapes the sandbox. Cost: the LYT's content now embeds the per-invocation sandbox number, so the orfs_gds action cannot be cross-action cached. That's an acceptable trade-off for correctness while we wait for a klayout-level fix or a Bazel feature that lets us write a stable bare-execroot path from inside the action. Confirmed end-to-end: bazelisk build //flow/designs/sky130hd/gcd:gcd_final_blender_html produces 6_final.gds and the blender_html sh_binary, with both the sandbox sandbox-id N going forward and after fresh action re-runs (verified by deleting outputs and rebuilding). Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent d605df7 commit f183165

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

flow/util/generate_klayout_tech.py

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

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]
54+
# Write absolute (not relative, not realpath'd) LEF paths into the LYT.
55+
# Klayout's Layout.read(def, layout_options) follows the symlinked input
56+
# DEF to its realpath at the bare execroot and resolves relative
57+
# <lef-files> entries from there. Sibling intermediates like
58+
# objects/klayout_tech.lef don't exist at the bare execroot during
59+
# action execution -- they're only at the per-action sandbox -- so
60+
# resolution fails with errno=2. Plain abspath (NOT realpath, which
61+
# would chase Bazel input-file symlinks back out to the bare execroot)
62+
# keeps klayout pointed at the in-sandbox file. reference_dir is now
63+
# unused for LEFs.
64+
resolved_lefs = [os.path.abspath(f) for f in lef_files]
5965

6066
content = replace_lef_files(content, resolved_lefs)
6167

0 commit comments

Comments
 (0)