File tree Expand file tree Collapse file tree 2 files changed +59
-1
lines changed Expand file tree Collapse file tree 2 files changed +59
-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 (
26+ "Error! new cell before finishing the previous one!"
27+ )
28+ print () # print blank line like Perl
29+ print (line , end = "" )
30+ flag = 1 # entering a cell block
31+ elif flag > 0 :
32+ # Increase/decrease brace depth
33+ flag += line .count ("{" )
34+ flag -= line .count ("}" )
35+ print (line , end = "" )
36+
37+ # Optionally: reset flag to 0 here if it's finished
38+ # But not necessary unless you're adding post-processing
39+
40+
41+ def main ():
42+ if len (sys .argv ) < 3 :
43+ print ("use: mergeLib.py new_library_name lib1 lib2 lib3 ...." )
44+ sys .exit (1 )
45+
46+ sclname = sys .argv [1 ]
47+ files = sys .argv [2 :]
48+
49+ process_header (files [0 ], sclname )
50+ for file in files :
51+ process_cells (file )
52+ print ("\n }" )
53+
54+
55+ if __name__ == "__main__" :
56+ main ()
You can’t perform that action at this time.
0 commit comments