12
12
# values.
13
13
#
14
14
15
- import gyb , os , os .path , subprocess
15
+ import gyb , os , os .path , shutil , subprocess
16
16
17
17
def find_which (p ):
18
18
for d in os .environ ["PATH" ].split (os .pathsep ):
@@ -38,20 +38,23 @@ def has_debuginfo(swiftc):
38
38
39
39
40
40
def write_input_file (args , ast , d , n ):
41
- ifile = os .path .join (d , "in%d.swift" % n )
42
- with open (ifile ,'w+' ) as f :
41
+ fname = "in%d.swift" % n
42
+ pathname = os .path .join (d , fname )
43
+ with open (pathname ,'w+' ) as f :
43
44
f .write (gyb .execute_template (ast , '' , N = n ))
44
- return ifile
45
+ return fname
45
46
46
47
47
48
def run_once_with_primary (args , ast , rng , primary_idx ):
48
- import sys , shutil , tempfile , json
49
+ import sys , tempfile , json
49
50
r = {}
50
51
try :
51
- d = tempfile .mkdtemp ()
52
+ if args .tmpdir != None and not os .path .exists (args .tmpdir ):
53
+ os .makedirs (args .tmpdir , 0700 )
54
+ d = tempfile .mkdtemp (dir = args .tmpdir )
52
55
inputs = [write_input_file (args , ast , d , i ) for i in rng ]
53
56
primary = inputs [primary_idx ]
54
- ofile = os . path . join ( d , "out.o" )
57
+ ofile = "out.o"
55
58
56
59
mode = "-c"
57
60
if args .parse :
@@ -81,26 +84,26 @@ def run_once_with_primary(args, ast, rng, primary_idx):
81
84
print "running: " + " " .join (command )
82
85
83
86
if args .dtrace :
84
- trace = os . path . join ( d , "trace.txt" )
87
+ trace = "trace.txt"
85
88
script = "pid$target:swiftc:*%s*:entry { @[probefunc] = count() }" % args .select
86
89
subprocess .check_call (
87
90
["sudo" , "dtrace" , "-q" ,
88
91
"-o" , trace ,
89
92
"-b" , "256" ,
90
93
"-n" , script ,
91
- "-c" , " " .join (command )])
94
+ "-c" , " " .join (command )], cwd = d )
92
95
r = {fields [0 ]: int (fields [1 ]) for fields in
93
- [line .split () for line in open (trace )]
96
+ [line .split () for line in open (os . path . join ( d , trace ) )]
94
97
if len (fields ) == 2 }
95
98
else :
96
99
if args .debug :
97
100
command = ["lldb" , "--" ] + command
98
- stats = os . path . join ( d , "stats.json" )
101
+ stats = "stats.json"
99
102
argv = command + ["-Xllvm" , "-stats" ,
100
103
"-Xllvm" , "-stats-json" ,
101
104
"-Xllvm" , "-info-output-file=" + stats ]
102
- subprocess .check_call (argv )
103
- with open (stats ) as f :
105
+ subprocess .check_call (argv , cwd = d )
106
+ with open (os . path . join ( d , stats ) ) as f :
104
107
r = json .load (f )
105
108
finally :
106
109
shutil .rmtree (d )
@@ -241,6 +244,9 @@ def main():
241
244
parser .add_argument (
242
245
'--swiftc-binary' ,
243
246
default = "swiftc" , help = 'swift binary to execute' )
247
+ parser .add_argument (
248
+ '--tmpdir' , type = str ,
249
+ default = None , help = 'directory to create tempfiles in' )
244
250
parser .add_argument (
245
251
'--select' ,
246
252
default = "" , help = 'substring of counters/symbols to restrict attention to' )
0 commit comments