Skip to content

Commit 270d7f0

Browse files
authored
Merge pull request #4871 from oharboe/delete-make-klayout
make: delete the klayout target
2 parents bd29d96 + a605805 commit 270d7f0

4 files changed

Lines changed: 170 additions & 88 deletions

File tree

‎flow/Makefile‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ ifneq ($(KLAYOUT_DRC_FILE),)
776776
--deck=$(KLAYOUT_DRC_FILE) \
777777
--in-gds=$< \
778778
--report-file=$(abspath $@), \
779-
$(SCRIPTS_DIR)/klayout.sh -zz -rd in_gds="$<" \
779+
$(or $(KLAYOUT_CMD),$(error KLayout not found. Install KLayout or set KLAYOUT_CMD)) -zz -rd in_gds="$<" \
780780
-rd report_file=$(abspath $@) \
781781
-r $(KLAYOUT_DRC_FILE))
782782
# Hacky way of getting DRV count (don't error on no matches)
@@ -805,7 +805,7 @@ ifneq ($(KLAYOUT_LVS_FILE),)
805805
--cdl-file=$(abspath $(OBJECTS_DIR)/6_final_concat.cdl) \
806806
--top-cell=$(DESIGN_NAME) \
807807
--report-file=$(abspath $@), \
808-
$(SCRIPTS_DIR)/klayout.sh -b -rd in_gds="$<" \
808+
$(or $(KLAYOUT_CMD),$(error KLayout not found. Install KLayout or set KLAYOUT_CMD)) -b -rd in_gds="$<" \
809809
-rd cdl_file=$(abspath $(OBJECTS_DIR)/6_final_concat.cdl) \
810810
-rd top_cell="$(DESIGN_NAME)" \
811811
-rd report_file=$(abspath $@) \
@@ -869,7 +869,7 @@ nuke: clean_issues
869869
#-------------------------------------------------------------------------------
870870
.PHONY: $(foreach file,$(RESULTS_DEF) $(RESULTS_GDS) $(RESULTS_OAS),klayout_$(file))
871871
$(foreach file,$(RESULTS_DEF) $(RESULTS_GDS) $(RESULTS_OAS),klayout_$(file)): klayout_%: check-klayout $(OBJECTS_DIR)/klayout.lyt
872-
$(SCRIPTS_DIR)/klayout.sh -nn $(OBJECTS_DIR)/klayout.lyt $(RESULTS_DIR)/$*
872+
$(KLAYOUT_CMD) -nn $(OBJECTS_DIR)/klayout.lyt $(RESULTS_DIR)/$*
873873

874874
$(eval $(call OPEN_GUI_SHORTCUT,synth,1_synth.odb))
875875
$(eval $(call OPEN_GUI_SHORTCUT,floorplan,2_floorplan.odb))
@@ -914,10 +914,6 @@ handoff : all_defs all_verilog
914914
.PHONY: test-unset-and-make-%
915915
test-unset-and-make-%: ; $(UNSET_AND_MAKE) $*
916916

917-
.phony: klayout
918-
klayout:
919-
$(SCRIPTS_DIR)/klayout.sh
920-
921917
.PHONY: run
922918
run:
923919
@mkdir -p $(RESULTS_DIR) $(LOG_DIR) $(REPORTS_DIR) $(OBJECTS_DIR)

‎flow/scripts/klayout.sh‎

Lines changed: 0 additions & 9 deletions
This file was deleted.

