diff --git a/src/cargo/ops/cargo_package.rs b/src/cargo/ops/cargo_package.rs index a8ae22db04a..99f1d4fdde7 100644 --- a/src/cargo/ops/cargo_package.rs +++ b/src/cargo/ops/cargo_package.rs @@ -448,15 +448,11 @@ fn error_custom_build_file_not_in_package( } /// Construct `Cargo.lock` for the package to be published. -fn build_lock(ws: &Workspace<'_>, orig_pkg: &Package) -> CargoResult { +fn build_lock(ws: &Workspace<'_>, publish_pkg: &Package) -> CargoResult { let gctx = ws.gctx(); let orig_resolve = ops::load_pkg_lockfile(ws)?; - let manifest = prepare_for_publish(orig_pkg, ws)?; - let new_pkg = Package::new(manifest, orig_pkg.manifest_path()); - - // Regenerate Cargo.lock using the old one as a guide. - let tmp_ws = Workspace::ephemeral(new_pkg, ws.gctx(), None, true)?; + let tmp_ws = Workspace::ephemeral(publish_pkg.clone(), ws.gctx(), None, true)?; let mut tmp_reg = PackageRegistry::new(ws.gctx())?; let mut new_resolve = ops::resolve_with_previous( &mut tmp_reg, @@ -687,6 +683,7 @@ fn tar( let base_name = format!("{}-{}", pkg.name(), pkg.version()); let base_path = Path::new(&base_name); + let publish_pkg = prepare_for_publish(pkg, ws)?; let mut uncompressed_size = 0; for ar_file in ar_files { @@ -717,11 +714,8 @@ fn tar( } FileContents::Generated(generated_kind) => { let contents = match generated_kind { - GeneratedFile::Manifest => { - let manifest = prepare_for_publish(pkg, ws)?; - manifest.to_resolved_contents()? - } - GeneratedFile::Lockfile => build_lock(ws, pkg)?, + GeneratedFile::Manifest => publish_pkg.manifest().to_resolved_contents()?, + GeneratedFile::Lockfile => build_lock(ws, &publish_pkg)?, GeneratedFile::VcsInfo(ref s) => serde_json::to_string_pretty(s)?, }; header.set_entry_type(EntryType::file()); diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 26084308e0c..523447d3263 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -218,7 +218,7 @@ fn warn_on_unused(unused: &BTreeSet, warnings: &mut Vec) { } } -pub fn prepare_for_publish(me: &Package, ws: &Workspace<'_>) -> CargoResult { +pub fn prepare_for_publish(me: &Package, ws: &Workspace<'_>) -> CargoResult { let contents = me.manifest().contents(); let document = me.manifest().document(); let toml_manifest = prepare_toml_for_publish(me.manifest().resolved_toml(), ws, me.root())?; @@ -236,7 +236,8 @@ pub fn prepare_for_publish(me: &Package, ws: &Workspace<'_>) -> CargoResult