@@ -4,8 +4,9 @@ use std::collections::BTreeSet;
44use std:: env;
55use std:: ffi:: OsStr ;
66use std:: fmt:: { Debug , Write } ;
7- use std:: fs:: { self } ;
7+ use std:: fs:: { self , File } ;
88use std:: hash:: Hash ;
9+ use std:: io:: { BufRead , BufReader } ;
910use std:: ops:: Deref ;
1011use std:: path:: { Component , Path , PathBuf } ;
1112use std:: process:: Command ;
@@ -484,17 +485,43 @@ impl<'a> ShouldRun<'a> {
484485
485486 // multiple aliases for the same job
486487 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+
487512 self . paths . insert ( PathSet :: Set (
488513 paths
489514 . iter ( )
490515 . 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+
498525 TaskPath { path : p. into ( ) , kind : Some ( self . kind ) }
499526 } )
500527 . collect ( ) ,
0 commit comments