@@ -916,73 +916,68 @@ fn copy_src_dirs(
916916 exclude_dirs : & [ & str ] ,
917917 dst_dir : & Path ,
918918) {
919+ // The src directories should be relative to `base`, we depend on them not being absolute
920+ // paths below.
921+ for src_dir in src_dirs {
922+ assert ! ( Path :: new( src_dir) . is_relative( ) ) ;
923+ }
924+
919925 fn filter_fn ( exclude_dirs : & [ & str ] , dir : & str , path : & Path ) -> bool {
926+ // The paths are relative, e.g. `llvm-project/...`.
920927 let spath = match path. to_str ( ) {
921928 Some ( path) => path,
922929 None => return false ,
923930 } ;
924931 if spath. ends_with ( '~' ) || spath. ends_with ( ".pyc" ) {
925932 return false ;
926933 }
934+ // Normalize slashes
935+ let spath = spath. replace ( "\\ " , "/" ) ;
927936
928- const LLVM_PROJECTS : & [ & str ] = & [
937+ static LLVM_PROJECTS : & [ & str ] = & [
929938 "llvm-project/clang" ,
930- "llvm-project\\ clang" ,
931939 "llvm-project/libunwind" ,
932- "llvm-project\\ libunwind" ,
933940 "llvm-project/lld" ,
934- "llvm-project\\ lld" ,
935941 "llvm-project/lldb" ,
936- "llvm-project\\ lldb" ,
937942 "llvm-project/llvm" ,
938- "llvm-project\\ llvm" ,
939943 "llvm-project/compiler-rt" ,
940- "llvm-project\\ compiler-rt" ,
941944 "llvm-project/cmake" ,
942- "llvm-project\\ cmake" ,
943945 "llvm-project/runtimes" ,
944- "llvm-project\\ runtimes" ,
945946 "llvm-project/third-party" ,
946- "llvm-project\\ third-party" ,
947947 ] ;
948- if spath. contains ( "llvm-project" )
949- && !spath. ends_with ( "llvm-project" )
950- && !LLVM_PROJECTS . iter ( ) . any ( |path| spath. contains ( path) )
951- {
952- return false ;
953- }
948+ if spath. starts_with ( "llvm-project" ) && spath != "llvm-project" {
949+ if !LLVM_PROJECTS . iter ( ) . any ( |path| spath. starts_with ( path) ) {
950+ return false ;
951+ }
954952
955- // Keep only these third party libraries
956- const LLVM_THIRD_PARTY : & [ & str ] =
957- & [ "llvm-project/third-party/siphash" , "llvm-project\\ third-party\\ siphash" ] ;
958- if ( spath. starts_with ( "llvm-project/third-party" )
959- || spath. starts_with ( "llvm-project\\ third-party" ) )
960- && !( spath. ends_with ( "llvm-project/third-party" )
961- || spath. ends_with ( "llvm-project\\ third-party" ) )
962- && !LLVM_THIRD_PARTY . iter ( ) . any ( |path| spath. contains ( path) )
963- {
964- return false ;
965- }
953+ // Keep siphash third-party dependency
954+ if spath. starts_with ( "llvm-project/third-party" )
955+ && spath != "llvm-project/third-party"
956+ && !spath. starts_with ( "llvm-project/third-party/siphash" )
957+ {
958+ return false ;
959+ }
966960
967- const LLVM_TEST : & [ & str ] = & [ "llvm-project/llvm/test" , "llvm-project \\ llvm \\ test" ] ;
968- if LLVM_TEST . iter ( ) . any ( |path | spath. contains ( path ) )
969- && ( spath . ends_with ( ".ll" ) || spath . ends_with ( ".td" ) || spath . ends_with ( ".s" ) )
970- {
971- return false ;
961+ if spath . starts_with ( "llvm-project/llvm/test" )
962+ && ( spath . ends_with ( ".ll" ) || spath . ends_with ( ".td" ) | | spath. ends_with ( ".s" ) )
963+ {
964+ return false ;
965+ }
972966 }
973967
974968 // Cargo tests use some files like `.gitignore` that we would otherwise exclude.
975- const CARGO_TESTS : & [ & str ] = & [ "tools/cargo/tests" , "tools\\ cargo\\ tests" ] ;
976- if CARGO_TESTS . iter ( ) . any ( |path| spath. contains ( path) ) {
969+ if spath. starts_with ( "tools/cargo/tests" ) {
977970 return true ;
978971 }
979972
980- let full_path = Path :: new ( dir) . join ( path) ;
981- if exclude_dirs. iter ( ) . any ( |excl| full_path == Path :: new ( excl) ) {
982- return false ;
973+ if !exclude_dirs. is_empty ( ) {
974+ let full_path = Path :: new ( dir) . join ( path) ;
975+ if exclude_dirs. iter ( ) . any ( |excl| full_path == Path :: new ( excl) ) {
976+ return false ;
977+ }
983978 }
984979
985- let excludes = [
980+ static EXCLUDES : & [ & str ] = & [
986981 "CVS" ,
987982 "RCS" ,
988983 "SCCS" ,
@@ -1005,7 +1000,15 @@ fn copy_src_dirs(
10051000 ".hgrags" ,
10061001 "_darcs" ,
10071002 ] ;
1008- !path. iter ( ) . map ( |s| s. to_str ( ) . unwrap ( ) ) . any ( |s| excludes. contains ( & s) )
1003+
1004+ // We want to check if any component of `path` doesn't contain the strings in `EXCLUDES`.
1005+ // However, since we traverse directories top-down in `Builder::cp_link_filtered`,
1006+ // it is enough to always check only the last component:
1007+ // - If the path is a file, we will iterate to it and then check it's filename
1008+ // - If the path is a dir, if it's dir name contains an excluded string, we will not even
1009+ // recurse into it.
1010+ let last_component = path. iter ( ) . next_back ( ) . map ( |s| s. to_str ( ) . unwrap ( ) ) . unwrap ( ) ;
1011+ !EXCLUDES . contains ( & last_component)
10091012 }
10101013
10111014 // Copy the directories using our filter
0 commit comments