From: Steven Fackler Date: Thu, 18 Jan 2018 18:35:40 +0000 (-0800) Subject: Allow packaging of crates with unstable features X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~3^2~34^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=c85a43b07ef6b436ef223cea7abbfec8ae05a31b;p=cargo.git Allow packaging of crates with unstable features We don't want them to land on crates.io, but it's fine to make a .crate file. Closes #4954 --- diff --git a/src/cargo/ops/cargo_package.rs b/src/cargo/ops/cargo_package.rs index b72793ae6..bd968d08d 100644 --- a/src/cargo/ops/cargo_package.rs +++ b/src/cargo/ops/cargo_package.rs @@ -31,12 +31,6 @@ pub fn package(ws: &Workspace, let pkg = ws.current()?; let config = ws.config(); - // Allow packaging if a registry has been provided, or if there are no nightly - // features enabled. - if opts.registry.is_none() && !pkg.manifest().features().activated().is_empty() { - bail!("cannot package or publish crates which activate nightly-only \ - cargo features") - } let mut src = PathSource::new(pkg.root(), pkg.package_id().source_id(), config); diff --git a/src/cargo/ops/registry.rs b/src/cargo/ops/registry.rs index 85b3682a8..4f6acd39a 100644 --- a/src/cargo/ops/registry.rs +++ b/src/cargo/ops/registry.rs @@ -42,6 +42,12 @@ pub struct PublishOpts<'cfg> { pub fn publish(ws: &Workspace, opts: &PublishOpts) -> CargoResult<()> { let pkg = ws.current()?; + // Allow publishing if a registry has been provided, or if there are no nightly + // features enabled. + if opts.registry.is_none() && !pkg.manifest().features().activated().is_empty() { + bail!("cannot publish crates which activate nightly-only cargo features to crates.io") + } + if let &Some(ref allowed_registries) = pkg.publish() { if !match opts.registry { Some(ref registry) => allowed_registries.contains(registry), diff --git a/tests/cargo-features.rs b/tests/cargo-features.rs index 0434b776e..9d3246c4d 100644 --- a/tests/cargo-features.rs +++ b/tests/cargo-features.rs @@ -264,10 +264,10 @@ fn publish_rejected() { "#) .file("src/lib.rs", "") .build(); - assert_that(p.cargo("package") + assert_that(p.cargo("publish") .masquerade_as_nightly_cargo(), execs().with_status(101) .with_stderr("\ -error: cannot package or publish crates which activate nightly-only cargo features +error: cannot publish crates which activate nightly-only cargo features to crates.io ")); } diff --git a/tests/publish.rs b/tests/publish.rs index 22f76c154..334ade227 100644 --- a/tests/publish.rs +++ b/tests/publish.rs @@ -706,7 +706,8 @@ fn block_publish_no_registry() { .build(); assert_that(p.cargo("publish").masquerade_as_nightly_cargo() - .arg("--index").arg(publish::registry().to_string()), + .arg("--registry").arg("alternative") + .arg("-Zunstable-options"), execs().with_status(101).with_stderr("\ [ERROR] some crates cannot be published. `foo` is marked as unpublishable