From 6b61d98fb030f4cbd2db15071f15a0468dfddc83 Mon Sep 17 00:00:00 2001 From: Behnam Esfahbod Date: Mon, 12 Nov 2018 00:43:25 -0800 Subject: [PATCH] [sources/path] Enable gitignore-like pattern matching Enable gitignore-like pattern matching for package's `include`/`exclude` rules, as suggested in #4268 and initially implemented in #4270. We still warn on projects affected by the divergent behavior. We can drop the warning and clean up the source and tests in one or more releases. --- src/cargo/sources/path.rs | 28 ++++++++++++++++------------ tests/testsuite/package.rs | 22 +++++++--------------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/src/cargo/sources/path.rs b/src/cargo/sources/path.rs index 3f61febbfd3..d03b07cba9c 100644 --- a/src/cargo/sources/path.rs +++ b/src/cargo/sources/path.rs @@ -103,14 +103,15 @@ impl<'cfg> PathSource<'cfg> { /// stages are: /// /// 1) Only warn users about the future change iff their matching rules are - /// affected. (CURRENT STAGE) + /// affected. /// /// 2) Switch to the new strategy and update documents. Still keep warning - /// affected users. + /// affected users. (CURRENT STAGE) /// /// 3) Drop the old strategy and no more warnings. /// /// See for more info. + // TODO: Drop glob-related code for Stage 3.. pub fn list_files(&self, pkg: &Package) -> CargoResult> { let root = pkg.root(); let no_include_option = pkg.manifest().include().is_empty(); @@ -208,38 +209,41 @@ impl<'cfg> PathSource<'cfg> { if glob_should_package { if no_include_option { self.config.shell().warn(format!( - "Pattern matching for Cargo's include/exclude fields is changing and \ - file `{}` WILL be excluded in a future Cargo version.\n\ + "Pattern matching for Cargo's include/exclude fields has changed and \ + file `{}` is NOW excluded, but USED TO be NOT excluded in a \ + previous Cargo version.\n\ See https://github.com/rust-lang/cargo/issues/4268 for more info", relative_path.display() ))?; } else { self.config.shell().warn(format!( - "Pattern matching for Cargo's include/exclude fields is changing and \ - file `{}` WILL NOT be included in a future Cargo version.\n\ + "Pattern matching for Cargo's include/exclude fields has changed and \ + file `{}` is NOT included anymore, but USED TO be included in a \ + previous Cargo version.\n\ See https://github.com/rust-lang/cargo/issues/4268 for more info", relative_path.display() ))?; } } else if no_include_option { self.config.shell().warn(format!( - "Pattern matching for Cargo's include/exclude fields is changing and \ - file `{}` WILL NOT be excluded in a future Cargo version.\n\ + "Pattern matching for Cargo's include/exclude fields has changed and \ + file `{}` is NOW NOT excluded, but USED TO be excluded in a \ + previous Cargo version.\n\ See https://github.com/rust-lang/cargo/issues/4268 for more info", relative_path.display() ))?; } else { self.config.shell().warn(format!( - "Pattern matching for Cargo's include/exclude fields is changing and \ - file `{}` WILL be included in a future Cargo version.\n\ + "Pattern matching for Cargo's include/exclude fields has changed and \ + file `{}` is NOW included, but USED TO be NOT included in a \ + previous Cargo version.\n\ See https://github.com/rust-lang/cargo/issues/4268 for more info", relative_path.display() ))?; } } - // Update to ignore_should_package for Stage 2 - Ok(glob_should_package) + Ok(ignore_should_package) }; // attempt git-prepopulate only if no `include` (rust-lang/cargo#4135) diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs index d5517131625..edcca01a8cc 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -316,7 +316,7 @@ fn exclude() { "*.txt", # file in root "file_root_1", # NO_CHANGE (ignored) - "/file_root_2", # CHANGING (packaged -> ignored) + "/file_root_2", # NO_CHANGE (ignored) "file_root_3/", # NO_CHANGE (packaged) "file_root_4/*", # NO_CHANGE (packaged) "file_root_5/**", # NO_CHANGE (packaged) @@ -377,17 +377,17 @@ fn exclude() { "\ [WARNING] manifest has no description[..] See http://doc.crates.io/manifest.html#package-metadata for more info. -[WARNING] [..] file `dir_root_1/some_dir/file` WILL be excluded [..] +[WARNING] [..] file `dir_root_1/some_dir/file` is NOW excluded [..] See [..] -[WARNING] [..] file `dir_root_2/some_dir/file` WILL be excluded [..] +[WARNING] [..] file `dir_root_2/some_dir/file` is NOW excluded [..] See [..] -[WARNING] [..] file `dir_root_3/some_dir/file` WILL be excluded [..] +[WARNING] [..] file `dir_root_3/some_dir/file` is NOW excluded [..] See [..] -[WARNING] [..] file `some_dir/dir_deep_1/some_dir/file` WILL be excluded [..] +[WARNING] [..] file `some_dir/dir_deep_1/some_dir/file` is NOW excluded [..] See [..] -[WARNING] [..] file `some_dir/dir_deep_3/some_dir/file` WILL be excluded [..] +[WARNING] [..] file `some_dir/dir_deep_3/some_dir/file` is NOW excluded [..] See [..] -[WARNING] [..] file `some_dir/file_deep_1` WILL be excluded [..] +[WARNING] [..] file `some_dir/file_deep_1` is NOW excluded [..] See [..] [PACKAGING] foo v0.0.1 ([..]) [ARCHIVING] [..] @@ -421,18 +421,10 @@ See [..] "\ .cargo_vcs_info.json Cargo.toml -dir_root_1/some_dir/file -dir_root_2/some_dir/file -dir_root_3/some_dir/file file_root_3 file_root_4 file_root_5 -some_dir/dir_deep_1/some_dir/file some_dir/dir_deep_2/some_dir/file -some_dir/dir_deep_3/some_dir/file -some_dir/dir_deep_4/some_dir/file -some_dir/dir_deep_5/some_dir/file -some_dir/file_deep_1 some_dir/file_deep_2 some_dir/file_deep_3 some_dir/file_deep_4