From 49e37f80fa68bf11b1d7775df14263e6ae687ba6 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Thu, 9 May 2019 09:09:42 -0700 Subject: [PATCH] Always include `Cargo.toml` when packaging. --- src/cargo/sources/path.rs | 17 ++++++++++------- src/doc/src/reference/manifest.md | 3 ++- tests/testsuite/package.rs | 20 ++++++++++++++++++++ 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/cargo/sources/path.rs b/src/cargo/sources/path.rs index 700f02391ad..b2cd4e82483 100644 --- a/src/cargo/sources/path.rs +++ b/src/cargo/sources/path.rs @@ -199,6 +199,14 @@ impl<'cfg> PathSource<'cfg> { let mut filter = |path: &Path| -> CargoResult { 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). diff --git a/src/doc/src/reference/manifest.md b/src/doc/src/reference/manifest.md index 69bcb792add..521b1264c5f 100644 --- a/src/doc/src/reference/manifest.md +++ b/src/doc/src/reference/manifest.md @@ -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 diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs index 64a2e051b1a..b7fe1aa07d4 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -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(); +}