@@ -44,6 +44,18 @@ def set_swift_branch(branch):
44
44
swift_branch = branch
45
45
common .set_swift_branch (branch )
46
46
47
+ class TimeReporter (object ):
48
+ def __init__ (self , file_path ):
49
+ self ._file_path = file_path
50
+ self ._time_data = {}
51
+
52
+ def update (self , project , elapsed ):
53
+ self ._time_data [project + '.compile_time' ] = elapsed
54
+
55
+ def __del__ (self ):
56
+ if self ._file_path and self ._time_data :
57
+ with open (self ._file_path , 'w+' ) as f :
58
+ json .dump (self ._time_data , f )
47
59
48
60
class ProjectTarget (object ):
49
61
"""An abstract project target."""
@@ -164,6 +176,21 @@ def get_test_command(self, incremental=False):
164
176
165
177
return command
166
178
179
+ def build (self , sandbox_profile , stdout = sys .stdout , stderr = sys .stderr ,
180
+ incremental = False , time_reporter = None ):
181
+ """Build the project target."""
182
+
183
+ start_time = None
184
+ if time_reporter :
185
+ start_time = time .time ()
186
+ returncode = common .check_execute (self .get_build_command (incremental = incremental ),
187
+ sandbox_profile = sandbox_profile ,
188
+ stdout = stdout , stderr = stdout )
189
+ if returncode == 0 and time_reporter :
190
+ elapsed = time .time () - start_time
191
+ time_reporter .update (self ._target , elapsed )
192
+
193
+ return returncode
167
194
168
195
def get_stdlib_platform_path (swiftc , destination ):
169
196
"""Return the corresponding stdlib name for a destination."""
@@ -277,7 +304,7 @@ def dispatch(root_path, repo, action, swiftc, swift_version,
277
304
added_swift_flags , added_xcodebuild_flags ,
278
305
build_config , should_strip_resource_phases = False ,
279
306
stdout = sys .stdout , stderr = sys .stderr ,
280
- incremental = False ):
307
+ incremental = False , time_reporter = None ):
281
308
"""Call functions corresponding to actions."""
282
309
283
310
substitutions = action .copy ()
@@ -377,7 +404,8 @@ def dispatch(root_path, repo, action, swiftc, swift_version,
377
404
if match .group (1 ) == 'Build' :
378
405
return xcode_target .build (sandbox_profile_xcodebuild ,
379
406
stdout = stdout , stderr = stderr ,
380
- incremental = incremental )
407
+ incremental = incremental ,
408
+ time_reporter = time_reporter )
381
409
else :
382
410
return xcode_target .test (sandbox_profile_xcodebuild ,
383
411
stdout = stdout , stderr = stderr ,
@@ -551,6 +579,9 @@ def add_arguments(parser):
551
579
metavar = 'PATH' ,
552
580
type = os .path .abspath ,
553
581
default = 'project_cache' )
582
+ parser .add_argument ("--report-time-path" ,
583
+ help = 'export time for building each xcode build target to the specified json file' ,
584
+ type = os .path .abspath )
554
585
555
586
def add_minimal_arguments (parser ):
556
587
"""Add common arguments to parser."""
@@ -918,6 +949,7 @@ def __init__(self, swiftc, swift_version, swift_branch,
918
949
skip_clean , build_config ,
919
950
strip_resource_phases ,
920
951
project_cache_path ,
952
+ time_reporter ,
921
953
action , project ):
922
954
self .swiftc = swiftc
923
955
self .swift_version = swift_version
@@ -934,6 +966,7 @@ def __init__(self, swiftc, swift_version, swift_branch,
934
966
self .skip_clean = skip_clean
935
967
self .build_config = build_config
936
968
self .strip_resource_phases = strip_resource_phases
969
+ self .time_reporter = time_reporter
937
970
self .init ()
938
971
939
972
def init (self ):
@@ -991,6 +1024,7 @@ def dispatch(self, identifier, stdout=sys.stdout, stderr=sys.stderr):
991
1024
self .added_xcodebuild_flags ,
992
1025
self .build_config ,
993
1026
incremental = self .skip_clean ,
1027
+ time_reporter = self .time_reporter ,
994
1028
stdout = stdout , stderr = stderr )
995
1029
except common .ExecuteCommandFailure as error :
996
1030
return self .failed (identifier , error )
@@ -1029,6 +1063,7 @@ def __init__(self,
1029
1063
strip_resource_phases ,
1030
1064
only_latest_versions ,
1031
1065
project_cache_path ,
1066
+ time_reporter ,
1032
1067
action , version , project ):
1033
1068
super (CompatActionBuilder , self ).__init__ (
1034
1069
swiftc , swift_version , swift_branch ,
@@ -1039,6 +1074,7 @@ def __init__(self,
1039
1074
skip_clean , build_config ,
1040
1075
strip_resource_phases ,
1041
1076
project_cache_path ,
1077
+ time_reporter ,
1042
1078
action , project
1043
1079
)
1044
1080
self .only_latest_versions = only_latest_versions
@@ -1065,6 +1101,7 @@ def dispatch(self, identifier, stdout=sys.stdout, stderr=sys.stderr):
1065
1101
self .build_config ,
1066
1102
incremental = self .skip_clean ,
1067
1103
should_strip_resource_phases = self .strip_resource_phases ,
1104
+ time_reporter = self .time_reporter ,
1068
1105
stdout = stdout , stderr = stderr )
1069
1106
except common .ExecuteCommandFailure as error :
1070
1107
return self .failed (identifier , error )
@@ -1210,6 +1247,7 @@ def __init__(self, swiftc, swift_version, swift_branch,
1210
1247
sandbox_profile_package ,
1211
1248
added_swift_flags , build_config ,
1212
1249
strip_resource_phases ,
1250
+ time_reporter ,
1213
1251
project , action ):
1214
1252
super (IncrementalActionBuilder ,
1215
1253
self ).__init__ (swiftc , swift_version , swift_branch ,
@@ -1219,6 +1257,7 @@ def __init__(self, swiftc, swift_version, swift_branch,
1219
1257
skip_clean = True ,
1220
1258
build_config = build_config ,
1221
1259
strip_resource_phases = strip_resource_phases ,
1260
+ time_reporter = time_reporter ,
1222
1261
project = project ,
1223
1262
action = action )
1224
1263
self .proj_path = os .path .join (self .root_path , self .project ['path' ])
@@ -1324,6 +1363,7 @@ def dispatch(self, identifier, incremental, stdout=sys.stdout, stderr=sys.stderr
1324
1363
self .added_xcodebuild_flags ,
1325
1364
self .build_config ,
1326
1365
should_strip_resource_phases = False ,
1366
+ time_reporter = self .time_reporter ,
1327
1367
stdout = stdout , stderr = stderr ,
1328
1368
incremental = incremental )
1329
1369
except common .ExecuteCommandFailure as error :
0 commit comments