blob: a673c2f30574ffb4a599e16c6a491a27c9dec99e [file] [log] [blame]
Tim Edwards55f4d0e2020-07-05 15:41:02 -04001#!/bin/env python3
2# Script to read a GDS library and write into individual GDS files, one per cell
3
4import os
5import sys
6import subprocess
7
8def usage():
9 print('split_gds.py <path_to_gds_library> <magic_techfile> [<file_with_list_of_cells>]')
10
11if __name__ == '__main__':
12
13 if len(sys.argv) == 1:
14 print("No options given to split_gds.py.")
15 usage()
16 sys.exit(0)
17
18 optionlist = []
19 arguments = []
20
21 for option in sys.argv[1:]:
22 if option.find('-', 0) == 0:
23 optionlist.append(option)
24 else:
25 arguments.append(option)
26
27 if len(arguments) != 3:
28 print("Wrong number of arguments given to split_gds.py.")
29 usage()
30 sys.exit(0)
31
32 source = arguments[0]
33
34 techfile = arguments[1]
35
36 celllist = arguments[2]
37 if os.path.isfile(celllist):
38 with open(celllist, 'r') as ifile:
39 celllist = ifile.read().splitlines()
40
41 destdir = os.path.split(source)[0]
42 gdsfile = os.path.split(source)[1]
43
44 with open(destdir + '/split_gds.tcl', 'w') as ofile:
45 print('#!/bin/env wish', file=ofile)
46 print('drc off', file=ofile)
47 print('gds readonly true', file=ofile)
48 print('gds rescale false', file=ofile)
49 print('tech unlock *', file=ofile)
50 print('gds read ' + gdsfile, file=ofile)
51
52 for cell in celllist:
53 print('load ' + cell, file=ofile)
54 print('gds write ' + cell, file=ofile)
55
56 print('quit -noprompt', file=ofile)
57
58 mproc = subprocess.run(['magic', '-dnull', '-noconsole',
59 '-T', techfile,
60 destdir + '/split_gds.tcl'],
61 stdin = subprocess.DEVNULL,
62 stdout = subprocess.PIPE,
63 stderr = subprocess.PIPE, cwd = destdir,
64 universal_newlines = True)
65 if mproc.stdout:
66 for line in mproc.stdout.splitlines():
67 print(line)
68 if mproc.stderr:
69 print('Error message output from magic:')
70 for line in mproc.stderr.splitlines():
71 print(line)
72 if mproc.returncode != 0:
73 print('ERROR: Magic exited with status ' + str(mproc.returncode))
74
75 os.remove(destdir + '/split_gds.tcl')
76 exit(0)