diff --git a/src/cargo/ops/cargo_package.rs b/src/cargo/ops/cargo_package.rs
index cda35913aa9..d16d98c9e6a 100644
--- a/src/cargo/ops/cargo_package.rs
+++ b/src/cargo/ops/cargo_package.rs
@@ -50,8 +50,17 @@ struct ArchiveFile {
enum FileContents {
/// Absolute path to the file on disk to add to the archive.
OnDisk(PathBuf),
- /// Contents of a file generated in memory.
- Generated(String),
+ /// Generates a file.
+ Generated(GeneratedFile),
+}
+
+enum GeneratedFile {
+ /// Generates `Cargo.toml` by rewriting the original.
+ Manifest,
+ /// Generates `Cargo.lock` in some cases (like if there is a binary).
+ Lockfile,
+ /// Adds a `.cargo-vcs_info.json` file if in a (clean) git repo.
+ VcsInfo(String),
}
pub fn package(ws: &Workspace<'_>, opts: &PackageOpts<'_>) -> CargoResult> {
@@ -71,8 +80,6 @@ pub fn package(ws: &Workspace<'_>, opts: &PackageOpts<'_>) -> CargoResult , opts: &PackageOpts<'_>) -> CargoResult continue,
@@ -179,18 +187,17 @@ fn build_ar_list(
}
}
if pkg.include_lockfile() {
- let new_lock = build_lock(ws)?;
result.push(ArchiveFile {
rel_path: PathBuf::from("Cargo.lock"),
rel_str: "Cargo.lock".to_string(),
- contents: FileContents::Generated(new_lock),
+ contents: FileContents::Generated(GeneratedFile::Lockfile),
});
}
if let Some(vcs_info) = vcs_info {
result.push(ArchiveFile {
rel_path: PathBuf::from(VCS_INFO_FILE),
rel_str: VCS_INFO_FILE.to_string(),
- contents: FileContents::Generated(vcs_info),
+ contents: FileContents::Generated(GeneratedFile::VcsInfo(vcs_info)),
});
}
if let Some(license_file) = &pkg.manifest().metadata().license_file {
@@ -530,7 +537,12 @@ fn tar(
format!("could not archive source file `{}`", disk_path.display())
})?;
}
- FileContents::Generated(contents) => {
+ FileContents::Generated(generated_kind) => {
+ let contents = match generated_kind {
+ GeneratedFile::Manifest => pkg.to_registry_toml(ws.config())?,
+ GeneratedFile::Lockfile => build_lock(ws)?,
+ GeneratedFile::VcsInfo(s) => s,
+ };
header.set_entry_type(EntryType::file());
header.set_mode(0o644);
header.set_mtime(
diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs
index 408b9b94b9d..c0be136a334 100644
--- a/tests/testsuite/package.rs
+++ b/tests/testsuite/package.rs
@@ -5,10 +5,10 @@ use std::io::prelude::*;
use std::path::Path;
use cargo_test_support::paths::CargoPathExt;
-use cargo_test_support::registry::Package;
+use cargo_test_support::publish::validate_crate_contents;
+use cargo_test_support::registry::{self, Package};
use cargo_test_support::{
- basic_manifest, cargo_process, git, path2url, paths, project, publish::validate_crate_contents,
- registry, symlink_supported, t,
+ basic_manifest, cargo_process, git, path2url, paths, project, symlink_supported, t,
};
#[cargo_test]
@@ -1697,3 +1697,52 @@ fn package_restricted_windows() {
)
.run();
}
+
+#[cargo_test]
+fn list_with_path_and_lock() {
+ // Allow --list even for something that isn't packageable.
+
+ // Init an empty registry because a versionless path dep will search for
+ // the package on crates.io.
+ registry::init();
+ let p = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.1.0"
+ license = "MIT"
+ description = "foo"
+ homepage = "foo"
+
+ [dependencies]
+ bar = {path="bar"}
+ "#,
+ )
+ .file("src/main.rs", "fn main() {}")
+ .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
+ .file("bar/src/lib.rs", "")
+ .build();
+
+ p.cargo("package --list")
+ .with_stdout(
+ "\
+Cargo.lock
+Cargo.toml
+Cargo.toml.orig
+src/main.rs
+",
+ )
+ .run();
+
+ p.cargo("package")
+ .with_status(101)
+ .with_stderr(
+ "\
+error: all path dependencies must have a version specified when packaging.
+dependency `bar` does not specify a version.
+",
+ )
+ .run();
+}
diff --git a/tests/testsuite/publish_lockfile.rs b/tests/testsuite/publish_lockfile.rs
index 7e0964f0d6a..341fe8ff087 100644
--- a/tests/testsuite/publish_lockfile.rs
+++ b/tests/testsuite/publish_lockfile.rs
@@ -297,8 +297,8 @@ fn no_warn_workspace_extras() {
.cwd("a")
.with_stderr(
"\
-[UPDATING] `[..]` index
[PACKAGING] a v0.1.0 ([..])
+[UPDATING] `[..]` index
",
)
.run();
@@ -328,10 +328,10 @@ fn warn_package_with_yanked() {
p.cargo("package --no-verify")
.with_stderr(
"\
+[PACKAGING] foo v0.0.1 ([..])
[UPDATING] `[..]` index
[WARNING] package `bar v0.1.0` in Cargo.lock is yanked in registry \
`crates.io`, consider updating to a version that is not yanked
-[PACKAGING] foo v0.0.1 ([..])
",
)
.run();
diff --git a/tests/testsuite/registry.rs b/tests/testsuite/registry.rs
index 297884544d2..f4722e9ac3f 100644
--- a/tests/testsuite/registry.rs
+++ b/tests/testsuite/registry.rs
@@ -361,13 +361,18 @@ fn package_with_path_deps() {
.file("notyet/src/lib.rs", "")
.build();
- p.cargo("package -v")
+ p.cargo("package")
.with_status(101)
.with_stderr_contains(
"\
-[ERROR] no matching package named `notyet` found
-location searched: registry [..]
-required by package `foo v0.0.1 ([..])`
+[PACKAGING] foo [..]
+[UPDATING] [..]
+[ERROR] failed to prepare local package for uploading
+
+Caused by:
+ no matching package named `notyet` found
+location searched: registry `https://github.com/rust-lang/crates.io-index`
+required by package `foo v0.0.1 [..]`
",
)
.run();
@@ -377,8 +382,8 @@ required by package `foo v0.0.1 ([..])`
p.cargo("package")
.with_stderr(
"\
-[UPDATING] `[..]` index
[PACKAGING] foo v0.0.1 ([CWD])
+[UPDATING] `[..]` index
[VERIFYING] foo v0.0.1 ([CWD])
[DOWNLOADING] crates ...
[DOWNLOADED] notyet v0.0.1 (registry `[ROOT][..]`)