File tree Expand file tree Collapse file tree 2 files changed +56
-1
lines changed
Expand file tree Collapse file tree 2 files changed +56
-1
lines changed Original file line number Diff line number Diff line change @@ -207,7 +207,9 @@ $(DONT_USE_LIBS): $$(filter %$$(@F) %$$(@F).gz,$(LIB_FILES))
207207 $(PYTHON_EXE ) $(UTILS_DIR ) /preprocessLib.py -i $^ -o $@
208208
209209$(OBJECTS_DIR ) /lib/merged.lib : $(DONT_USE_LIBS )
210- $(UTILS_DIR ) /mergeLib.pl $(PLATFORM ) _merged $(DONT_USE_LIBS ) > $@
210+ $(UTILS_DIR ) /mergeLib.pl $(PLATFORM ) _merged $(DONT_USE_LIBS ) > $@ .old
211+ $(PYTHON_EXE ) $(UTILS_DIR ) /merge_lib.py $(PLATFORM ) _merged $(DONT_USE_LIBS ) > $@
212+ diff -u $@ .old $@ || (echo " Merged library differs from original!" ; exit 1)
211213
212214# Pre-process KLayout tech
213215# ==============================================================================
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+
3+ import re
4+ import sys
5+
6+
7+ def process_header (filename , sclname ):
8+ with open (filename , "r" ) as fh :
9+ for line in fh :
10+ if re .search (r'library\s*\(' , line ):
11+ print (f"library ({ sclname } ) {{" )
12+ continue
13+ if re .match (r'^[\t ]*cell\s*\(' , line ):
14+ break
15+ print (line , end = "" )
16+
17+
18+ def process_cells (filename ):
19+ with open (filename , "r" ) as fh :
20+ flag = 0 # brace depth
21+ for line in fh :
22+ # Match 'cell ( ... )' with optional whitespace
23+ if re .match (r'^[\t ]*cell\s*\(' , line ):
24+ if flag != 0 :
25+ raise RuntimeError ("Error! new cell before finishing the previous one!" )
26+ print () # print blank line like Perl
27+ print (line , end = "" )
28+ flag = 1 # entering a cell block
29+ elif flag > 0 :
30+ # Increase/decrease brace depth
31+ flag += line .count ('{' )
32+ flag -= line .count ('}' )
33+ print (line , end = "" )
34+
35+ # Optionally: reset flag to 0 here if it's finished
36+ # But not necessary unless you're adding post-processing
37+
38+ def main ():
39+ if len (sys .argv ) < 3 :
40+ print ("use: mergeLib.py new_library_name lib1 lib2 lib3 ...." )
41+ sys .exit (1 )
42+
43+ sclname = sys .argv [1 ]
44+ files = sys .argv [2 :]
45+
46+ process_header (files [0 ], sclname )
47+ for file in files :
48+ process_cells (file )
49+ print ("\n }" )
50+
51+
52+ if __name__ == "__main__" :
53+ main ()
You can’t perform that action at this time.
0 commit comments