Skip to content
Draft
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
36 changes: 11 additions & 25 deletions src/cargo/ops/cargo_package/mod.rs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ready for merge?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For myself, if we want an intermediate period, I feel like more than one release is probably needed.

Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,8 @@ fn create_package(
}

let filename = pkg.package_id().tarball_name();
let dir = ws.build_dir().join("package");
let mut dst = {
let tmp = format!(".{}", filename);
dir.open_rw_exclusive_create(&tmp, gctx, "package scratch space")?
};
let dir = ws.build_dir().join("package").join("tmp-crate");
let dst = dir.open_rw_exclusive_create(&filename, gctx, "package scratch space")?;
Comment on lines +163 to +164
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this will cause a behavior change, Ive marked this as a draft while we wait for #15910 to propagate to users so they can prepare.


// Package up and test a temporary tarball and only move it to the final
// location if it actually passes all our tests. Any previously existing
Expand All @@ -176,14 +173,10 @@ fn create_package(
let uncompressed_size = tar(ws, opts, pkg, local_reg, ar_files, dst.file(), &filename)
.context("failed to prepare local package for uploading")?;

dst.seek(SeekFrom::Start(0))?;
let dst_path = dst.parent().join(&filename);
dst.rename(&dst_path)?;

let dst_metadata = dst
.file()
.metadata()
.with_context(|| format!("could not learn metadata for: `{}`", dst_path.display()))?;
.with_context(|| format!("could not learn metadata for: `{}`", dst.path().display()))?;
let compressed_size = dst_metadata.len();

let uncompressed = HumanBytes(uncompressed_size);
Expand Down Expand Up @@ -217,22 +210,15 @@ pub fn package(ws: &Workspace<'_>, opts: &PackageOpts<'_>) -> CargoResult<Vec<Fi

let packaged = do_package(ws, opts, pkgs)?;

// Uplifting artifacts
let mut result = Vec::new();
let target_dir = ws.target_dir();
let build_dir = ws.build_dir();
if target_dir == build_dir {
result.extend(packaged.into_iter().map(|(_, _, src)| src));
} else {
// Uplifting artifacts
let artifact_dir = target_dir.join("package");
for (pkg, _, src) in packaged {
let filename = pkg.package_id().tarball_name();
let dst =
artifact_dir.open_rw_exclusive_create(filename, ws.gctx(), "uplifted package")?;
src.file().seek(SeekFrom::Start(0))?;
std::io::copy(&mut src.file(), &mut dst.file())?;
result.push(dst);
}
let artifact_dir = ws.target_dir().join("package");
for (pkg, _, src) in packaged {
let filename = pkg.package_id().tarball_name();
let dst = artifact_dir.open_rw_exclusive_create(filename, ws.gctx(), "uplifted package")?;
src.file().seek(SeekFrom::Start(0))?;
std::io::copy(&mut src.file(), &mut dst.file())?;
result.push(dst);
}

Ok(result)
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/build_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ fn cargo_package_should_build_in_build_dir_and_output_to_target_dir() {
[ROOT]/foo/build-dir/package/foo-0.0.1/Cargo.toml
[ROOT]/foo/build-dir/package/foo-0.0.1/Cargo.toml.orig
[ROOT]/foo/build-dir/package/foo-0.0.1/src/main.rs
[ROOT]/foo/build-dir/package/foo-0.0.1.crate
[ROOT]/foo/build-dir/package/tmp-crate/foo-0.0.1.crate

"#]]);

Expand Down