Skip to content

Commit 24d2850

Browse files
committed
Remove include/exclude glob warning.
1 parent a2f5431 commit 24d2850

File tree

2 files changed

+6
-154
lines changed

2 files changed

+6
-154
lines changed

src/cargo/sources/path.rs

Lines changed: 1 addition & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::fs;
33
use std::path::{Path, PathBuf};
44

55
use filetime::FileTime;
6-
use glob::Pattern;
76
use ignore::gitignore::GitignoreBuilder;
87
use ignore::Match;
98
use log::{trace, warn};
@@ -93,81 +92,10 @@ impl<'cfg> PathSource<'cfg> {
9392
/// The basic assumption of this method is that all files in the directory
9493
/// are relevant for building this package, but it also contains logic to
9594
/// use other methods like .gitignore to filter the list of files.
96-
///
97-
/// ## Pattern matching strategy
98-
///
99-
/// Migrating from a glob-like pattern matching (using `glob` crate) to a
100-
/// gitignore-like pattern matching (using `ignore` crate). The migration
101-
/// stages are:
102-
///
103-
/// 1) Only warn users about the future change iff their matching rules are
104-
/// affected.
105-
///
106-
/// 2) Switch to the new strategy and update documents. Still keep warning
107-
/// affected users. (CURRENT STAGE)
108-
///
109-
/// 3) Drop the old strategy and no more warnings.
110-
///
111-
/// See rust-lang/cargo#4268 for more info.
11295
pub fn list_files(&self, pkg: &Package) -> CargoResult<Vec<PathBuf>> {
11396
let root = pkg.root();
11497
let no_include_option = pkg.manifest().include().is_empty();
11598

116-
// Glob-like matching rules.
117-
118-
let glob_parse = |p: &String| {
119-
let pattern: &str = if p.starts_with('/') {
120-
&p[1..p.len()]
121-
} else {
122-
p
123-
};
124-
Pattern::new(pattern)
125-
};
126-
127-
let glob_exclude = pkg
128-
.manifest()
129-
.exclude()
130-
.iter()
131-
.map(|p| glob_parse(p))
132-
.collect::<Result<Vec<_>, _>>();
133-
134-
let glob_include = pkg
135-
.manifest()
136-
.include()
137-
.iter()
138-
.map(|p| glob_parse(p))
139-
.collect::<Result<Vec<_>, _>>();
140-
141-
// Don't warn if using a negate pattern, since those weren't ever
142-
// previously supported.
143-
let has_negate = pkg
144-
.manifest()
145-
.exclude()
146-
.iter()
147-
.chain(pkg.manifest().include().iter())
148-
.any(|p| p.starts_with('!'));
149-
// Don't warn about glob mismatch if it doesn't parse.
150-
let glob_is_valid = glob_exclude.is_ok() && glob_include.is_ok() && !has_negate;
151-
let glob_exclude = glob_exclude.unwrap_or_else(|_| Vec::new());
152-
let glob_include = glob_include.unwrap_or_else(|_| Vec::new());
153-
154-
let glob_should_package = |relative_path: &Path| -> bool {
155-
fn glob_match(patterns: &[Pattern], relative_path: &Path) -> bool {
156-
patterns
157-
.iter()
158-
.any(|pattern| pattern.matches_path(relative_path))
159-
}
160-
161-
// "Include" and "exclude" options are mutually exclusive.
162-
if no_include_option {
163-
!glob_match(&glob_exclude, relative_path)
164-
} else {
165-
glob_match(&glob_include, relative_path)
166-
}
167-
};
168-
169-
// Ignore-like matching rules.
170-
17199
let mut exclude_builder = GitignoreBuilder::new(root);
172100
for rule in pkg.manifest().exclude() {
173101
exclude_builder.add_line(None, rule)?;
@@ -201,8 +129,6 @@ impl<'cfg> PathSource<'cfg> {
201129
}
202130
};
203131

204-
// Matching to paths.
205-
206132
let mut filter = |path: &Path| -> CargoResult<bool> {
207133
let relative_path = path.strip_prefix(root)?;
208134

@@ -213,48 +139,7 @@ impl<'cfg> PathSource<'cfg> {
213139
return Ok(true);
214140
}
215141

216-
let glob_should_package = glob_should_package(relative_path);
217-
let ignore_should_package = ignore_should_package(relative_path)?;
218-
219-
if glob_is_valid && glob_should_package != ignore_should_package {
220-
if glob_should_package {
221-
if no_include_option {
222-
self.config.shell().warn(format!(
223-
"Pattern matching for Cargo's include/exclude fields has changed and \
224-
file `{}` is now excluded.\n\
225-
See <https://github.com/rust-lang/cargo/issues/4268> for more \
226-
information.",
227-
relative_path.display()
228-
))?;
229-
} else {
230-
self.config.shell().warn(format!(
231-
"Pattern matching for Cargo's include/exclude fields has changed and \
232-
file `{}` is no longer included.\n\
233-
See <https://github.com/rust-lang/cargo/issues/4268> for more \
234-
information.",
235-
relative_path.display()
236-
))?;
237-
}
238-
} else if no_include_option {
239-
self.config.shell().warn(format!(
240-
"Pattern matching for Cargo's include/exclude fields has changed and \
241-
file `{}` is NOT excluded.\n\
242-
See <https://github.com/rust-lang/cargo/issues/4268> for more \
243-
information.",
244-
relative_path.display()
245-
))?;
246-
} else {
247-
self.config.shell().warn(format!(
248-
"Pattern matching for Cargo's include/exclude fields has changed and \
249-
file `{}` is now included.\n\
250-
See <https://github.com/rust-lang/cargo/issues/4268> for more \
251-
information.",
252-
relative_path.display()
253-
))?;
254-
}
255-
}
256-
257-
Ok(ignore_should_package)
142+
ignore_should_package(relative_path)
258143
};
259144

260145
// Attempt Git-prepopulate only if no `include` (see rust-lang/cargo#4135).

tests/testsuite/package.rs

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -367,18 +367,6 @@ fn exclude() {
367367
"\
368368
[WARNING] manifest has no description[..]
369369
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
370-
[WARNING] [..] file `dir_root_1/some_dir/file` is now excluded.
371-
See [..]
372-
[WARNING] [..] file `dir_root_2/some_dir/file` is now excluded.
373-
See [..]
374-
[WARNING] [..] file `dir_root_3/some_dir/file` is now excluded.
375-
See [..]
376-
[WARNING] [..] file `some_dir/dir_deep_1/some_dir/file` is now excluded.
377-
See [..]
378-
[WARNING] [..] file `some_dir/dir_deep_3/some_dir/file` is now excluded.
379-
See [..]
380-
[WARNING] [..] file `some_dir/file_deep_1` is now excluded.
381-
See [..]
382370
[PACKAGING] foo v0.0.1 ([..])
383371
[ARCHIVING] Cargo.toml
384372
[ARCHIVING] file_root_3
@@ -1172,13 +1160,7 @@ fn include_cargo_toml_implicit() {
11721160
.run();
11731161
}
11741162

1175-
fn include_exclude_test(
1176-
include: &str,
1177-
exclude: &str,
1178-
files: &[&str],
1179-
expected: &str,
1180-
has_warnings: bool,
1181-
) {
1163+
fn include_exclude_test(include: &str, exclude: &str, files: &[&str], expected: &str) {
11821164
let mut pb = project().file(
11831165
"Cargo.toml",
11841166
&format!(
@@ -1203,13 +1185,10 @@ fn include_exclude_test(
12031185
}
12041186
let p = pb.build();
12051187

1206-
let mut e = p.cargo("package --list");
1207-
if has_warnings {
1208-
e.with_stderr_contains("[..]");
1209-
} else {
1210-
e.with_stderr("");
1211-
}
1212-
e.with_stdout(expected).run();
1188+
p.cargo("package --list")
1189+
.with_stderr("")
1190+
.with_stdout(expected)
1191+
.run();
12131192
p.root().rm_rf();
12141193
}
12151194

@@ -1230,7 +1209,6 @@ fn package_include_ignore_only() {
12301209
src/abc2.rs\n\
12311210
src/lib.rs\n\
12321211
",
1233-
false,
12341212
)
12351213
}
12361214

@@ -1246,7 +1224,6 @@ fn gitignore_patterns() {
12461224
foo\n\
12471225
x/foo/y\n\
12481226
",
1249-
true,
12501227
);
12511228

12521229
include_exclude_test(
@@ -1256,7 +1233,6 @@ fn gitignore_patterns() {
12561233
"Cargo.toml\n\
12571234
foo\n\
12581235
",
1259-
false,
12601236
);
12611237

12621238
include_exclude_test(
@@ -1269,7 +1245,6 @@ fn gitignore_patterns() {
12691245
foo\n\
12701246
src/lib.rs\n\
12711247
",
1272-
true,
12731248
);
12741249

12751250
include_exclude_test(
@@ -1292,7 +1267,6 @@ fn gitignore_patterns() {
12921267
other\n\
12931268
src/lib.rs\n\
12941269
",
1295-
false,
12961270
);
12971271

12981272
include_exclude_test(
@@ -1302,7 +1276,6 @@ fn gitignore_patterns() {
13021276
"Cargo.toml\n\
13031277
a/foo/bar\n\
13041278
",
1305-
false,
13061279
);
13071280

13081281
include_exclude_test(
@@ -1312,7 +1285,6 @@ fn gitignore_patterns() {
13121285
"Cargo.toml\n\
13131286
foo/x/y/z\n\
13141287
",
1315-
false,
13161288
);
13171289

13181290
include_exclude_test(
@@ -1324,7 +1296,6 @@ fn gitignore_patterns() {
13241296
a/x/b\n\
13251297
a/x/y/b\n\
13261298
",
1327-
false,
13281299
);
13291300
}
13301301

@@ -1338,7 +1309,6 @@ fn gitignore_negate() {
13381309
Cargo.toml\n\
13391310
src/lib.rs\n\
13401311
",
1341-
false,
13421312
);
13431313

13441314
// NOTE: This is unusual compared to git. Git treats `src/` as a
@@ -1352,7 +1322,6 @@ fn gitignore_negate() {
13521322
"Cargo.toml\n\
13531323
src/lib.rs\n\
13541324
",
1355-
false,
13561325
);
13571326

13581327
include_exclude_test(
@@ -1362,7 +1331,6 @@ fn gitignore_negate() {
13621331
"Cargo.toml\n\
13631332
src/lib.rs\n\
13641333
",
1365-
false,
13661334
);
13671335

13681336
include_exclude_test(
@@ -1372,6 +1340,5 @@ fn gitignore_negate() {
13721340
"Cargo.toml\n\
13731341
foo.rs\n\
13741342
",
1375-
false,
13761343
);
13771344
}

0 commit comments

Comments
 (0)