‎flow/test/test_klayout_make.py‎

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
#!/usr/bin/env python3
2+
"""The make rules that run a KLayout application: a Ruby DRC or LVS deck
3+
and the klayout_<file> viewers. With KLayout, each rule hands it the
4+
rule's arguments as they are; without it, each stops with an error and
5+
runs nothing.
6+
7+
KLayout is stubbed: `klayout` logs its argv and writes the report file it
8+
is given, so make needs nothing installed. The inputs the rules depend on
9+
are written empty and kept as they are with make's -o.
10+
"""
11+
12+
import os
13+
import subprocess
14+
import tempfile
15+
import unittest
16+
17+
FLOW_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
18+
DESIGN_CONFIG = "designs/nangate45/gcd/config.mk"
19+
20+
FAKE_KLAYOUT = """\
21+
#!/usr/bin/env bash
22+
printf "%s|" "$@" >> "$ARGV_LOG"
23+
echo >> "$ARGV_LOG"
24+
for arg in "$@"; do
25+
case "$arg" in
26+
report_file=*) echo "<value>1</value>" > "${arg#report_file=}" ;;
27+
esac
28+
done
29+
"""
30+
31+
32+
class TestKlayoutMake(unittest.TestCase):
33+
def setUp(self):
34+
self.tmp_dir = tempfile.TemporaryDirectory()
35+
tmp = self.tmp_dir.name
36+
self.log = os.path.join(tmp, "argv.log")
37+
self.klayout = os.path.join(tmp, "klayout")
38+
with open(self.klayout, "w") as f:
39+
f.write(FAKE_KLAYOUT)
40+
os.chmod(self.klayout, 0o755)
41+
self.deck = {}
42+
for name in ("drc.lydrc", "lvs.lylvs"):
43+
self.deck[name] = os.path.join(tmp, name)
44+
open(self.deck[name], "w").close()
45+
self.args = [
46+
f"DESIGN_CONFIG={DESIGN_CONFIG}",
47+
f"WORK_HOME={os.path.join(tmp, 'work')}",
48+
"FLOW_VARIANT=klayout_make",
49+
]
50+
self.env = dict(os.environ, ARGV_LOG=self.log)
51+
for name in ("KLAYOUT_CMD", "MAKEFLAGS"):
52+
self.env.pop(name, None)
53+
self.dirs = {
54+
name: self.print_var(name)
55+
for name in ("RESULTS_DIR", "OBJECTS_DIR", "REPORTS_DIR", "LOG_DIR")
56+
}
57+
for path in self.dirs.values():
58+
os.makedirs(path, exist_ok=True)
59+
self.gds = self.input("RESULTS_DIR", "6_final.gds")
60+
self.lyt = self.input("OBJECTS_DIR", "klayout.lyt")
61+
self.cdl = self.input("OBJECTS_DIR", "6_final_concat.cdl")
62+
63+
def tearDown(self):
64+
self.tmp_dir.cleanup()
65+
66+
def input(self, directory, name):
67+
path = os.path.join(self.dirs[directory], name)
68+
open(path, "w").close()
69+
return path
70+
71+
def print_var(self, name):
72+
result = subprocess.run(
73+
["make", "--no-print-directory", *self.args, f"print-{name}"],
74+
cwd=FLOW_DIR,
75+
env=self.env,
76+
capture_output=True,
77+
text=True,
78+
check=True,
79+
)
80+
return result.stdout.split(f"{name}: ")[1].strip()
81+
82+
def make(self, target, klayout_cmd, *args):
83+
if os.path.exists(self.log):
84+
os.remove(self.log)
85+
result = subprocess.run(
86+
[
87+
"make",
88+
"--no-print-directory",
89+
*self.args,
90+
f"KLAYOUT_CMD={klayout_cmd}",
91+
*(f"-o{path}" for path in (self.gds, self.lyt, self.cdl)),
92+
*args,
93+
target,
94+
],
95+
cwd=FLOW_DIR,
96+
env=self.env,
97+
stdin=subprocess.DEVNULL,
98+
capture_output=True,
99+
text=True,
100+
)
101+
calls = []
102+
if os.path.exists(self.log):
103+
with open(self.log) as f:
104+
calls = [line.split("|")[:-1] for line in f.read().splitlines()]
105+
return result, calls
106+
107+
def routes(self):
108+
"""Each route: the make target, its variables and the arguments
109+
KLayout gets."""
110+
drc_report = os.path.join(self.dirs["REPORTS_DIR"], "6_drc.lyrdb")
111+
lvs_report = os.path.join(self.dirs["RESULTS_DIR"], "6_lvs.lvsdb")
112+
return {
113+
"viewer": (
114+
"klayout_6_final.gds",
115+
[],
116+
["-nn", self.lyt, self.gds],
117+
),
118+
"ruby drc": (
119+
drc_report,
120+
[f"KLAYOUT_DRC_FILE={self.deck['drc.lydrc']}"],
121+
[
122+
"-zz",
123+
"-rd",
124+
f"in_gds={self.gds}",
125+
"-rd",
126+
f"report_file={drc_report}",
127+
"-r",
128+
self.deck["drc.lydrc"],
129+
],
130+
),
131+
"ruby lvs": (
132+
lvs_report,
133+
[f"KLAYOUT_LVS_FILE={self.deck['lvs.lylvs']}"],
134+
[
135+
"-b",
136+
"-rd",
137+
f"in_gds={self.gds}",
138+
"-rd",
139+
f"cdl_file={self.cdl}",
140+
"-rd",
141+
"top_cell=gcd",
142+
"-rd",
143+
f"report_file={lvs_report}",
144+
"-r",
145+
self.deck["lvs.lylvs"],
146+
],
147+
),
148+
}
149+
150+
def test_klayout_gets_the_arguments(self):
151+
for route, (target, args, expected) in self.routes().items():
152+
with self.subTest(route):
153+
result, calls = self.make(target, self.klayout, *args)
154+
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
155+
self.assertEqual(calls, [expected])
156+
157+
def test_missing_klayout_stops_the_rule(self):
158+
for route, (target, args, _) in self.routes().items():
159+
with self.subTest(route):
160+
result, calls = self.make(target, "", *args)
161+
self.assertNotEqual(result.returncode, 0)
162+
self.assertIn("KLayout not found", result.stdout + result.stderr)
163+
self.assertEqual(calls, [])
164+
165+
166+
if __name__ == "__main__":
167+
unittest.main()

‎flow/test/test_klayout_sh.py‎

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)