@@ -37,7 +37,9 @@ def __init__(self):
37
37
self .chromium_src_dir = p .normpath (d (d (d (p .abspath (__file__ )))))
38
38
self .default_config = p .join (self .chromium_src_dir , 'tools' , 'mb' ,
39
39
'mb_config.pyl' )
40
+ self .executable = sys .executable
40
41
self .platform = sys .platform
42
+ self .sep = os .sep
41
43
self .args = argparse .Namespace ()
42
44
self .configs = {}
43
45
self .masters = {}
@@ -146,7 +148,7 @@ def CmdLookup(self):
146
148
elif vals ['type' ] == 'gyp' :
147
149
if vals ['gyp_crosscompile' ]:
148
150
self .Print ('GYP_CROSSCOMPILE=1' )
149
- cmd = self .GYPCmd ('<path>' , vals ['gyp_defines' ], vals [ 'gyp_config' ] )
151
+ cmd = self .GYPCmd ('<path>' , vals ['gyp_defines' ])
150
152
else :
151
153
raise MBErr ('Unknown meta-build type "%s"' % vals ['type' ])
152
154
@@ -285,7 +287,6 @@ def FlattenConfig(self, config):
285
287
vals = {
286
288
'type' : None ,
287
289
'gn_args' : [],
288
- 'gyp_config' : [],
289
290
'gyp_defines' : '' ,
290
291
'gyp_crosscompile' : False ,
291
292
}
@@ -311,8 +312,6 @@ def FlattenMixins(self, mixins, vals, visited):
311
312
vals ['gn_args' ] += ' ' + mixin_vals ['gn_args' ]
312
313
else :
313
314
vals ['gn_args' ] = mixin_vals ['gn_args' ]
314
- if 'gyp_config' in mixin_vals :
315
- vals ['gyp_config' ] = mixin_vals ['gyp_config' ]
316
315
if 'gyp_crosscompile' in mixin_vals :
317
316
vals ['gyp_crosscompile' ] = mixin_vals ['gyp_crosscompile' ]
318
317
if 'gyp_defines' in mixin_vals :
@@ -327,7 +326,7 @@ def FlattenMixins(self, mixins, vals, visited):
327
326
def ClobberIfNeeded (self , vals ):
328
327
path = self .args .path [0 ]
329
328
build_dir = self .ToAbsPath (path )
330
- mb_type_path = os . path . join (build_dir , 'mb_type' )
329
+ mb_type_path = self . PathJoin (build_dir , 'mb_type' )
331
330
needs_clobber = False
332
331
new_mb_type = vals ['type' ]
333
332
if self .Exists (build_dir ):
@@ -364,7 +363,7 @@ def RunGNGen(self, vals):
364
363
# the compile targets to the matching GN labels.
365
364
contents = self .ReadFile (self .args .swarming_targets_file )
366
365
swarming_targets = contents .splitlines ()
367
- gn_isolate_map = ast .literal_eval (self .ReadFile (os . path . join (
366
+ gn_isolate_map = ast .literal_eval (self .ReadFile (self . PathJoin (
368
367
self .chromium_src_dir , 'testing' , 'buildbot' , 'gn_isolate_map.pyl' )))
369
368
gn_labels = []
370
369
for target in swarming_targets :
@@ -399,7 +398,7 @@ def RunGNGen(self, vals):
399
398
runtime_deps_target = 'obj/%s.stamp' % label .replace (':' , '/' )
400
399
else :
401
400
runtime_deps_target = target
402
- if sys .platform == 'win32' :
401
+ if self .platform == 'win32' :
403
402
deps_path = self .ToAbsPath (path ,
404
403
runtime_deps_target + '.exe.runtime_deps' )
405
404
else :
@@ -426,9 +425,9 @@ def RunGNGen(self, vals):
426
425
{
427
426
'args' : [
428
427
'--isolated' ,
429
- self .ToSrcRelPath ('%s%s%s.isolated' % (path , os .sep , target )),
428
+ self .ToSrcRelPath ('%s%s%s.isolated' % (path , self .sep , target )),
430
429
'--isolate' ,
431
- self .ToSrcRelPath ('%s%s%s.isolate' % (path , os .sep , target )),
430
+ self .ToSrcRelPath ('%s%s%s.isolate' % (path , self .sep , target )),
432
431
],
433
432
'dir' : self .chromium_src_dir ,
434
433
'version' : 1 ,
@@ -440,14 +439,12 @@ def RunGNGen(self, vals):
440
439
441
440
def GNCmd (self , subcommand , path , gn_args = '' ):
442
441
if self .platform == 'linux2' :
443
- gn_path = os .path .join (self .chromium_src_dir , 'buildtools' , 'linux64' ,
444
- 'gn' )
442
+ subdir = 'linux64'
445
443
elif self .platform == 'darwin' :
446
- gn_path = os .path .join (self .chromium_src_dir , 'buildtools' , 'mac' ,
447
- 'gn' )
444
+ subdir = 'mac'
448
445
else :
449
- gn_path = os . path . join ( self . chromium_src_dir , 'buildtools' , ' win',
450
- 'gn.exe ' )
446
+ subdir = ' win'
447
+ gn_path = self . PathJoin ( self . chromium_src_dir , 'buildtools' , subdir , 'gn' )
451
448
452
449
cmd = [gn_path , subcommand , path ]
453
450
gn_args = gn_args .replace ("$(goma_dir)" , self .args .goma_dir )
@@ -458,12 +455,8 @@ def GNCmd(self, subcommand, path, gn_args=''):
458
455
def RunGYPGen (self , vals ):
459
456
path = self .args .path [0 ]
460
457
461
- output_dir , gyp_config = self .ParseGYPConfigPath (path )
462
- if gyp_config != vals ['gyp_config' ]:
463
- raise MBErr ('The last component of the path (%s) must match the '
464
- 'GYP configuration specified in the config (%s), and '
465
- 'it does not.' % (gyp_config , vals ['gyp_config' ]))
466
- cmd = self .GYPCmd (output_dir , vals ['gyp_defines' ], config = gyp_config )
458
+ output_dir = self .ParseGYPConfigPath (path )
459
+ cmd = self .GYPCmd (output_dir , vals ['gyp_defines' ])
467
460
env = None
468
461
if vals ['gyp_crosscompile' ]:
469
462
if self .args .verbose :
@@ -474,19 +467,15 @@ def RunGYPGen(self, vals):
474
467
return ret
475
468
476
469
def RunGYPAnalyze (self , vals ):
477
- output_dir , gyp_config = self .ParseGYPConfigPath (self .args .path [0 ])
478
- if gyp_config != vals ['gyp_config' ]:
479
- raise MBErr ('The last component of the path (%s) must match the '
480
- 'GYP configuration specified in the config (%s), and '
481
- 'it does not.' % (gyp_config , vals ['gyp_config' ]))
470
+ output_dir = self .ParseGYPConfigPath (self .args .path [0 ])
482
471
if self .args .verbose :
483
472
inp = self .ReadInputJSON (['files' , 'targets' ])
484
473
self .Print ()
485
474
self .Print ('analyze input:' )
486
475
self .PrintJSON (inp )
487
476
self .Print ()
488
477
489
- cmd = self .GYPCmd (output_dir , vals ['gyp_defines' ], config = gyp_config )
478
+ cmd = self .GYPCmd (output_dir , vals ['gyp_defines' ])
490
479
cmd .extend (['-f' , 'analyzer' ,
491
480
'-G' , 'config_path=%s' % self .args .input_path [0 ],
492
481
'-G' , 'analyzer_output_path=%s' % self .args .output_path [0 ]])
@@ -504,15 +493,15 @@ def GetIsolateCommand(self, target, vals, gn_isolate_map):
504
493
# This needs to mirror the settings in //build/config/ui.gni:
505
494
# use_x11 = is_linux && !use_ozone.
506
495
# TODO(dpranke): Figure out how to keep this in sync better.
507
- use_x11 = (sys .platform == 'linux2' and
496
+ use_x11 = (self .platform == 'linux2' and
508
497
not 'target_os="android"' in vals ['gn_args' ] and
509
498
not 'use_ozone=true' in vals ['gn_args' ])
510
499
511
500
asan = 'is_asan=true' in vals ['gn_args' ]
512
501
msan = 'is_msan=true' in vals ['gn_args' ]
513
502
tsan = 'is_tsan=true' in vals ['gn_args' ]
514
503
515
- executable_suffix = '.exe' if sys .platform == 'win32' else ''
504
+ executable_suffix = '.exe' if self .platform == 'win32' else ''
516
505
517
506
test_type = gn_isolate_map [target ]['type' ]
518
507
cmdline = []
@@ -580,38 +569,28 @@ def GetIsolateCommand(self, target, vals, gn_isolate_map):
580
569
return cmdline , extra_files
581
570
582
571
def ToAbsPath (self , build_path , * comps ):
583
- return os . path . join (self .chromium_src_dir ,
584
- self .ToSrcRelPath (build_path ),
585
- * comps )
572
+ return self . PathJoin (self .chromium_src_dir ,
573
+ self .ToSrcRelPath (build_path ),
574
+ * comps )
586
575
587
576
def ToSrcRelPath (self , path ):
588
577
"""Returns a relative path from the top of the repo."""
589
578
# TODO: Support normal paths in addition to source-absolute paths.
590
579
assert (path .startswith ('//' ))
591
- return path [2 :].replace ('/' , os .sep )
580
+ return path [2 :].replace ('/' , self .sep )
592
581
593
582
def ParseGYPConfigPath (self , path ):
594
583
rpath = self .ToSrcRelPath (path )
595
- output_dir , _ , config = rpath .rpartition ('/' )
596
- self .CheckGYPConfigIsSupported (config , path )
597
- return output_dir , config
598
-
599
- def CheckGYPConfigIsSupported (self , config , path ):
600
- if config not in ('Debug' , 'Release' ):
601
- if (sys .platform in ('win32' , 'cygwin' ) and
602
- config not in ('Debug_x64' , 'Release_x64' )):
603
- raise MBErr ('Unknown or unsupported config type "%s" in "%s"' %
604
- config , path )
605
-
606
- def GYPCmd (self , output_dir , gyp_defines , config ):
584
+ output_dir , _ , _ = rpath .rpartition (self .sep )
585
+ return output_dir
586
+
587
+ def GYPCmd (self , output_dir , gyp_defines ):
607
588
gyp_defines = gyp_defines .replace ("$(goma_dir)" , self .args .goma_dir )
608
589
cmd = [
609
- sys .executable ,
610
- os . path . join ('build' , 'gyp_chromium' ),
590
+ self .executable ,
591
+ self . PathJoin ('build' , 'gyp_chromium' ),
611
592
'-G' ,
612
593
'output_dir=' + output_dir ,
613
- '-G' ,
614
- 'config=' + config ,
615
594
]
616
595
for d in shlex .split (gyp_defines ):
617
596
cmd += ['-D' , d ]
@@ -667,7 +646,7 @@ def RunGNAnalyze(self, vals):
667
646
if ret and not 'The input matches no targets' in out :
668
647
self .WriteFailureAndRaise ('gn refs returned %d: %s' % (ret , out ),
669
648
output_path )
670
- build_dir = self .ToSrcRelPath (self .args .path [0 ]) + os .sep
649
+ build_dir = self .ToSrcRelPath (self .args .path [0 ]) + self .sep
671
650
for output in out .splitlines ():
672
651
build_output = output .replace (build_dir , '' )
673
652
if build_output in inp ['targets' ]:
@@ -746,7 +725,7 @@ def WriteJSON(self, obj, path, force_verbose=False):
746
725
(e , path ))
747
726
748
727
def PrintCmd (self , cmd ):
749
- if cmd [0 ] == sys .executable :
728
+ if cmd [0 ] == self .executable :
750
729
cmd = ['python' ] + cmd [1 :]
751
730
self .Print (* [pipes .quote (c ) for c in cmd ])
752
731
@@ -794,6 +773,10 @@ def MaybeMakeDirectory(self, path):
794
773
if e .errno != errno .EEXIST :
795
774
raise
796
775
776
+ def PathJoin (self , * comps ):
777
+ # This function largely exists so it can be overriden for testing.
778
+ return os .path .join (* comps )
779
+
797
780
def ReadFile (self , path ):
798
781
# This function largely exists so it can be overriden for testing.
799
782
with open (path ) as fp :
@@ -804,7 +787,7 @@ def RemoveFile(self, path):
804
787
os .remove (path )
805
788
806
789
def RemoveDirectory (self , abs_path ):
807
- if sys .platform == 'win32' :
790
+ if self .platform == 'win32' :
808
791
# In other places in chromium, we often have to retry this command
809
792
# because we're worried about other processes still holding on to
810
793
# file handles, but when MB is invoked, it will be early enough in the
0 commit comments