File tree Expand file tree Collapse file tree 3 files changed +32
-8
lines changed Expand file tree Collapse file tree 3 files changed +32
-8
lines changed Original file line number Diff line number Diff line change @@ -199,6 +199,14 @@ impl<'cfg> PathSource<'cfg> {
199199
200200 let mut filter = |path : & Path | -> CargoResult < bool > {
201201 let relative_path = path. strip_prefix ( root) ?;
202+
203+ let rel = relative_path. as_os_str ( ) ;
204+ if rel == "Cargo.lock" {
205+ return Ok ( pkg. include_lockfile ( ) ) ;
206+ } else if rel == "Cargo.toml" {
207+ return Ok ( true ) ;
208+ }
209+
202210 let glob_should_package = glob_should_package ( relative_path) ;
203211 let ignore_should_package = ignore_should_package ( relative_path) ?;
204212
@@ -240,13 +248,8 @@ impl<'cfg> PathSource<'cfg> {
240248 }
241249 }
242250
243- let should_include = match path. file_name ( ) . and_then ( |s| s. to_str ( ) ) {
244- Some ( "Cargo.lock" ) => pkg. include_lockfile ( ) ,
245- // Update to `ignore_should_package` for Stage 2.
246- _ => glob_should_package,
247- } ;
248-
249- Ok ( should_include)
251+ // Update to `ignore_should_package` for Stage 2.
252+ Ok ( glob_should_package)
250253 } ;
251254
252255 // Attempt Git-prepopulate only if no `include` (see rust-lang/cargo#4135).
Original file line number Diff line number Diff line change @@ -145,7 +145,8 @@ include = ["src/**/*", "Cargo.toml"]
145145
146146The options are mutually exclusive: setting ` include ` will override an
147147` exclude ` . Note that ` include ` must be an exhaustive list of files as otherwise
148- necessary source files may not be included.
148+ necessary source files may not be included. The package's ` Cargo.toml ` is
149+ automatically included.
149150
150151[ globs ] : https://docs.rs/glob/0.2.11/glob/struct.Pattern.html
151152
Original file line number Diff line number Diff line change @@ -1154,3 +1154,23 @@ fn package_no_default_features() {
11541154 . with_status ( 101 )
11551155 . run ( ) ;
11561156}
1157+
1158+ #[ test]
1159+ fn include_cargo_toml_implicit ( ) {
1160+ let p = project ( )
1161+ . file (
1162+ "Cargo.toml" ,
1163+ r#"
1164+ [package]
1165+ name = "foo"
1166+ version = "0.1.0"
1167+ include = ["src/lib.rs"]
1168+ "# ,
1169+ )
1170+ . file ( "src/lib.rs" , "" )
1171+ . build ( ) ;
1172+
1173+ p. cargo ( "package --list" )
1174+ . with_stdout ( "Cargo.toml\n src/lib.rs\n " )
1175+ . run ( ) ;
1176+ }
You can’t perform that action at this time.
0 commit comments