@@ -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 ):
130+ def run (args , verbose = False , exception = False ):
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 )
136+ ret = subprocess .Popen (args )
137137 code = ret .wait ()
138138 if code != 0 :
139139 err = "failed to run: " + ' ' .join (args )
@@ -389,24 +389,14 @@ def build_bootstrap(self):
389389 args .append ("--locked" )
390390 if self .use_vendored_sources :
391391 args .append ("--frozen" )
392- self .run (args , env )
392+ self .run (args , env = env )
393393
394- def run (self , args , env = None , cwd = None ):
395- proc = subprocess .Popen (args , env = env , cwd = cwd )
394+ def run (self , args , ** kwargs ):
395+ proc = subprocess .Popen (args , ** kwargs )
396396 ret = proc .wait ()
397397 if ret != 0 :
398398 sys .exit (ret )
399399
400- def output (self , args , env = None , cwd = None ):
401- default_encoding = sys .getdefaultencoding ()
402- proc = subprocess .Popen (args , stdout = subprocess .PIPE , env = env , cwd = cwd )
403- (out , err ) = proc .communicate ()
404- ret = proc .wait ()
405- if ret != 0 :
406- print (out )
407- sys .exit (ret )
408- return out .decode (default_encoding )
409-
410400 def build_triple (self ):
411401 default_encoding = sys .getdefaultencoding ()
412402 config = self .get_toml ('build' )
@@ -551,46 +541,26 @@ def update_submodules(self):
551541 return
552542
553543 print ('Updating submodules' )
554- output = self .output (["git" , "submodule" , "status" ], cwd = self .rust_root )
555- submodules = []
556- for line in output .splitlines ():
557- # NOTE `git submodule status` output looks like this:
558- #
559- # -5066b7dcab7e700844b0e2ba71b8af9dc627a59b src/liblibc
560- # +b37ef24aa82d2be3a3cc0fe89bf82292f4ca181c src/compiler-rt (remotes/origin/..)
561- # e058ca661692a8d01f8cf9d35939dfe3105ce968 src/jemalloc (3.6.0-533-ge058ca6)
562- #
563- # The first character can be '-', '+' or ' ' and denotes the
564- # `State` of the submodule Right next to this character is the
565- # SHA-1 of the submodule HEAD And after that comes the path to the
566- # submodule
567- path = line [1 :].split (' ' )[1 ]
568- submodules .append ([path , line [0 ]])
569-
570- self .run (["git" , "submodule" , "sync" ], cwd = self .rust_root )
571-
572- for submod in submodules :
573- path , status = submod
574- if path .endswith ('llvm' ) and \
544+ self .run (["git" , "submodule" , "-q" , "sync" ], cwd = self .rust_root )
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 \
575552 (self .get_toml ('llvm-config' ) or self .get_mk ('CFG_LLVM_ROOT' )):
576553 continue
577- if path .endswith (' jemalloc' ) and \
554+ if module .endswith (b" jemalloc" ) and \
578555 (self .get_toml ('jemalloc' ) or self .get_mk ('CFG_JEMALLOC_ROOT' )):
579556 continue
580- submod_path = os .path .join (self .rust_root , path )
581-
582- if status == ' ' :
583- self .run (["git" , "reset" , "--hard" ], cwd = submod_path )
584- self .run (["git" , "clean" , "-fdx" ], cwd = submod_path )
585- elif status == '+' :
586- self .run (["git" , "submodule" , "update" , path ], cwd = self .rust_root )
587- self .run (["git" , "reset" , "--hard" ], cwd = submod_path )
588- self .run (["git" , "clean" , "-fdx" ], cwd = submod_path )
589- elif status == '-' :
590- self .run (["git" , "submodule" , "init" , path ], cwd = self .rust_root )
591- self .run (["git" , "submodule" , "update" , path ], cwd = self .rust_root )
592- else :
593- raise ValueError ('unknown submodule status: ' + status )
557+ self .run (["git" , "submodule" , "update" ,
558+ "--init" , module ], cwd = self .rust_root )
559+ self .run (["git" , "submodule" , "-q" , "foreach" , "git" ,
560+ "reset" , "-q" , "--hard" ], cwd = self .rust_root )
561+ self .run (["git" , "submodule" , "-q" , "foreach" , "git" ,
562+ "clean" , "-qdfx" ], cwd = self .rust_root )
563+
594564
595565def bootstrap ():
596566 parser = argparse .ArgumentParser (description = 'Build rust' )
@@ -676,7 +646,7 @@ def bootstrap():
676646 env ["BUILD" ] = rb .build
677647 env ["SRC" ] = rb .rust_root
678648 env ["BOOTSTRAP_PARENT_ID" ] = str (os .getpid ())
679- rb .run (args , env )
649+ rb .run (args , env = env )
680650
681651def main ():
682652 start_time = time ()
0 commit comments