@@ -554,29 +554,7 @@ impl<'a> ShouldRun<'a> {
554
554
///
555
555
/// [`path`]: ShouldRun::path
556
556
pub fn paths ( mut self , paths : & [ & str ] ) -> Self {
557
- static SUBMODULES_PATHS : OnceLock < Vec < String > > = OnceLock :: new ( ) ;
558
-
559
- let init_submodules_paths = |src : & PathBuf | {
560
- let file = File :: open ( src. join ( ".gitmodules" ) ) . unwrap ( ) ;
561
-
562
- let mut submodules_paths = vec ! [ ] ;
563
- for line in BufReader :: new ( file) . lines ( ) {
564
- if let Ok ( line) = line {
565
- let line = line. trim ( ) ;
566
-
567
- if line. starts_with ( "path" ) {
568
- let actual_path =
569
- line. split ( ' ' ) . last ( ) . expect ( "Couldn't get value of path" ) ;
570
- submodules_paths. push ( actual_path. to_owned ( ) ) ;
571
- }
572
- }
573
- }
574
-
575
- submodules_paths
576
- } ;
577
-
578
- let submodules_paths =
579
- SUBMODULES_PATHS . get_or_init ( || init_submodules_paths ( & self . builder . src ) ) ;
557
+ let submodules_paths = self . builder . get_all_submodules ( ) ;
580
558
581
559
self . paths . insert ( PathSet :: Set (
582
560
paths
@@ -2151,6 +2129,37 @@ impl<'a> Builder<'a> {
2151
2129
out
2152
2130
}
2153
2131
2132
+ /// Return paths of all submodules managed by git.
2133
+ /// If the current checkout is not managed by git, returns an empty slice.
2134
+ pub fn get_all_submodules ( & self ) -> & [ String ] {
2135
+ if !self . rust_info ( ) . is_managed_git_subrepository ( ) {
2136
+ return & [ ] ;
2137
+ }
2138
+
2139
+ static SUBMODULES_PATHS : OnceLock < Vec < String > > = OnceLock :: new ( ) ;
2140
+
2141
+ let init_submodules_paths = |src : & PathBuf | {
2142
+ let file = File :: open ( src. join ( ".gitmodules" ) ) . unwrap ( ) ;
2143
+
2144
+ let mut submodules_paths = vec ! [ ] ;
2145
+ for line in BufReader :: new ( file) . lines ( ) {
2146
+ if let Ok ( line) = line {
2147
+ let line = line. trim ( ) ;
2148
+
2149
+ if line. starts_with ( "path" ) {
2150
+ let actual_path =
2151
+ line. split ( ' ' ) . last ( ) . expect ( "Couldn't get value of path" ) ;
2152
+ submodules_paths. push ( actual_path. to_owned ( ) ) ;
2153
+ }
2154
+ }
2155
+ }
2156
+
2157
+ submodules_paths
2158
+ } ;
2159
+
2160
+ & SUBMODULES_PATHS . get_or_init ( || init_submodules_paths ( & self . src ) )
2161
+ }
2162
+
2154
2163
/// Ensure that a given step is built *only if it's supposed to be built by default*, returning
2155
2164
/// its output. This will cache the step, so it's safe (and good!) to call this as often as
2156
2165
/// needed to ensure that all dependencies are build.
0 commit comments