Skip to content

Commit 8a74899

Browse files
committed
refactor(package): Consolidate creation of published package
1 parent 866d51d commit 8a74899

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

src/cargo/ops/cargo_package.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -448,15 +448,11 @@ fn error_custom_build_file_not_in_package(
448448
}
449449

450450
/// Construct `Cargo.lock` for the package to be published.
451-
fn build_lock(ws: &Workspace<'_>, orig_pkg: &Package) -> CargoResult<String> {
451+
fn build_lock(ws: &Workspace<'_>, publish_pkg: &Package) -> CargoResult<String> {
452452
let gctx = ws.gctx();
453453
let orig_resolve = ops::load_pkg_lockfile(ws)?;
454454

455-
let manifest = prepare_for_publish(orig_pkg, ws)?;
456-
let new_pkg = Package::new(manifest, orig_pkg.manifest_path());
457-
458-
// Regenerate Cargo.lock using the old one as a guide.
459-
let tmp_ws = Workspace::ephemeral(new_pkg, ws.gctx(), None, true)?;
455+
let tmp_ws = Workspace::ephemeral(publish_pkg.clone(), ws.gctx(), None, true)?;
460456
let mut tmp_reg = PackageRegistry::new(ws.gctx())?;
461457
let mut new_resolve = ops::resolve_with_previous(
462458
&mut tmp_reg,
@@ -687,6 +683,7 @@ fn tar(
687683

688684
let base_name = format!("{}-{}", pkg.name(), pkg.version());
689685
let base_path = Path::new(&base_name);
686+
let publish_pkg = prepare_for_publish(pkg, ws)?;
690687

691688
let mut uncompressed_size = 0;
692689
for ar_file in ar_files {
@@ -717,11 +714,8 @@ fn tar(
717714
}
718715
FileContents::Generated(generated_kind) => {
719716
let contents = match generated_kind {
720-
GeneratedFile::Manifest => {
721-
let manifest = prepare_for_publish(pkg, ws)?;
722-
manifest.to_resolved_contents()?
723-
}
724-
GeneratedFile::Lockfile => build_lock(ws, pkg)?,
717+
GeneratedFile::Manifest => publish_pkg.manifest().to_resolved_contents()?,
718+
GeneratedFile::Lockfile => build_lock(ws, &publish_pkg)?,
725719
GeneratedFile::VcsInfo(ref s) => serde_json::to_string_pretty(s)?,
726720
};
727721
header.set_entry_type(EntryType::file());

src/cargo/util/toml/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ fn warn_on_unused(unused: &BTreeSet<String>, warnings: &mut Vec<String>) {
218218
}
219219
}
220220

221-
pub fn prepare_for_publish(me: &Package, ws: &Workspace<'_>) -> CargoResult<Manifest> {
221+
pub fn prepare_for_publish(me: &Package, ws: &Workspace<'_>) -> CargoResult<Package> {
222222
let contents = me.manifest().contents();
223223
let document = me.manifest().document();
224224
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<Mani
236236
&mut warnings,
237237
&mut errors,
238238
)?;
239-
Ok(manifest)
239+
let new_pkg = Package::new(manifest, me.manifest_path());
240+
Ok(new_pkg)
240241
}
241242

242243
/// Prepares the manifest for publishing.

0 commit comments

Comments
 (0)