Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always include Cargo.toml when packaging. #6925

Merged
merged 1 commit into from
May 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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();
}