Auto merge of #11270 - antonok-edm:report-packagesize, r=weihanglo

Report crate size on package and publish

### Motivation

Fixes #11251.

This adds a line like `Packaged 42 files, 727.0KiB (143.8KiB compressed)` to the output of `cargo package` and `cargo publish`. See the associated issue for more details.

### Test info

I've updated associated tests to account for the new line in the output, including the file count where relevant. I've also added a few additional tests specifically to address the uncompressed and compressed file sizes.

If you'd like to test this manually, simply run `cargo package` or `cargo publish` within a project of your choice. The new `Packaged` line will appear at the end of the stderr output, or directly before the `Uploaded` line, respectively.

### Review info

This PR touches many test files to account for the additional line of stderr output. For convenience, I've split the PR into 4 commits.
1. contains the actual implementation
2. updates existing tests unrelated to `cargo package` and `cargo publish`
3. updates existing tests related to `cargo package` and `cargo publish`, including file counts where relevant
4. adds new tests specifically for the file sizes, which are generally not covered by existing tests

### Additional information

The feature was discussed [on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/Report.20crate.20size.20when.20packaging) prior to implementation.

Potential future extensions to explore include:
- Report size per file when using `--verbose`
- Compare to the size of the previously uploaded version to warn if the increase is sufficiently large
- Consider designs that can draw more attention to the most important information
- Warn if large binary files are included ([#9058](https://github.com/rust-lang/cargo/issues/9058))
This commit is contained in:
bors 2022-10-29 00:27:56 +00:00
commit da204963d6
14 changed files with 441 additions and 13 deletions

View file

@ -174,6 +174,7 @@ fn substitute_macros(input: &str) -> String {
("[REMOVING]", " Removing"),
("[DOCTEST]", " Doc-tests"),
("[PACKAGING]", " Packaging"),
("[PACKAGED]", " Packaged"),
("[DOWNLOADING]", " Downloading"),
("[DOWNLOADED]", " Downloaded"),
("[UPLOADING]", " Uploading"),

View file

@ -14,7 +14,7 @@ use crate::core::{Package, PackageId, PackageSet, Resolve, SourceId};
use crate::sources::PathSource;
use crate::util::errors::CargoResult;
use crate::util::toml::TomlManifest;
use crate::util::{self, restricted_names, Config, FileLock};
use crate::util::{self, human_readable_bytes, restricted_names, Config, FileLock};
use crate::{drop_println, ops};
use anyhow::Context as _;
use cargo_util::paths;
@ -110,6 +110,8 @@ pub fn package_one(
let ar_files = build_ar_list(ws, pkg, src_files, vcs_info)?;
let filecount = ar_files.len();
if opts.list {
for ar_file in ar_files {
drop_println!(config, "{}", ar_file.rel_str);
@ -138,7 +140,7 @@ pub fn package_one(
.shell()
.status("Packaging", pkg.package_id().to_string())?;
dst.file().set_len(0)?;
tar(ws, pkg, ar_files, dst.file(), &filename)
let uncompressed_size = tar(ws, pkg, ar_files, dst.file(), &filename)
.with_context(|| "failed to prepare local package for uploading")?;
if opts.verify {
dst.seek(SeekFrom::Start(0))?;
@ -151,6 +153,22 @@ pub fn package_one(
fs::rename(&src_path, &dst_path)
.with_context(|| "failed to move temporary tarball into final location")?;
let dst_metadata = dst
.file()
.metadata()
.with_context(|| format!("could not learn metadata for: `{}`", dst_path.display()))?;
let compressed_size = dst_metadata.len();
let uncompressed = human_readable_bytes(uncompressed_size);
let compressed = human_readable_bytes(compressed_size);
let message = format!(
"{} files, {:.1}{} ({:.1}{} compressed)",
filecount, uncompressed.0, uncompressed.1, compressed.0, compressed.1,
);
// It doesn't really matter if this fails.
drop(config.shell().status("Packaged", message));
return Ok(Some(dst));
}
@ -567,13 +585,16 @@ fn check_repo_state(
}
}
/// Compresses and packages a list of [`ArchiveFile`]s and writes into the given file.
///
/// Returns the uncompressed size of the contents of the new archive file.
fn tar(
ws: &Workspace<'_>,
pkg: &Package,
ar_files: Vec<ArchiveFile>,
dst: &File,
filename: &str,
) -> CargoResult<()> {
) -> CargoResult<u64> {
// Prepare the encoder and its header.
let filename = Path::new(filename);
let encoder = GzBuilder::new()
@ -586,6 +607,8 @@ fn tar(
let base_name = format!("{}-{}", pkg.name(), pkg.version());
let base_path = Path::new(&base_name);
let mut uncompressed_size = 0;
for ar_file in ar_files {
let ArchiveFile {
rel_path,
@ -611,6 +634,7 @@ fn tar(
.with_context(|| {
format!("could not archive source file `{}`", disk_path.display())
})?;
uncompressed_size += metadata.len() as u64;
}
FileContents::Generated(generated_kind) => {
let contents = match generated_kind {
@ -626,13 +650,14 @@ fn tar(
header.set_cksum();
ar.append_data(&mut header, &ar_path, contents.as_bytes())
.with_context(|| format!("could not archive source file `{}`", rel_str))?;
uncompressed_size += contents.len() as u64;
}
}
}
let encoder = ar.into_inner()?;
encoder.finish()?;
Ok(())
Ok(uncompressed_size)
}
/// Generate warnings when packaging Cargo.lock, and the resolve have changed.

View file

@ -3,7 +3,7 @@
use crate::core::GitReference;
use crate::util::errors::CargoResult;
use crate::util::{network, Config, IntoUrl, MetricsCounter, Progress};
use crate::util::{human_readable_bytes, network, Config, IntoUrl, MetricsCounter, Progress};
use anyhow::{anyhow, Context as _};
use cargo_util::{paths, ProcessBuilder};
use curl::easy::List;
@ -755,13 +755,8 @@ pub fn with_fetch_options(
counter.add(stats.received_bytes(), now);
last_update = now;
}
fn format_bytes(bytes: f32) -> (&'static str, f32) {
static UNITS: [&str; 5] = ["", "Ki", "Mi", "Gi", "Ti"];
let i = (bytes.log2() / 10.0).min(4.0) as usize;
(UNITS[i], bytes / 1024_f32.powi(i as i32))
}
let (unit, rate) = format_bytes(counter.rate());
format!(", {:.2}{}B/s", rate, unit)
let (rate, unit) = human_readable_bytes(counter.rate() as u64);
format!(", {:.2}{}/s", rate, unit)
};
progress
.tick(stats.indexed_objects(), stats.total_objects(), &msg)

View file

@ -73,6 +73,15 @@ pub fn elapsed(duration: Duration) -> String {
}
}
/// Formats a number of bytes into a human readable SI-prefixed size.
/// Returns a tuple of `(quantity, units)`.
pub fn human_readable_bytes(bytes: u64) -> (f32, &'static str) {
static UNITS: [&str; 7] = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"];
let bytes = bytes as f32;
let i = ((bytes.log2() / 10.0) as usize).min(UNITS.len() - 1);
(bytes / 1024_f32.powi(i as i32), UNITS[i])
}
pub fn iter_join_onto<W, I, T>(mut w: W, iter: I, delim: &str) -> fmt::Result
where
W: fmt::Write,
@ -122,3 +131,37 @@ pub fn truncate_with_ellipsis(s: &str, max_width: usize) -> String {
}
prefix
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_human_readable_bytes() {
assert_eq!(human_readable_bytes(0), (0., "B"));
assert_eq!(human_readable_bytes(8), (8., "B"));
assert_eq!(human_readable_bytes(1000), (1000., "B"));
assert_eq!(human_readable_bytes(1024), (1., "KiB"));
assert_eq!(human_readable_bytes(1024 * 420 + 512), (420.5, "KiB"));
assert_eq!(human_readable_bytes(1024 * 1024), (1., "MiB"));
assert_eq!(
human_readable_bytes(1024 * 1024 + 1024 * 256),
(1.25, "MiB")
);
assert_eq!(human_readable_bytes(1024 * 1024 * 1024), (1., "GiB"));
assert_eq!(
human_readable_bytes((1024. * 1024. * 1024. * 3.1415) as u64),
(3.1415, "GiB")
);
assert_eq!(human_readable_bytes(1024 * 1024 * 1024 * 1024), (1., "TiB"));
assert_eq!(
human_readable_bytes(1024 * 1024 * 1024 * 1024 * 1024),
(1., "PiB")
);
assert_eq!(
human_readable_bytes(1024 * 1024 * 1024 * 1024 * 1024 * 1024),
(1., "EiB")
);
assert_eq!(human_readable_bytes(u64::MAX), (16., "EiB"));
}
}

View file

@ -1919,6 +1919,7 @@ fn publish_artifact_dep() {
"\
[UPDATING] [..]
[PACKAGING] foo v0.1.0 [..]
[PACKAGED] [..]
[UPLOADING] foo v0.1.0 [..]
[UPDATING] [..]
",

View file

@ -134,6 +134,7 @@ Only one of these values may be set, remove one or the other to proceed.
"\
[UPDATING] [..]
[PACKAGING] foo v0.1.0 [..]
[PACKAGED] [..]
[UPLOADING] foo v0.1.0 [..]
[UPDATING] [..]
",
@ -208,6 +209,7 @@ fn publish() {
"\
[UPDATING] [..]
[PACKAGING] foo v0.1.0 [..]
[PACKAGED] [..]
[UPLOADING] foo v0.1.0 [..]
[UPDATING] [..]
",

View file

@ -46,6 +46,7 @@ fn simple_cross_package() {
[VERIFYING] foo v0.0.0 ([CWD])
[COMPILING] foo v0.0.0 ([CWD]/target/package/foo-0.0.0)
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
[PACKAGED] 4 files, [..] ([..] compressed)
",
)
.run();
@ -109,6 +110,7 @@ fn publish_with_target() {
[VERIFYING] foo v0.0.0 ([CWD])
[COMPILING] foo v0.0.0 ([CWD]/target/package/foo-0.0.0)
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
[PACKAGED] [..]
[UPLOADING] foo v0.0.0 ([CWD])
[UPDATING] crates.io index
",

View file

@ -902,6 +902,7 @@ fn publish_no_implicit() {
"\
[UPDATING] [..]
[PACKAGING] foo v0.1.0 [..]
[PACKAGED] [..]
[UPLOADING] foo v0.1.0 [..]
[UPDATING] [..]
",
@ -1029,6 +1030,7 @@ fn publish() {
[VERIFYING] foo v0.1.0 [..]
[COMPILING] foo v0.1.0 [..]
[FINISHED] [..]
[PACKAGED] [..]
[UPLOADING] foo v0.1.0 [..]
[UPDATING] [..]
",

View file

@ -39,6 +39,7 @@ See [..]
[VERIFYING] foo v0.0.1 ([CWD])
[COMPILING] foo v0.0.1 ([CWD][..])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
[PACKAGED] 4 files, [..] ([..] compressed)
",
)
.run();
@ -77,6 +78,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
[VERIFYING] foo v0.0.1 ([CWD])
[COMPILING] foo v0.0.1 ([CWD][..])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
[PACKAGED] [..] files, [..] ([..] compressed)
",
)
.run();
@ -103,6 +105,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
[VERIFYING] foo v0.0.1 ([CWD])
[COMPILING] foo v0.0.1 ([CWD][..])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
[PACKAGED] [..] files, [..] ([..] compressed)
",
)
.run();
@ -129,6 +132,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
[VERIFYING] foo v0.0.1 ([CWD])
[COMPILING] foo v0.0.1 ([CWD][..])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
[PACKAGED] [..] files, [..] ([..] compressed)
",
)
.run();
@ -158,6 +162,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
[ARCHIVING] Cargo.toml
[ARCHIVING] Cargo.toml.orig
[ARCHIVING] src/main.rs
[PACKAGED] 5 files, [..] ([..] compressed)
",
)
.run();
@ -198,6 +203,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
[ARCHIVING] Cargo.toml
[ARCHIVING] Cargo.toml.orig
[ARCHIVING] src/lib.rs
[PACKAGED] 4 files, [..] ([..] compressed)
",
)
.run();
@ -239,6 +245,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
[VERIFYING] foo v0.0.1 ([CWD])
[COMPILING] foo v0.0.1 ([CWD][..])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
[PACKAGED] [..] files, [..] ([..] compressed)
",
)
.run();
@ -488,6 +495,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
[ARCHIVING] some_dir/file_deep_4
[ARCHIVING] some_dir/file_deep_5
[ARCHIVING] src/main.rs
[PACKAGED] 15 files, [..] ([..] compressed)
",
)
.run();
@ -555,6 +563,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
[ARCHIVING] Cargo.toml.orig
[ARCHIVING] foo.txt
[ARCHIVING] src/main.rs
[PACKAGED] 7 files, [..] ([..] compressed)
",
)
.run();
@ -708,6 +717,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
[VERIFYING] foo v0.0.1 ([CWD])
[COMPILING] foo v0.0.1 ([CWD][..])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
[PACKAGED] 4 files, [..] ([..] compressed)
",
)
.run();
@ -775,6 +785,7 @@ See [..]
[VERIFYING] foo v0.0.1 ([CWD])
[COMPILING] foo v0.0.1 ([CWD][..])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
[PACKAGED] 5 files, [..] ([..] compressed)
",
)
.run();
@ -1788,6 +1799,7 @@ fn invalid_license_file_path() {
Please update the license-file setting in the manifest at `[..]/foo/Cargo.toml`
This may become a hard error in the future.
[PACKAGING] foo v1.0.0 ([..]/foo)
[PACKAGED] [..] files, [..] ([..] compressed)
",
)
.run();
@ -1835,6 +1847,7 @@ subdir/LICENSE
[ARCHIVING] Cargo.toml.orig
[ARCHIVING] src/lib.rs
[ARCHIVING] subdir/LICENSE
[PACKAGED] 5 files, [..] ([..] compressed)
",
)
.run();
@ -1891,6 +1904,7 @@ src/lib.rs
[VERIFYING] foo v1.0.0 [..]
[COMPILING] foo v1.0.0 [..]
[FINISHED] [..]
[PACKAGED] 4 files, [..] ([..] compressed)
",
)
.run();
@ -1949,6 +1963,7 @@ src/lib.rs
[VERIFYING] foo v1.0.0 [..]
[COMPILING] foo v1.0.0 [..]
[FINISHED] [..]
[PACKAGED] 4 files, [..] ([..] compressed)
",
)
.run();
@ -1994,6 +2009,7 @@ fn package_restricted_windows() {
[PACKAGING] foo [..]
[VERIFYING] foo [..]
[COMPILING] foo [..]
[PACKAGED] [..] files, [..] ([..] compressed)
[FINISHED] [..]
",
)
@ -2367,12 +2383,14 @@ See [..]
[VERIFYING] bar v0.0.1 ([CWD]/bar)
[COMPILING] bar v0.0.1 ([CWD][..])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
[PACKAGED] [..] files, [..] ([..] compressed)
[WARNING] manifest has no documentation, [..]
See [..]
[PACKAGING] foo v0.0.1 ([CWD])
[VERIFYING] foo v0.0.1 ([CWD])
[COMPILING] foo v0.0.1 ([CWD][..])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
[PACKAGED] [..] files, [..] ([..] compressed)
",
)
.run();
@ -2451,3 +2469,296 @@ version = "0.1.0"
&[("Cargo.toml", &rewritten_toml)],
);
}
fn verify_packaged_status_line(
output: std::process::Output,
num_files: usize,
uncompressed_size: u64,
compressed_size: u64,
) {
use cargo::util::human_readable_bytes;
let stderr = String::from_utf8(output.stderr).unwrap();
let mut packaged_lines = stderr
.lines()
.filter(|line| line.trim().starts_with("Packaged"));
let packaged_line = packaged_lines
.next()
.expect("`Packaged` status line should appear in stderr");
assert!(
packaged_lines.next().is_none(),
"Only one `Packaged` status line should appear in stderr"
);
let size_info = packaged_line.trim().trim_start_matches("Packaged").trim();
let uncompressed = human_readable_bytes(uncompressed_size);
let compressed = human_readable_bytes(compressed_size);
let expected = format!(
"{} files, {:.1}{} ({:.1}{} compressed)",
num_files, uncompressed.0, uncompressed.1, compressed.0, compressed.1
);
assert_eq!(size_info, expected);
}
#[cargo_test]
fn basic_filesizes() {
let cargo_toml_orig_contents = r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
exclude = ["*.txt"]
license = "MIT"
description = "foo"
"#;
let main_rs_contents = r#"fn main() { println!("🦀"); }"#;
let cargo_toml_contents = format!(
r#"{}
[package]
name = "foo"
version = "0.0.1"
authors = []
exclude = ["*.txt"]
description = "foo"
license = "MIT"
"#,
cargo::core::package::MANIFEST_PREAMBLE
);
let cargo_lock_contents = r#"# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "foo"
version = "0.0.1"
"#;
let p = project()
.file("Cargo.toml", cargo_toml_orig_contents)
.file("src/main.rs", main_rs_contents)
.file("src/bar.txt", "Ignored text file contents") // should be ignored when packaging
.build();
let uncompressed_size = (cargo_toml_orig_contents.len()
+ main_rs_contents.len()
+ cargo_toml_contents.len()
+ cargo_lock_contents.len()) as u64;
let output = p.cargo("package").exec_with_output().unwrap();
assert!(p.root().join("target/package/foo-0.0.1.crate").is_file());
p.cargo("package -l")
.with_stdout(
"\
Cargo.lock
Cargo.toml
Cargo.toml.orig
src/main.rs
",
)
.run();
p.cargo("package").with_stdout("").run();
let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap();
let compressed_size = f.metadata().unwrap().len();
verify_packaged_status_line(output, 4, uncompressed_size, compressed_size);
validate_crate_contents(
f,
"foo-0.0.1.crate",
&["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"],
&[
("Cargo.lock", cargo_lock_contents),
("Cargo.toml", &cargo_toml_contents),
("Cargo.toml.orig", cargo_toml_orig_contents),
("src/main.rs", main_rs_contents),
],
);
}
#[cargo_test]
fn larger_filesizes() {
let cargo_toml_orig_contents = r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
license = "MIT"
description = "foo"
"#;
let lots_of_crabs = std::iter::repeat("🦀").take(1337).collect::<String>();
let main_rs_contents = format!(r#"fn main() {{ println!("{}"); }}"#, lots_of_crabs);
let bar_txt_contents = "This file is relatively uncompressible, to increase the compressed
package size beyond 1KiB.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est
laborum.";
let cargo_toml_contents = format!(
r#"{}
[package]
name = "foo"
version = "0.0.1"
authors = []
description = "foo"
license = "MIT"
"#,
cargo::core::package::MANIFEST_PREAMBLE
);
let cargo_lock_contents = r#"# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "foo"
version = "0.0.1"
"#;
let p = project()
.file("Cargo.toml", cargo_toml_orig_contents)
.file("src/main.rs", &main_rs_contents)
.file("src/bar.txt", bar_txt_contents)
.build();
let uncompressed_size = (cargo_toml_orig_contents.len()
+ main_rs_contents.len()
+ cargo_toml_contents.len()
+ cargo_lock_contents.len()
+ bar_txt_contents.len()) as u64;
let output = p.cargo("package").exec_with_output().unwrap();
assert!(p.root().join("target/package/foo-0.0.1.crate").is_file());
p.cargo("package -l")
.with_stdout(
"\
Cargo.lock
Cargo.toml
Cargo.toml.orig
src/bar.txt
src/main.rs
",
)
.run();
p.cargo("package").with_stdout("").run();
let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap();
let compressed_size = f.metadata().unwrap().len();
verify_packaged_status_line(output, 5, uncompressed_size, compressed_size);
validate_crate_contents(
f,
"foo-0.0.1.crate",
&[
"Cargo.lock",
"Cargo.toml",
"Cargo.toml.orig",
"src/bar.txt",
"src/main.rs",
],
&[
("Cargo.lock", cargo_lock_contents),
("Cargo.toml", &cargo_toml_contents),
("Cargo.toml.orig", cargo_toml_orig_contents),
("src/bar.txt", bar_txt_contents),
("src/main.rs", &main_rs_contents),
],
);
}
#[cargo_test]
fn symlink_filesizes() {
if !symlink_supported() {
return;
}
let cargo_toml_orig_contents = r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
license = "MIT"
description = "foo"
"#;
let lots_of_crabs = std::iter::repeat("🦀").take(1337).collect::<String>();
let main_rs_contents = format!(r#"fn main() {{ println!("{}"); }}"#, lots_of_crabs);
let bar_txt_contents = "This file is relatively uncompressible, to increase the compressed
package size beyond 1KiB.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est
laborum.";
let cargo_toml_contents = format!(
r#"{}
[package]
name = "foo"
version = "0.0.1"
authors = []
description = "foo"
license = "MIT"
"#,
cargo::core::package::MANIFEST_PREAMBLE
);
let cargo_lock_contents = r#"# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "foo"
version = "0.0.1"
"#;
let p = project()
.file("Cargo.toml", cargo_toml_orig_contents)
.file("src/main.rs", &main_rs_contents)
.file("bla/bar.txt", bar_txt_contents)
.symlink("src/main.rs", "src/main.rs.bak")
.symlink_dir("bla", "foo")
.build();
let uncompressed_size = (cargo_toml_orig_contents.len()
+ main_rs_contents.len() * 2
+ cargo_toml_contents.len()
+ cargo_lock_contents.len()
+ bar_txt_contents.len() * 2) as u64;
let output = p.cargo("package").exec_with_output().unwrap();
assert!(p.root().join("target/package/foo-0.0.1.crate").is_file());
p.cargo("package -l")
.with_stdout(
"\
Cargo.lock
Cargo.toml
Cargo.toml.orig
bla/bar.txt
foo/bar.txt
src/main.rs
src/main.rs.bak
",
)
.run();
p.cargo("package").with_stdout("").run();
let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap();
let compressed_size = f.metadata().unwrap().len();
verify_packaged_status_line(output, 7, uncompressed_size, compressed_size);
validate_crate_contents(
f,
"foo-0.0.1.crate",
&[
"Cargo.lock",
"Cargo.toml",
"Cargo.toml.orig",
"bla/bar.txt",
"foo/bar.txt",
"src/main.rs",
"src/main.rs.bak",
],
&[
("Cargo.lock", cargo_lock_contents),
("Cargo.toml", &cargo_toml_contents),
("Cargo.toml.orig", cargo_toml_orig_contents),
("bla/bar.txt", bar_txt_contents),
("foo/bar.txt", bar_txt_contents),
("src/main.rs", &main_rs_contents),
("src/main.rs.bak", &main_rs_contents),
],
);
}

View file

@ -122,6 +122,7 @@ fn simple() {
[WARNING] manifest has no documentation, [..]
See [..]
[PACKAGING] foo v0.0.1 ([CWD])
[PACKAGED] [..] files, [..] ([..] compressed)
[UPLOADING] foo v0.0.1 ([CWD])
[UPDATING] [..]
",
@ -176,6 +177,7 @@ fn old_token_location() {
[WARNING] manifest has no documentation, [..]
See [..]
[PACKAGING] foo v0.0.1 ([CWD])
[PACKAGED] [..] files, [..] ([..] compressed)
[UPLOADING] foo v0.0.1 ([CWD])
[UPDATING] [..]
",
@ -217,6 +219,7 @@ fn simple_with_index() {
[..]
[..]
[..]
[..]
[UPLOADING] foo v0.0.1 ([CWD])
[UPDATING] [..]
",
@ -414,6 +417,7 @@ fn publish_clean() {
[VERIFYING] foo v0.0.1 ([CWD])
[..]
[..]
[..]
[UPLOADING] foo v0.0.1 ([CWD])
[UPDATING] [..]
",
@ -459,6 +463,7 @@ fn publish_in_sub_repo() {
[VERIFYING] foo v0.0.1 ([CWD])
[..]
[..]
[..]
[UPLOADING] foo v0.0.1 ([CWD])
[UPDATING] [..]
",
@ -504,6 +509,7 @@ fn publish_when_ignored() {
[VERIFYING] foo v0.0.1 ([CWD])
[..]
[..]
[..]
[UPLOADING] foo v0.0.1 ([CWD])
[UPDATING] [..]
",
@ -548,6 +554,7 @@ fn ignore_when_crate_ignored() {
[VERIFYING] foo v0.0.1 ([CWD])
[..]
[..]
[..]
[UPLOADING] foo v0.0.1 ([CWD])
[UPDATING] [..]
",
@ -622,6 +629,7 @@ See [..]
[VERIFYING] foo v0.0.1 ([CWD])
[COMPILING] foo v0.0.1 [..]
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
[PACKAGED] [..] files, [..] ([..] compressed)
[UPLOADING] foo v0.0.1 ([CWD])
[WARNING] aborting upload due to dry run
",
@ -739,6 +747,7 @@ fn publish_allowed_registry() {
[VERIFYING] foo v0.0.1 ([CWD])
[..]
[..]
[..]
[UPLOADING] foo v0.0.1 ([CWD])
[UPDATING] `alternative` index
",
@ -803,6 +812,7 @@ fn publish_implicitly_to_only_allowed_registry() {
[VERIFYING] foo v0.0.1 ([CWD])
[..]
[..]
[..]
[UPLOADING] foo v0.0.1 ([CWD])
[UPDATING] `alternative` index
",
@ -928,6 +938,7 @@ The registry `alternative` is not listed in the `package.publish` value in Cargo
[VERIFYING] foo v0.0.1 ([CWD])
[..]
[..]
[..]
[UPLOADING] foo v0.0.1 ([CWD])
[UPDATING] crates.io index
",
@ -975,6 +986,7 @@ fn publish_with_select_features() {
[VERIFYING] foo v0.0.1 ([CWD])
[..]
[..]
[..]
[UPLOADING] foo v0.0.1 ([CWD])
[UPDATING] crates.io index
",
@ -1022,6 +1034,7 @@ fn publish_with_all_features() {
[VERIFYING] foo v0.0.1 ([CWD])
[..]
[..]
[..]
[UPLOADING] foo v0.0.1 ([CWD])
[UPDATING] crates.io index
",
@ -1132,6 +1145,7 @@ fn publish_with_patch() {
[..]
[..]
[..]
[..]
[UPLOADING] foo v0.0.1 ([CWD])
[UPDATING] crates.io index
",
@ -1219,6 +1233,7 @@ fn publish_checks_for_token_before_verify() {
[VERIFYING] foo v0.0.1 ([CWD])
[..]
[..]
[..]
[UPLOADING] foo v0.0.1 [..]
[WARNING] aborting upload due to dry run
",
@ -1338,6 +1353,7 @@ fn publish_git_with_version() {
[..]
[..]
[..]
[..]
[UPLOADING] foo v0.1.0 ([CWD])
[UPDATING] crates.io index
",
@ -1466,6 +1482,7 @@ fn publish_dev_dep_no_version() {
"\
[UPDATING] [..]
[PACKAGING] foo v0.1.0 [..]
[PACKAGED] [..] files, [..] ([..] compressed)
[UPLOADING] foo v0.1.0 [..]
[UPDATING] crates.io index
",
@ -1550,6 +1567,7 @@ fn credentials_ambiguous_filename() {
[..]
[..]
[..]
[..]
[UPLOADING] foo v0.0.1 [..]
[UPDATING] crates.io index
",
@ -1653,6 +1671,7 @@ fn publish_with_missing_readme() {
"\
[UPDATING] [..]
[PACKAGING] foo v0.1.0 [..]
[PACKAGED] [..] files, [..] ([..] compressed)
[UPLOADING] foo v0.1.0 [..]
[ERROR] failed to read `readme` file for package `foo v0.1.0 ([ROOT]/foo)`
@ -1704,6 +1723,7 @@ fn api_error_json() {
"\
[UPDATING] [..]
[PACKAGING] foo v0.0.1 [..]
[PACKAGED] [..] files, [..] ([..] compressed)
[UPLOADING] foo v0.0.1 [..]
[ERROR] failed to publish to registry at http://127.0.0.1:[..]/
@ -1751,6 +1771,7 @@ fn api_error_200() {
"\
[UPDATING] [..]
[PACKAGING] foo v0.0.1 [..]
[PACKAGED] [..] files, [..] ([..] compressed)
[UPLOADING] foo v0.0.1 [..]
[ERROR] failed to publish to registry at http://127.0.0.1:[..]/
@ -1798,6 +1819,7 @@ fn api_error_code() {
"\
[UPDATING] [..]
[PACKAGING] foo v0.0.1 [..]
[PACKAGED] [..] files, [..] ([..] compressed)
[UPLOADING] foo v0.0.1 [..]
[ERROR] failed to publish to registry at http://127.0.0.1:[..]/
@ -1853,6 +1875,7 @@ fn api_curl_error() {
"\
[UPDATING] [..]
[PACKAGING] foo v0.0.1 [..]
[PACKAGED] [..] files, [..] ([..] compressed)
[UPLOADING] foo v0.0.1 [..]
[ERROR] failed to publish to registry at http://127.0.0.1:[..]/
@ -1900,6 +1923,7 @@ fn api_other_error() {
"\
[UPDATING] [..]
[PACKAGING] foo v0.0.1 [..]
[PACKAGED] [..] files, [..] ([..] compressed)
[UPLOADING] foo v0.0.1 [..]
[ERROR] failed to publish to registry at http://127.0.0.1:[..]/
@ -1959,6 +1983,7 @@ fn in_package_workspace() {
[WARNING] manifest has no documentation, homepage or repository.
See [..]
[PACKAGING] li v0.0.1 ([CWD]/li)
[PACKAGED] [..] files, [..] ([..] compressed)
[UPLOADING] li v0.0.1 ([CWD]/li)
[UPDATING] crates.io index
",
@ -2065,6 +2090,7 @@ fn in_package_workspace_with_members_with_features_old() {
[WARNING] manifest has no documentation, homepage or repository.
See [..]
[PACKAGING] li v0.0.1 ([CWD]/li)
[PACKAGED] [..] files, [..] ([..] compressed)
[UPLOADING] li v0.0.1 ([CWD]/li)
[UPDATING] crates.io index
",
@ -2156,6 +2182,7 @@ fn in_virtual_workspace_with_p() {
[WARNING] manifest has no documentation, homepage or repository.
See [..]
[PACKAGING] li v0.0.1 ([CWD]/li)
[PACKAGED] [..] files, [..] ([..] compressed)
[UPLOADING] li v0.0.1 ([CWD]/li)
[UPDATING] crates.io index
",
@ -2342,6 +2369,7 @@ fn http_api_not_noop() {
[VERIFYING] foo v0.0.1 ([CWD])
[..]
[..]
[..]
[UPLOADING] foo v0.0.1 ([CWD])
[UPDATING] [..]
",
@ -2423,6 +2451,7 @@ fn wait_for_publish() {
[WARNING] manifest has no documentation, [..]
See [..]
[PACKAGING] delay v0.0.1 ([CWD])
[PACKAGED] [..] files, [..] ([..] compressed)
[UPLOADING] delay v0.0.1 ([CWD])
[UPDATING] crates.io index
[WAITING] on `delay` to propagate to crates.io index (ctrl-c to wait asynchronously)
@ -2513,6 +2542,7 @@ fn wait_for_publish_underscore() {
[WARNING] manifest has no documentation, [..]
See [..]
[PACKAGING] delay_with_underscore v0.0.1 ([CWD])
[PACKAGED] [..] files, [..] ([..] compressed)
[UPLOADING] delay_with_underscore v0.0.1 ([CWD])
[UPDATING] crates.io index
[WAITING] on `delay_with_underscore` to propagate to crates.io index (ctrl-c to wait asynchronously)
@ -2583,6 +2613,7 @@ fn skip_wait_for_publish() {
[WARNING] manifest has no documentation, [..]
See [..]
[PACKAGING] foo v0.0.1 ([CWD])
[PACKAGED] [..] files, [..] ([..] compressed)
[UPLOADING] foo v0.0.1 ([CWD])
",
)

View file

@ -77,6 +77,7 @@ fn package_lockfile() {
[VERIFYING] foo v0.0.1 ([CWD])
[COMPILING] foo v0.0.1 ([CWD][..])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
[PACKAGED] [..] files, [..] ([..] compressed)
",
)
.run();
@ -135,6 +136,7 @@ src/main.rs
[COMPILING] foo v0.0.1 ([..])
[RUNNING] `rustc --crate-name foo src/main.rs [..]
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
[PACKAGED] 5 files, [..] ([..] compressed)
",
)
.run();
@ -232,6 +234,7 @@ fn note_resolve_changes() {
[UPDATING] `[..]` index
[NOTE] package `multi v0.1.0` added to the packaged Cargo.lock file, was originally sourced from `[..]/foo/multi`
[NOTE] package `patched v1.0.0` added to the packaged Cargo.lock file, was originally sourced from `[..]/foo/patched`
[PACKAGED] [..] files, [..] ([..] compressed)
",
)
.run();
@ -251,7 +254,12 @@ fn outdated_lock_version_change_does_not_warn() {
p.change_file("Cargo.toml", &pl_manifest("foo", "0.2.0", ""));
p.cargo("package --no-verify")
.with_stderr("[PACKAGING] foo v0.2.0 ([..])")
.with_stderr(
"\
[PACKAGING] foo v0.2.0 ([..])
[PACKAGED] [..] files, [..] ([..] compressed)
",
)
.run();
}
@ -301,6 +309,7 @@ fn no_warn_workspace_extras() {
"\
[PACKAGING] a v0.1.0 ([..])
[UPDATING] `[..]` index
[PACKAGED] [..] files, [..] ([..] compressed)
",
)
.run();
@ -334,6 +343,7 @@ fn warn_package_with_yanked() {
[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
[PACKAGED] [..] files, [..] ([..] compressed)
",
)
.run();
@ -450,6 +460,7 @@ src/main.rs
[COMPILING] foo v0.0.1 ([..])
[RUNNING] `rustc --crate-name foo src/main.rs [..]
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
[PACKAGED] 5 files, [..] ([..] compressed)
",
)
.run();
@ -476,6 +487,7 @@ fn ignore_lockfile_inner() {
[ARCHIVING] Cargo.toml
[ARCHIVING] Cargo.toml.orig
[ARCHIVING] src/main.rs
[PACKAGED] 6 files, [..] ([..] compressed)
",
)
.run();

View file

@ -500,6 +500,7 @@ Caused by:
[COMPILING] notyet v0.0.1
[COMPILING] foo v0.0.1 ([CWD][..])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
[PACKAGED] [..]
",
)
.run();

View file

@ -218,6 +218,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
[COMPILING] bar v1.0.0
[COMPILING] foo v0.0.1 ([..]foo-0.0.1)
[FINISHED] dev [..]
[PACKAGED] [..]
[UPLOADING] foo v0.0.1 ([..])
[UPDATING] crates.io index
",

View file

@ -568,6 +568,7 @@ fn publish() {
[VERIFYING] foo v0.1.0 [..]
[COMPILING] foo v0.1.0 [..]
[FINISHED] [..]
[PACKAGED] [..]
[UPLOADING] foo v0.1.0 [..]
[UPDATING] [..]
",