@@ -4,8 +4,9 @@ use std::collections::BTreeSet;
4
4
use std:: env;
5
5
use std:: ffi:: OsStr ;
6
6
use std:: fmt:: { Debug , Write } ;
7
- use std:: fs:: { self } ;
7
+ use std:: fs:: { self , File } ;
8
8
use std:: hash:: Hash ;
9
+ use std:: io:: { BufRead , BufReader } ;
9
10
use std:: ops:: Deref ;
10
11
use std:: path:: { Component , Path , PathBuf } ;
11
12
use std:: process:: Command ;
@@ -484,17 +485,43 @@ impl<'a> ShouldRun<'a> {
484
485
485
486
// multiple aliases for the same job
486
487
pub fn paths ( mut self , paths : & [ & str ] ) -> Self {
488
+ lazy_static:: lazy_static! {
489
+ static ref SUBMODULES_PATHS : Vec <String > = get_submodules_paths( ) ;
490
+ }
491
+
492
+ fn get_submodules_paths ( ) -> Vec < String > {
493
+ let manifest_dir = PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
494
+ let src = manifest_dir. ancestors ( ) . nth ( 2 ) . unwrap ( ) ;
495
+ let file = File :: open ( src. join ( ".gitmodules" ) ) . unwrap ( ) ;
496
+
497
+ let mut submodules_paths = vec ! [ ] ;
498
+ for line in BufReader :: new ( file) . lines ( ) {
499
+ if let Ok ( line) = line {
500
+ let line = line. trim ( ) ;
501
+
502
+ if line. starts_with ( "path" ) {
503
+ let actual_path = line. split ( ' ' ) . last ( ) . unwrap ( ) ;
504
+ submodules_paths. push ( actual_path. to_owned ( ) ) ;
505
+ }
506
+ }
507
+ }
508
+
509
+ submodules_paths
510
+ }
511
+
487
512
self . paths . insert ( PathSet :: Set (
488
513
paths
489
514
. iter ( )
490
515
. map ( |p| {
491
- // FIXME(#96188): make sure this is actually a path.
492
- // This currently breaks for paths within submodules.
493
- //assert!(
494
- // self.builder.src.join(p).exists(),
495
- // "`should_run.paths` should correspond to real on-disk paths - use `alias` if there is no relevant path: {}",
496
- // p
497
- //);
516
+ // assert only if `p` isn't submodule
517
+ if !SUBMODULES_PATHS . iter ( ) . find ( |sm_p| p. contains ( * sm_p) ) . is_some ( ) {
518
+ assert ! (
519
+ self . builder. src. join( p) . exists( ) ,
520
+ "`should_run.paths` should correspond to real on-disk paths - use `alias` if there is no relevant path: {}" ,
521
+ p
522
+ ) ;
523
+ }
524
+
498
525
TaskPath { path : p. into ( ) , kind : Some ( self . kind ) }
499
526
} )
500
527
. collect ( ) ,
0 commit comments