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
37 changes: 12 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 @@ -163,11 +163,8 @@ fn create_package(
let filename = pkg.package_id().tarball_name();
let build_dir = ws.build_dir();
paths::create_dir_all_excluded_from_backups_atomic(build_dir.as_path_unlocked())?;
let dir = build_dir.join("package");
let mut dst = {
let tmp = format!(".{}", filename);
dir.open_rw_exclusive_create(&tmp, gctx, "package scratch space")?
};
let dir = build_dir.join("package").join("tmp-crate");
let dst = dir.open_rw_exclusive_create(&filename, gctx, "package scratch space")?;

// 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 @@ -179,14 +176,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 @@ -220,23 +213,17 @@ 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
paths::create_dir_all_excluded_from_backups_atomic(target_dir.as_path_unlocked())?;
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);
}
paths::create_dir_all_excluded_from_backups_atomic(target_dir.as_path_unlocked())?;
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);
}

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 @@ -524,8 +524,8 @@ 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/CACHEDIR.TAG
[ROOT]/foo/build-dir/package/tmp-crate/foo-0.0.1.crate

"#]]);

Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/build_dir_legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,8 @@ 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/CACHEDIR.TAG
[ROOT]/foo/build-dir/package/tmp-crate/foo-0.0.1.crate

"#]]);

Expand Down