@@ -127,13 +127,13 @@ def unpack(tarball, dst, verbose=False, match=None):
127127 shutil .move (tp , fp )
128128 shutil .rmtree (os .path .join (dst , fname ))
129129
130- def run (args , verbose = False , exception = False , cwd = None , env = None ):
130+ def run (args , verbose = False , exception = False , ** kwargs ):
131131 if verbose :
132132 print ("running: " + ' ' .join (args ))
133133 sys .stdout .flush ()
134134 # Use Popen here instead of call() as it apparently allows powershell on
135135 # Windows to not lock up waiting for input presumably.
136- ret = subprocess .Popen (args , cwd = cwd , env = env )
136+ ret = subprocess .Popen (args , ** kwargs )
137137 code = ret .wait ()
138138 if code != 0 :
139139 err = "failed to run: " + ' ' .join (args )
@@ -395,16 +395,6 @@ def build_bootstrap(self):
395395 args .append ("--frozen" )
396396 run (args , env = env , verbose = self .verbose )
397397
398- def output (self , args , env = None , cwd = None ):
399- default_encoding = sys .getdefaultencoding ()
400- proc = subprocess .Popen (args , stdout = subprocess .PIPE , env = env , cwd = cwd )
401- (out , err ) = proc .communicate ()
402- ret = proc .wait ()
403- if ret != 0 :
404- print (out )
405- sys .exit (ret )
406- return out .decode (default_encoding )
407-
408398 def build_triple (self ):
409399 default_encoding = sys .getdefaultencoding ()
410400 config = self .get_toml ('build' )
@@ -549,46 +539,26 @@ def update_submodules(self):
549539 return
550540
551541 print ('Updating submodules' )
552- output = self .output (["git" , "submodule" , "status" ], cwd = self .rust_root )
553- submodules = []
554- for line in output .splitlines ():
555- # NOTE `git submodule status` output looks like this:
556- #
557- # -5066b7dcab7e700844b0e2ba71b8af9dc627a59b src/liblibc
558- # +b37ef24aa82d2be3a3cc0fe89bf82292f4ca181c src/compiler-rt (remotes/origin/..)
559- # e058ca661692a8d01f8cf9d35939dfe3105ce968 src/jemalloc (3.6.0-533-ge058ca6)
560- #
561- # The first character can be '-', '+' or ' ' and denotes the
562- # `State` of the submodule Right next to this character is the
563- # SHA-1 of the submodule HEAD And after that comes the path to the
564- # submodule
565- path = line [1 :].split (' ' )[1 ]
566- submodules .append ([path , line [0 ]])
567-
568- run (["git" , "submodule" , "sync" ], cwd = self .rust_root )
569-
570- for submod in submodules :
571- path , status = submod
572- if path .endswith ('llvm' ) and \
542+ run (["git" , "submodule" , "-q" , "sync" ], cwd = self .rust_root )
543+ # FIXME: nobody does, but this won't work well with whitespace in
544+ # submodule path
545+ submodules = [s .split ()[1 ] for s in subprocess .check_output (
546+ ["git" , "config" , "--file" , os .path .join (
547+ self .rust_root , ".gitmodules" ), "--get-regexp" , "path" ]).splitlines ()]
548+ for module in submodules :
549+ if module .endswith (b"llvm" ) and \
573550 (self .get_toml ('llvm-config' ) or self .get_mk ('CFG_LLVM_ROOT' )):
574551 continue
575- if path .endswith (' jemalloc' ) and \
552+ if module .endswith (b" jemalloc" ) and \
576553 (self .get_toml ('jemalloc' ) or self .get_mk ('CFG_JEMALLOC_ROOT' )):
577554 continue
578- submod_path = os .path .join (self .rust_root , path )
579-
580- if status == ' ' :
581- run (["git" , "reset" , "--hard" ], cwd = submod_path )
582- run (["git" , "clean" , "-fdx" ], cwd = submod_path )
583- elif status == '+' :
584- run (["git" , "submodule" , "update" , path ], cwd = self .rust_root )
585- run (["git" , "reset" , "--hard" ], cwd = submod_path )
586- run (["git" , "clean" , "-fdx" ], cwd = submod_path )
587- elif status == '-' :
588- run (["git" , "submodule" , "init" , path ], cwd = self .rust_root )
589- run (["git" , "submodule" , "update" , path ], cwd = self .rust_root )
590- else :
591- raise ValueError ('unknown submodule status: ' + status )
555+ run (["git" , "submodule" , "update" ,
556+ "--init" , module ], cwd = self .rust_root )
557+ run (["git" , "submodule" , "-q" , "foreach" , "git" ,
558+ "reset" , "-q" , "--hard" ], cwd = self .rust_root )
559+ run (["git" , "submodule" , "-q" , "foreach" , "git" ,
560+ "clean" , "-qdfx" ], cwd = self .rust_root )
561+
592562
593563def bootstrap ():
594564 parser = argparse .ArgumentParser (description = 'Build rust' )
0 commit comments