Always include Cargo.toml when packaging.

This commit is contained in:
Eric Huss 2019-05-09 09:09:42 -07:00
parent 6fc356e556
commit 49e37f80fa
3 changed files with 32 additions and 8 deletions

View file

@ -199,6 +199,14 @@ impl<'cfg> PathSource<'cfg> {
let mut filter = |path: &Path| -> CargoResult<bool> {
let relative_path = path.strip_prefix(root)?;
let rel = relative_path.as_os_str();
if rel == "Cargo.lock" {
return Ok(pkg.include_lockfile());
} else if rel == "Cargo.toml" {
return Ok(true);
}
let glob_should_package = glob_should_package(relative_path);
let ignore_should_package = ignore_should_package(relative_path)?;
@ -240,13 +248,8 @@ impl<'cfg> PathSource<'cfg> {
}
}
let should_include = match path.file_name().and_then(|s| s.to_str()) {
Some("Cargo.lock") => pkg.include_lockfile(),
// Update to `ignore_should_package` for Stage 2.
_ => glob_should_package,
};
Ok(should_include)
// Update to `ignore_should_package` for Stage 2.
Ok(glob_should_package)
};
// Attempt Git-prepopulate only if no `include` (see rust-lang/cargo#4135).

View file

@ -145,7 +145,8 @@ include = ["src/**/*", "Cargo.toml"]
The options are mutually exclusive: setting `include` will override an
`exclude`. Note that `include` must be an exhaustive list of files as otherwise
necessary source files may not be included.
necessary source files may not be included. The package's `Cargo.toml` is
automatically included.
[globs]: https://docs.rs/glob/0.2.11/glob/struct.Pattern.html

View file

@ -1154,3 +1154,23 @@ fn package_no_default_features() {
.with_status(101)
.run();
}
#[test]
fn include_cargo_toml_implicit() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
include = ["src/lib.rs"]
"#,
)
.file("src/lib.rs", "")
.build();
p.cargo("package --list")
.with_stdout("Cargo.toml\nsrc/lib.rs\n")
.run();
}