mirror of
https://github.com/rust-lang/cargo
synced 2024-10-14 03:32:39 +00:00
f2fc5ca86d
Originally, crates.io would block on publish requests until the publish was complete, giving `cargo publish` this behavior by extension. When crates.io switched to asynchronous publishing, this intermittently broke people's workflows when publishing multiple crates. I say interittent because it usually works until it doesn't and it is unclear why to the end user because it will be published by the time they check. In the end, callers tend to either put in timeouts (and pray), poll the server's API, or use `crates-index` crate to poll the index. This isn't sufficient because - For any new interested party, this is a pit of failure they'll fall into - crates-index has re-implemented index support incorrectly in the past, currently doesn't handle auth, doesn't support `git-cli`, etc. - None of these previous options work if we were to implement workspace-publish support (#1169) - The new sparse registry might increase the publish times, making the delay easier to hit manually - The new sparse registry goes through CDNs so checking the server's API might not be sufficient - Once the sparse registry is available, crates-index users will find out when the package is ready in git but it might not be ready through the sparse registry because of CDNs So now `cargo` will block until it sees the package in the index. - This is checking via the index instead of server APIs in case there are propagation delays. This has the side effect of being noisy because of all of the "Updating index" messages. - This is done unconditionally because cargo used to block and that didn't seem to be a problem, blocking by default is the less error prone case, and there doesn't seem to be enough justification for a "don't block" flag. The timeout was 5min but I dropped it to 1m. Unfortunately, I don't have data from `cargo-release` to know what a reasonable timeout is, so going ahead and dropping to 60s and assuming anything more is an outage. Fixes #9507
118 lines
2.9 KiB
Rust
118 lines
2.9 KiB
Rust
//! Tests for publishing using the `--target` flag.
|
|
|
|
use std::fs::File;
|
|
|
|
use cargo_test_support::{cross_compile, project, publish, registry};
|
|
|
|
#[cargo_test]
|
|
fn simple_cross_package() {
|
|
if cross_compile::disabled() {
|
|
return;
|
|
}
|
|
let p = project()
|
|
.file(
|
|
"Cargo.toml",
|
|
r#"
|
|
[package]
|
|
name = "foo"
|
|
version = "0.0.0"
|
|
authors = []
|
|
license = "MIT"
|
|
description = "foo"
|
|
repository = "bar"
|
|
"#,
|
|
)
|
|
.file(
|
|
"src/main.rs",
|
|
&format!(
|
|
r#"
|
|
use std::env;
|
|
fn main() {{
|
|
assert_eq!(env::consts::ARCH, "{}");
|
|
}}
|
|
"#,
|
|
cross_compile::alternate_arch()
|
|
),
|
|
)
|
|
.build();
|
|
|
|
let target = cross_compile::alternate();
|
|
|
|
p.cargo("package --target")
|
|
.arg(&target)
|
|
.with_stderr(
|
|
"\
|
|
[PACKAGING] foo v0.0.0 ([CWD])
|
|
[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 [..]
|
|
",
|
|
)
|
|
.run();
|
|
|
|
// Check that the tarball contains the files
|
|
let f = File::open(&p.root().join("target/package/foo-0.0.0.crate")).unwrap();
|
|
publish::validate_crate_contents(
|
|
f,
|
|
"foo-0.0.0.crate",
|
|
&["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"],
|
|
&[],
|
|
);
|
|
}
|
|
|
|
#[cargo_test]
|
|
fn publish_with_target() {
|
|
if cross_compile::disabled() {
|
|
return;
|
|
}
|
|
|
|
// `publish` generally requires a remote registry
|
|
let registry = registry::RegistryBuilder::new().http_api().build();
|
|
|
|
let p = project()
|
|
.file(
|
|
"Cargo.toml",
|
|
r#"
|
|
[package]
|
|
name = "foo"
|
|
version = "0.0.0"
|
|
authors = []
|
|
license = "MIT"
|
|
description = "foo"
|
|
repository = "bar"
|
|
"#,
|
|
)
|
|
.file(
|
|
"src/main.rs",
|
|
&format!(
|
|
r#"
|
|
use std::env;
|
|
fn main() {{
|
|
assert_eq!(env::consts::ARCH, "{}");
|
|
}}
|
|
"#,
|
|
cross_compile::alternate_arch()
|
|
),
|
|
)
|
|
.build();
|
|
|
|
let target = cross_compile::alternate();
|
|
|
|
p.cargo("publish")
|
|
.replace_crates_io(registry.index_url())
|
|
.arg("--target")
|
|
.arg(&target)
|
|
.with_stderr(
|
|
"\
|
|
[UPDATING] crates.io index
|
|
[PACKAGING] foo v0.0.0 ([CWD])
|
|
[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 [..]
|
|
[UPLOADING] foo v0.0.0 ([CWD])
|
|
[UPDATING] crates.io index
|
|
",
|
|
)
|
|
.run();
|
|
}
|