@@ -3,7 +3,6 @@ use std::fs;
3
3
use std:: path:: { Path , PathBuf } ;
4
4
5
5
use filetime:: FileTime ;
6
- use glob:: Pattern ;
7
6
use ignore:: gitignore:: GitignoreBuilder ;
8
7
use ignore:: Match ;
9
8
use log:: { trace, warn} ;
@@ -93,81 +92,10 @@ impl<'cfg> PathSource<'cfg> {
93
92
/// The basic assumption of this method is that all files in the directory
94
93
/// are relevant for building this package, but it also contains logic to
95
94
/// 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.
112
95
pub fn list_files ( & self , pkg : & Package ) -> CargoResult < Vec < PathBuf > > {
113
96
let root = pkg. root ( ) ;
114
97
let no_include_option = pkg. manifest ( ) . include ( ) . is_empty ( ) ;
115
98
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
-
171
99
let mut exclude_builder = GitignoreBuilder :: new ( root) ;
172
100
for rule in pkg. manifest ( ) . exclude ( ) {
173
101
exclude_builder. add_line ( None , rule) ?;
@@ -201,8 +129,6 @@ impl<'cfg> PathSource<'cfg> {
201
129
}
202
130
} ;
203
131
204
- // Matching to paths.
205
-
206
132
let mut filter = |path : & Path | -> CargoResult < bool > {
207
133
let relative_path = path. strip_prefix ( root) ?;
208
134
@@ -213,48 +139,7 @@ impl<'cfg> PathSource<'cfg> {
213
139
return Ok ( true ) ;
214
140
}
215
141
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)
258
143
} ;
259
144
260
145
// Attempt Git-prepopulate only if no `include` (see rust-lang/cargo#4135).
0 commit comments