@@ -127,13 +127,13 @@ def unpack(tarball, dst, verbose=False, match=None):
127
127
shutil .move (tp , fp )
128
128
shutil .rmtree (os .path .join (dst , fname ))
129
129
130
- def run (args , verbose = False , exception = False ):
130
+ def run (args , verbose = False , exception = False , cwd = None ):
131
131
if verbose :
132
132
print ("running: " + ' ' .join (args ))
133
133
sys .stdout .flush ()
134
134
# Use Popen here instead of call() as it apparently allows powershell on
135
135
# Windows to not lock up waiting for input presumably.
136
- ret = subprocess .Popen (args )
136
+ ret = subprocess .Popen (args , cwd = cwd )
137
137
code = ret .wait ()
138
138
if code != 0 :
139
139
err = "failed to run: " + ' ' .join (args )
@@ -391,12 +391,21 @@ def build_bootstrap(self):
391
391
args .append ("--frozen" )
392
392
self .run (args , env )
393
393
394
- def run (self , args , env = None ):
395
- proc = subprocess .Popen (args , env = env )
394
+ def run (self , args , env = None , cwd = None ):
395
+ proc = subprocess .Popen (args , env = env , cwd = cwd )
396
396
ret = proc .wait ()
397
397
if ret != 0 :
398
398
sys .exit (ret )
399
399
400
+ def output (self , args , env = None , cwd = None ):
401
+ proc = subprocess .Popen (args , stdout = subprocess .PIPE , env = env , cwd = cwd )
402
+ (out , err ) = proc .communicate ()
403
+ ret = proc .wait ()
404
+ if ret != 0 :
405
+ print (out )
406
+ sys .exit (ret )
407
+ return out
408
+
400
409
def build_triple (self ):
401
410
default_encoding = sys .getdefaultencoding ()
402
411
config = self .get_toml ('build' )
@@ -541,25 +550,47 @@ def update_submodules(self):
541
550
return
542
551
543
552
print ('Updating submodules' )
544
- self .run (["git" , "-C" , self .rust_root , "submodule" , "-q" , "sync" ])
545
- # FIXME: nobody does, but this won't work well with whitespace in
546
- # submodule path
547
- submodules = [s .split ()[1 ] for s in subprocess .check_output (
548
- ["git" , "config" , "--file" , os .path .join (
549
- self .rust_root , ".gitmodules" ), "--get-regexp" , "path" ]).splitlines ()]
550
- for module in submodules :
551
- if module .endswith (b"llvm" ) and \
553
+ output = self .output (["git" , "submodule" , "status" ], cwd = self .rust_root )
554
+ submodules = []
555
+ for line in output .splitlines ():
556
+ # NOTE `git submodule status` output looks like this:
557
+ #
558
+ # -5066b7dcab7e700844b0e2ba71b8af9dc627a59b src/liblibc
559
+ # +b37ef24aa82d2be3a3cc0fe89bf82292f4ca181c src/compiler-rt (remotes/origin/..)
560
+ # e058ca661692a8d01f8cf9d35939dfe3105ce968 src/jemalloc (3.6.0-533-ge058ca6)
561
+ #
562
+ # The first character can be '-', '+' or ' ' and denotes the
563
+ # `State` of the submodule Right next to this character is the
564
+ # SHA-1 of the submodule HEAD And after that comes the path to the
565
+ # submodule
566
+ path = line [1 :].split (' ' )[1 ]
567
+ submodules .append ([path , line [0 ]])
568
+
569
+ self .run (["git" , "submodule" , "sync" ], cwd = self .rust_root )
570
+
571
+ for submod in submodules :
572
+ path , status = submod
573
+ if path .endswith (b"llvm" ) and \
552
574
(self .get_toml ('llvm-config' ) or self .get_mk ('CFG_LLVM_ROOT' )):
553
575
continue
554
- if module .endswith (b"jemalloc" ) and \
576
+ if path .endswith (b"jemalloc" ) and \
555
577
(self .get_toml ('jemalloc' ) or self .get_mk ('CFG_JEMALLOC_ROOT' )):
556
578
continue
557
- self .run (["git" , "-C" , self .rust_root ,
558
- "submodule" , "update" , "--init" , module ])
559
- self .run (["git" , "-C" , self .rust_root , "submodule" , "-q" ,
560
- "foreach" , "git" , "reset" , "-q" , "--hard" ])
561
- self .run (["git" , "-C" , self .rust_root , "submodule" ,
562
- "-q" , "foreach" , "git" , "clean" , "-qdfx" ])
579
+ submod_path = os .path .join (self .rust_root , path )
580
+
581
+ if status == ' ' :
582
+ self .run (["git" , "reset" , "--hard" ], cwd = submod_path )
583
+ self .run (["git" , "clean" , "-fdx" ], cwd = submod_path )
584
+ elif status == '+' :
585
+ self .run (["git" , "submodule" , "update" , path ], cwd = self .rust_root )
586
+ self .run (["git" , "reset" , "--hard" ], cwd = submod_path )
587
+ self .run (["git" , "clean" , "-fdx" ], cwd = submod_path )
588
+ elif status == '-' :
589
+ self .run (["git" , "submodule" , "init" , path ], cwd = self .rust_root )
590
+ self .run (["git" , "submodule" , "update" , path ], cwd = self .rust_root )
591
+ else :
592
+ raise ValueError ('unknown submodule status: ' + status )
593
+
563
594
def bootstrap ():
564
595
parser = argparse .ArgumentParser (description = 'Build rust' )
565
596
parser .add_argument ('--config' )
0 commit comments