Skip to content

Commit

Permalink
Auto merge of #6925 - ehuss:package-include-manifest, r=alexcrichton
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed May 10, 2019
2 parents 4034d1d + 49e37f8 commit 29b000f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
17 changes: 10 additions & 7 deletions src/cargo/sources/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;

Expand Down Expand Up @@ -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).
Expand Down
3 changes: 2 additions & 1 deletion src/doc/src/reference/manifest.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 20 additions & 0 deletions tests/testsuite/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1142,3 +1142,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();
}

0 comments on commit 29b000f

Please sign in to comment.