@@ -30,37 +30,32 @@ def replace_map_files(content, map_files):
3030 return content
3131
3232
33- def generate_klayout_tech (
34- template_lyt ,
35- output_lyt ,
36- lef_files ,
37- reference_dir ,
38- map_files ,
39- use_relative_paths ,
40- ):
33+ def generate_klayout_tech (template_lyt , output_lyt , lef_files , map_files = None ):
4134 """Generate a klayout .lyt file from a platform template.
4235
4336 Args:
4437 template_lyt: Path to the platform .lyt template file.
4538 output_lyt: Path to write the generated .lyt file.
4639 lef_files: List of LEF file paths to include.
47- reference_dir: Directory to compute relative paths from.
4840 map_files: List of map file paths.
49- use_relative_paths: If True, compute paths relative to reference_dir.
5041 """
5142 with open (template_lyt , "r" ) as f :
5243 content = f .read ()
5344
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- ]
45+ # Write absolute (not relative, not realpath'd) LEF paths into the LYT.
46+ # Klayout's Layout.read(def, layout_options) follows the symlinked input
47+ # DEF to its realpath at the bare execroot and resolves relative
48+ # <lef-files> entries from there. Sibling intermediates like
49+ # objects/klayout_tech.lef don't exist at the bare execroot during
50+ # action execution -- they're only at the per-action sandbox -- so
51+ # resolution fails with errno=2. Plain abspath (NOT realpath, which
52+ # would chase Bazel input-file symlinks back out to the bare execroot)
53+ # keeps klayout pointed at the in-sandbox file.
54+ resolved_lefs = [os .path .abspath (f ) for f in lef_files ]
6055
6156 content = replace_lef_files (content , resolved_lefs )
6257
63- resolved_maps = [os .path .realpath (f ) for f in map_files ]
58+ resolved_maps = [os .path .abspath (f ) for f in ( map_files or []) ]
6459 content = replace_map_files (content , resolved_maps )
6560
6661 with open (output_lyt , "w" ) as f :
@@ -78,28 +73,16 @@ def main():
7873 parser .add_argument (
7974 "--lef-files" , nargs = "*" , default = [], help = "LEF files to include"
8075 )
81- parser .add_argument (
82- "--reference-dir" ,
83- required = True ,
84- help = "Directory for computing relative paths" ,
85- )
8676 parser .add_argument (
8777 "--map-files" , nargs = "*" , default = [], help = "Map files to include"
8878 )
89- parser .add_argument (
90- "--use-relative-paths" ,
91- action = "store_true" ,
92- help = "Use paths relative to reference-dir" ,
93- )
9479 args = parser .parse_args ()
9580
9681 generate_klayout_tech (
9782 template_lyt = args .template ,
9883 output_lyt = args .output ,
9984 lef_files = args .lef_files ,
100- reference_dir = args .reference_dir ,
10185 map_files = args .map_files ,
102- use_relative_paths = args .use_relative_paths ,
10386 )
10487
10588
0 commit comments