@@ -597,10 +597,8 @@ def build_bootstrap(self):
597
597
self .cargo ()))
598
598
args = [self .cargo (), "build" , "--manifest-path" ,
599
599
os .path .join (self .rust_root , "src/bootstrap/Cargo.toml" )]
600
- if self .verbose :
600
+ for _ in range ( 1 , self .verbose ) :
601
601
args .append ("--verbose" )
602
- if self .verbose > 1 :
603
- args .append ("--verbose" )
604
602
if self .use_locked_deps :
605
603
args .append ("--locked" )
606
604
if self .use_vendored_sources :
@@ -614,20 +612,55 @@ def build_triple(self):
614
612
return config
615
613
return default_build_triple ()
616
614
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
+
617
645
def update_submodules (self ):
618
646
"""Update submodules"""
619
647
if (not os .path .exists (os .path .join (self .rust_root , ".git" ))) or \
620
648
self .get_toml ('submodules' ) == "false" :
621
649
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' )
623
656
default_encoding = sys .getdefaultencoding ()
624
- run (["git" , "submodule" , "-q" , "sync" ], cwd = self .rust_root , verbose = self .verbose )
625
657
submodules = [s .split (' ' , 1 )[1 ] for s in subprocess .check_output (
626
658
["git" , "config" , "--file" ,
627
659
os .path .join (self .rust_root , ".gitmodules" ),
628
660
"--get-regexp" , "path" ]
629
661
).decode (default_encoding ).splitlines ()]
630
662
filtered_submodules = []
663
+ submodules_names = []
631
664
for module in submodules :
632
665
if module .endswith ("llvm" ):
633
666
if self .get_toml ('llvm-config' ):
@@ -645,16 +678,19 @@ def update_submodules(self):
645
678
config = self .get_toml ('lld' )
646
679
if config is None or config == 'false' :
647
680
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 ))
658
694
659
695
def set_dev_environment (self ):
660
696
"""Set download URL for development environment"""
@@ -675,7 +711,7 @@ def bootstrap(help_triggered):
675
711
parser .add_argument ('--config' )
676
712
parser .add_argument ('--build' )
677
713
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 )
679
715
680
716
args = [a for a in sys .argv if a != '-h' and a != '--help' ]
681
717
args , _ = parser .parse_known_args (args )
@@ -691,10 +727,9 @@ def bootstrap(help_triggered):
691
727
except (OSError , IOError ):
692
728
pass
693
729
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 )))
698
733
699
734
build .use_vendored_sources = '\n vendor = true' in build .config_toml
700
735
0 commit comments