@@ -597,10 +597,8 @@ def build_bootstrap(self):
597597 self .cargo ()))
598598 args = [self .cargo (), "build" , "--manifest-path" ,
599599 os .path .join (self .rust_root , "src/bootstrap/Cargo.toml" )]
600- if self .verbose :
600+ for _ in range ( 1 , self .verbose ) :
601601 args .append ("--verbose" )
602- if self .verbose > 1 :
603- args .append ("--verbose" )
604602 if self .use_locked_deps :
605603 args .append ("--locked" )
606604 if self .use_vendored_sources :
@@ -614,20 +612,55 @@ def build_triple(self):
614612 return config
615613 return default_build_triple ()
616614
615+ def check_submodule (self , module , slow_submodules ):
616+ if not slow_submodules :
617+ checked_out = subprocess .Popen (["git" , "rev-parse" , "HEAD" ],
618+ cwd = os .path .join (self .rust_root , module ),
619+ stdout = subprocess .PIPE )
620+ return checked_out
621+ else :
622+ return None
623+
624+ def update_submodule (self , module , checked_out , recorded_submodules ):
625+ module_path = os .path .join (self .rust_root , module )
626+
627+ if checked_out != None :
628+ default_encoding = sys .getdefaultencoding ()
629+ checked_out = checked_out .communicate ()[0 ].decode (default_encoding ).strip ()
630+ if recorded_submodules [module ] == checked_out :
631+ return
632+
633+ print ("Updating submodule" , module )
634+
635+ run (["git" , "submodule" , "-q" , "sync" , module ],
636+ cwd = self .rust_root , verbose = self .verbose )
637+ run (["git" , "submodule" , "update" ,
638+ "--init" , "--recursive" , module ],
639+ cwd = self .rust_root , verbose = self .verbose )
640+ run (["git" , "reset" , "-q" , "--hard" ],
641+ cwd = module_path , verbose = self .verbose )
642+ run (["git" , "clean" , "-qdfx" ],
643+ cwd = module_path , verbose = self .verbose )
644+
617645 def update_submodules (self ):
618646 """Update submodules"""
619647 if (not os .path .exists (os .path .join (self .rust_root , ".git" ))) or \
620648 self .get_toml ('submodules' ) == "false" :
621649 return
622- print ('Updating submodules' )
650+ slow_submodules = self .get_toml ('fast-submodule' ) == "false"
651+ start_time = time ()
652+ if slow_submodules :
653+ print ('Unconditionally updating all submodules' )
654+ else :
655+ print ('Updating only changed submodules' )
623656 default_encoding = sys .getdefaultencoding ()
624- run (["git" , "submodule" , "-q" , "sync" ], cwd = self .rust_root , verbose = self .verbose )
625657 submodules = [s .split (' ' , 1 )[1 ] for s in subprocess .check_output (
626658 ["git" , "config" , "--file" ,
627659 os .path .join (self .rust_root , ".gitmodules" ),
628660 "--get-regexp" , "path" ]
629661 ).decode (default_encoding ).splitlines ()]
630662 filtered_submodules = []
663+ submodules_names = []
631664 for module in submodules :
632665 if module .endswith ("llvm" ):
633666 if self .get_toml ('llvm-config' ):
@@ -645,16 +678,19 @@ def update_submodules(self):
645678 config = self .get_toml ('lld' )
646679 if config is None or config == 'false' :
647680 continue
648- filtered_submodules .append (module )
649- run (["git" , "submodule" , "update" ,
650- "--init" , "--recursive" ] + filtered_submodules ,
651- cwd = self .rust_root , verbose = self .verbose )
652- run (["git" , "submodule" , "-q" , "foreach" , "git" ,
653- "reset" , "-q" , "--hard" ],
654- cwd = self .rust_root , verbose = self .verbose )
655- run (["git" , "submodule" , "-q" , "foreach" , "git" ,
656- "clean" , "-qdfx" ],
657- cwd = self .rust_root , verbose = self .verbose )
681+ check = self .check_submodule (module , slow_submodules )
682+ filtered_submodules .append ((module , check ))
683+ submodules_names .append (module )
684+ recorded = subprocess .Popen (["git" , "ls-tree" , "HEAD" ] + submodules_names ,
685+ cwd = self .rust_root , stdout = subprocess .PIPE )
686+ recorded = recorded .communicate ()[0 ].decode (default_encoding ).strip ().splitlines ()
687+ recorded_submodules = {}
688+ for data in recorded :
689+ data = data .split ()
690+ recorded_submodules [data [3 ]] = data [2 ]
691+ for module in filtered_submodules :
692+ self .update_submodule (module [0 ], module [1 ], recorded_submodules )
693+ print ("Submodules updated in %.2f seconds" % (time () - start_time ))
658694
659695 def set_dev_environment (self ):
660696 """Set download URL for development environment"""
@@ -675,7 +711,7 @@ def bootstrap(help_triggered):
675711 parser .add_argument ('--config' )
676712 parser .add_argument ('--build' )
677713 parser .add_argument ('--clean' , action = 'store_true' )
678- parser .add_argument ('-v' , '--verbose' , action = 'store_true' )
714+ parser .add_argument ('-v' , '--verbose' , action = 'count' , default = 0 )
679715
680716 args = [a for a in sys .argv if a != '-h' and a != '--help' ]
681717 args , _ = parser .parse_known_args (args )
@@ -691,10 +727,9 @@ def bootstrap(help_triggered):
691727 except (OSError , IOError ):
692728 pass
693729
694- if '\n verbose = 2' in build .config_toml :
695- build .verbose = 2
696- elif '\n verbose = 1' in build .config_toml :
697- build .verbose = 1
730+ match = re .search (r'\nverbose = (\d+)' , build .config_toml )
731+ if match is not None :
732+ build .verbose = max (build .verbose , int (match .group (1 )))
698733
699734 build .use_vendored_sources = '\n vendor = true' in build .config_toml
700735
0 commit comments