Skip to content

Commit 6b61d98

Browse files
committed
[sources/path] Enable gitignore-like pattern matching
Enable gitignore-like pattern matching for package's `include`/`exclude` rules, as suggested in rust-lang#4268 and initially implemented in rust-lang#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.
1 parent 2ad4432 commit 6b61d98

File tree

2 files changed

+23
-27
lines changed

2 files changed

+23
-27
lines changed

src/cargo/sources/path.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,15 @@ impl<'cfg> PathSource<'cfg> {
103103
/// stages are:
104104
///
105105
/// 1) Only warn users about the future change iff their matching rules are
106-
/// affected. (CURRENT STAGE)
106+
/// affected.
107107
///
108108
/// 2) Switch to the new strategy and update documents. Still keep warning
109-
/// affected users.
109+
/// affected users. (CURRENT STAGE)
110110
///
111111
/// 3) Drop the old strategy and no more warnings.
112112
///
113113
/// See <https://github.com/rust-lang/cargo/issues/4268> for more info.
114+
// TODO: Drop glob-related code for Stage 3..
114115
pub fn list_files(&self, pkg: &Package) -> CargoResult<Vec<PathBuf>> {
115116
let root = pkg.root();
116117
let no_include_option = pkg.manifest().include().is_empty();
@@ -208,38 +209,41 @@ impl<'cfg> PathSource<'cfg> {
208209
if glob_should_package {
209210
if no_include_option {
210211
self.config.shell().warn(format!(
211-
"Pattern matching for Cargo's include/exclude fields is changing and \
212-
file `{}` WILL be excluded in a future Cargo version.\n\
212+
"Pattern matching for Cargo's include/exclude fields has changed and \
213+
file `{}` is NOW excluded, but USED TO be NOT excluded in a \
214+
previous Cargo version.\n\
213215
See https://github.com/rust-lang/cargo/issues/4268 for more info",
214216
relative_path.display()
215217
))?;
216218
} else {
217219
self.config.shell().warn(format!(
218-
"Pattern matching for Cargo's include/exclude fields is changing and \
219-
file `{}` WILL NOT be included in a future Cargo version.\n\
220+
"Pattern matching for Cargo's include/exclude fields has changed and \
221+
file `{}` is NOT included anymore, but USED TO be included in a \
222+
previous Cargo version.\n\
220223
See https://github.com/rust-lang/cargo/issues/4268 for more info",
221224
relative_path.display()
222225
))?;
223226
}
224227
} else if no_include_option {
225228
self.config.shell().warn(format!(
226-
"Pattern matching for Cargo's include/exclude fields is changing and \
227-
file `{}` WILL NOT be excluded in a future Cargo version.\n\
229+
"Pattern matching for Cargo's include/exclude fields has changed and \
230+
file `{}` is NOW NOT excluded, but USED TO be excluded in a \
231+
previous Cargo version.\n\
228232
See https://github.com/rust-lang/cargo/issues/4268 for more info",
229233
relative_path.display()
230234
))?;
231235
} else {
232236
self.config.shell().warn(format!(
233-
"Pattern matching for Cargo's include/exclude fields is changing and \
234-
file `{}` WILL be included in a future Cargo version.\n\
237+
"Pattern matching for Cargo's include/exclude fields has changed and \
238+
file `{}` is NOW included, but USED TO be NOT included in a \
239+
previous Cargo version.\n\
235240
See https://github.com/rust-lang/cargo/issues/4268 for more info",
236241
relative_path.display()
237242
))?;
238243
}
239244
}
240245

241-
// Update to ignore_should_package for Stage 2
242-
Ok(glob_should_package)
246+
Ok(ignore_should_package)
243247
};
244248

245249
// attempt git-prepopulate only if no `include` (rust-lang/cargo#4135)

tests/testsuite/package.rs

+7-15
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ fn exclude() {
316316
"*.txt",
317317
# file in root
318318
"file_root_1", # NO_CHANGE (ignored)
319-
"/file_root_2", # CHANGING (packaged -> ignored)
319+
"/file_root_2", # NO_CHANGE (ignored)
320320
"file_root_3/", # NO_CHANGE (packaged)
321321
"file_root_4/*", # NO_CHANGE (packaged)
322322
"file_root_5/**", # NO_CHANGE (packaged)
@@ -377,17 +377,17 @@ fn exclude() {
377377
"\
378378
[WARNING] manifest has no description[..]
379379
See http://doc.crates.io/manifest.html#package-metadata for more info.
380-
[WARNING] [..] file `dir_root_1/some_dir/file` WILL be excluded [..]
380+
[WARNING] [..] file `dir_root_1/some_dir/file` is NOW excluded [..]
381381
See [..]
382-
[WARNING] [..] file `dir_root_2/some_dir/file` WILL be excluded [..]
382+
[WARNING] [..] file `dir_root_2/some_dir/file` is NOW excluded [..]
383383
See [..]
384-
[WARNING] [..] file `dir_root_3/some_dir/file` WILL be excluded [..]
384+
[WARNING] [..] file `dir_root_3/some_dir/file` is NOW excluded [..]
385385
See [..]
386-
[WARNING] [..] file `some_dir/dir_deep_1/some_dir/file` WILL be excluded [..]
386+
[WARNING] [..] file `some_dir/dir_deep_1/some_dir/file` is NOW excluded [..]
387387
See [..]
388-
[WARNING] [..] file `some_dir/dir_deep_3/some_dir/file` WILL be excluded [..]
388+
[WARNING] [..] file `some_dir/dir_deep_3/some_dir/file` is NOW excluded [..]
389389
See [..]
390-
[WARNING] [..] file `some_dir/file_deep_1` WILL be excluded [..]
390+
[WARNING] [..] file `some_dir/file_deep_1` is NOW excluded [..]
391391
See [..]
392392
[PACKAGING] foo v0.0.1 ([..])
393393
[ARCHIVING] [..]
@@ -421,18 +421,10 @@ See [..]
421421
"\
422422
.cargo_vcs_info.json
423423
Cargo.toml
424-
dir_root_1/some_dir/file
425-
dir_root_2/some_dir/file
426-
dir_root_3/some_dir/file
427424
file_root_3
428425
file_root_4
429426
file_root_5
430-
some_dir/dir_deep_1/some_dir/file
431427
some_dir/dir_deep_2/some_dir/file
432-
some_dir/dir_deep_3/some_dir/file
433-
some_dir/dir_deep_4/some_dir/file
434-
some_dir/dir_deep_5/some_dir/file
435-
some_dir/file_deep_1
436428
some_dir/file_deep_2
437429
some_dir/file_deep_3
438430
some_dir/file_deep_4

0 commit comments

Comments
 (0)