Allow packaging of crates with unstable features
authorSteven Fackler <sfackler@palantir.com>
Thu, 18 Jan 2018 18:35:40 +0000 (10:35 -0800)
committerSteven Fackler <sfackler@palantir.com>
Thu, 18 Jan 2018 18:35:40 +0000 (10:35 -0800)
We don't want them to land on crates.io, but it's fine to make a .crate
file.

Closes #4954

src/cargo/ops/cargo_package.rs
src/cargo/ops/registry.rs
tests/cargo-features.rs
tests/publish.rs

index b72793ae60d884ec7a20d567148c10bf89205905..bd968d08d45d4a9f48112e1ecfa4efcd65a24d06 100644 (file)
@@ -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);
index 85b3682a8ee516c7ec7d3bb91084077ec6dcf9d1..4f6acd39afcbc9ca4272bc7013ec79bdf34a70ec 100644 (file)
@@ -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),
index 0434b776e10333f41acf8b5649ee79ea1589e648..9d3246c4d8f23d15d732721db8fa6929d05cfe59 100644 (file)
@@ -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
 "));
 }
index 22f76c154a866c9cc1d5e410539b5fad53c51e79..334ade2271c165edb15a08a0b2d07bde42196fa2 100644 (file)
@@ -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