@@ -473,117 +473,6 @@ impl Build {
473
473
build
474
474
}
475
475
476
- /// Given a path to the directory of a submodule, update it.
477
- ///
478
- /// `relative_path` should be relative to the root of the git repository, not an absolute path.
479
- ///
480
- /// This *does not* update the submodule if `config.toml` explicitly says
481
- /// not to, or if we're not in a git repository (like a plain source
482
- /// tarball). Typically [`Build::require_submodule`] should be
483
- /// used instead to provide a nice error to the user if the submodule is
484
- /// missing.
485
- fn update_submodule ( & self , relative_path : & str ) {
486
- if !self . config . submodules ( ) {
487
- return ;
488
- }
489
-
490
- let absolute_path = self . config . src . join ( relative_path) ;
491
-
492
- // NOTE: The check for the empty directory is here because when running x.py the first time,
493
- // the submodule won't be checked out. Check it out now so we can build it.
494
- if !GitInfo :: new ( false , & absolute_path) . is_managed_git_subrepository ( )
495
- && !dir_is_empty ( & absolute_path)
496
- {
497
- return ;
498
- }
499
-
500
- // Submodule updating actually happens during in the dry run mode. We need to make sure that
501
- // all the git commands below are actually executed, because some follow-up code
502
- // in bootstrap might depend on the submodules being checked out. Furthermore, not all
503
- // the command executions below work with an empty output (produced during dry run).
504
- // Therefore, all commands below are marked with `run_always()`, so that they also run in
505
- // dry run mode.
506
- let submodule_git = || {
507
- let mut cmd = helpers:: git ( Some ( & absolute_path) ) ;
508
- cmd. run_always ( ) ;
509
- cmd
510
- } ;
511
-
512
- // Determine commit checked out in submodule.
513
- let checked_out_hash =
514
- submodule_git ( ) . args ( [ "rev-parse" , "HEAD" ] ) . run_capture_stdout ( self ) . stdout ( ) ;
515
- let checked_out_hash = checked_out_hash. trim_end ( ) ;
516
- // Determine commit that the submodule *should* have.
517
- let recorded = helpers:: git ( Some ( & self . src ) )
518
- . run_always ( )
519
- . args ( [ "ls-tree" , "HEAD" ] )
520
- . arg ( relative_path)
521
- . run_capture_stdout ( self )
522
- . stdout ( ) ;
523
- let actual_hash = recorded
524
- . split_whitespace ( )
525
- . nth ( 2 )
526
- . unwrap_or_else ( || panic ! ( "unexpected output `{}`" , recorded) ) ;
527
-
528
- if actual_hash == checked_out_hash {
529
- // already checked out
530
- return ;
531
- }
532
-
533
- println ! ( "Updating submodule {relative_path}" ) ;
534
- helpers:: git ( Some ( & self . src ) )
535
- . run_always ( )
536
- . args ( [ "submodule" , "-q" , "sync" ] )
537
- . arg ( relative_path)
538
- . run ( self ) ;
539
-
540
- // Try passing `--progress` to start, then run git again without if that fails.
541
- let update = |progress : bool | {
542
- // Git is buggy and will try to fetch submodules from the tracking branch for *this* repository,
543
- // even though that has no relation to the upstream for the submodule.
544
- let current_branch = helpers:: git ( Some ( & self . src ) )
545
- . allow_failure ( )
546
- . run_always ( )
547
- . args ( [ "symbolic-ref" , "--short" , "HEAD" ] )
548
- . run_capture_stdout ( self )
549
- . stdout_if_ok ( )
550
- . map ( |s| s. trim ( ) . to_owned ( ) ) ;
551
-
552
- let mut git = helpers:: git ( Some ( & self . src ) ) . allow_failure ( ) ;
553
- git. run_always ( ) ;
554
- if let Some ( branch) = current_branch {
555
- // If there is a tag named after the current branch, git will try to disambiguate by prepending `heads/` to the branch name.
556
- // This syntax isn't accepted by `branch.{branch}`. Strip it.
557
- let branch = branch. strip_prefix ( "heads/" ) . unwrap_or ( & branch) ;
558
- git. arg ( "-c" ) . arg ( format ! ( "branch.{branch}.remote=origin" ) ) ;
559
- }
560
- git. args ( [ "submodule" , "update" , "--init" , "--recursive" , "--depth=1" ] ) ;
561
- if progress {
562
- git. arg ( "--progress" ) ;
563
- }
564
- git. arg ( relative_path) ;
565
- git
566
- } ;
567
- if !update ( true ) . run ( self ) {
568
- update ( false ) . run ( self ) ;
569
- }
570
-
571
- // Save any local changes, but avoid running `git stash pop` if there are none (since it will exit with an error).
572
- // diff-index reports the modifications through the exit status
573
- let has_local_modifications =
574
- !submodule_git ( ) . allow_failure ( ) . args ( [ "diff-index" , "--quiet" , "HEAD" ] ) . run ( self ) ;
575
- if has_local_modifications {
576
- submodule_git ( ) . args ( [ "stash" , "push" ] ) . run ( self ) ;
577
- }
578
-
579
- submodule_git ( ) . args ( [ "reset" , "-q" , "--hard" ] ) . run ( self ) ;
580
- submodule_git ( ) . args ( [ "clean" , "-qdfx" ] ) . run ( self ) ;
581
-
582
- if has_local_modifications {
583
- submodule_git ( ) . args ( [ "stash" , "pop" ] ) . run ( self ) ;
584
- }
585
- }
586
-
587
476
/// Updates a submodule, and exits with a failure if submodule management
588
477
/// is disabled and the submodule does not exist.
589
478
///
@@ -598,7 +487,7 @@ impl Build {
598
487
if cfg ! ( test) && !self . config . submodules ( ) {
599
488
return ;
600
489
}
601
- self . update_submodule ( submodule) ;
490
+ self . config . update_submodule ( submodule) ;
602
491
let absolute_path = self . config . src . join ( submodule) ;
603
492
if dir_is_empty ( & absolute_path) {
604
493
let maybe_enable = if !self . config . submodules ( )
@@ -646,7 +535,7 @@ impl Build {
646
535
let path = Path :: new ( submodule) ;
647
536
// Don't update the submodule unless it's already been cloned.
648
537
if GitInfo :: new ( false , path) . is_managed_git_subrepository ( ) {
649
- self . update_submodule ( submodule) ;
538
+ self . config . update_submodule ( submodule) ;
650
539
}
651
540
}
652
541
}
@@ -659,7 +548,7 @@ impl Build {
659
548
}
660
549
661
550
if GitInfo :: new ( false , Path :: new ( submodule) ) . is_managed_git_subrepository ( ) {
662
- self . update_submodule ( submodule) ;
551
+ self . config . update_submodule ( submodule) ;
663
552
}
664
553
}
665
554
0 commit comments