Skip to content

Commit

Permalink
[sources/path] Enable gitignore-like pattern matching
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
behnam committed Nov 12, 2018
1 parent 2ad4432 commit 6b61d98
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 27 deletions.
28 changes: 16 additions & 12 deletions src/cargo/sources/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/rust-lang/cargo/issues/4268> for more info.
// TODO: Drop glob-related code for Stage 3..
pub fn list_files(&self, pkg: &Package) -> CargoResult<Vec<PathBuf>> {
let root = pkg.root();
let no_include_option = pkg.manifest().include().is_empty();
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 7 additions & 15 deletions tests/testsuite/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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] [..]
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6b61d98

Please sign in to comment.