@@ -3,7 +3,6 @@ use std::fs;
33use std:: path:: { Path , PathBuf } ;
44
55use filetime:: FileTime ;
6- use glob:: Pattern ;
76use ignore:: gitignore:: GitignoreBuilder ;
87use ignore:: Match ;
98use 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).
0 commit comments