Skip to content

Commit 29b000f

Browse files
committed
Auto merge of #6925 - ehuss:package-include-manifest, r=alexcrichton
Always include `Cargo.toml` when packaging. Since `Cargo.toml` is required, might as well include it automatically rather than force everyone to include it explicitly. If it is not listed in `include`, there was a somewhat confusing error message when packaging. Closes #6830 Closes #4660
2 parents 4034d1d + 49e37f8 commit 29b000f

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

src/cargo/sources/path.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff 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).

src/doc/src/reference/manifest.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ include = ["src/**/*", "Cargo.toml"]
145145

146146
The 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

tests/testsuite/package.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,3 +1142,23 @@ fn package_no_default_features() {
11421142
.with_status(101)
11431143
.run();
11441144
}
1145+
1146+
#[test]
1147+
fn include_cargo_toml_implicit() {
1148+
let p = project()
1149+
.file(
1150+
"Cargo.toml",
1151+
r#"
1152+
[package]
1153+
name = "foo"
1154+
version = "0.1.0"
1155+
include = ["src/lib.rs"]
1156+
"#,
1157+
)
1158+
.file("src/lib.rs", "")
1159+
.build();
1160+
1161+
p.cargo("package --list")
1162+
.with_stdout("Cargo.toml\nsrc/lib.rs\n")
1163+
.run();
1164+
}

0 commit comments

Comments
 (0)