From d3f7bb0ae5d09e5e25a694d63f1ff02f85849fa6 Mon Sep 17 00:00:00 2001 From: Jethro Beekman Date: Thu, 10 Jan 2019 12:08:13 +0530 Subject: [PATCH] Having a [patch] section when publishing is not an error --- src/cargo/ops/registry.rs | 4 --- src/doc/man/cargo-publish.adoc | 1 - tests/testsuite/publish.rs | 60 ++++++++++++++++++++++++++++++++-- 3 files changed, 57 insertions(+), 8 deletions(-) diff --git a/src/cargo/ops/registry.rs b/src/cargo/ops/registry.rs index 4447dc9699e..557a84039d8 100644 --- a/src/cargo/ops/registry.rs +++ b/src/cargo/ops/registry.rs @@ -60,10 +60,6 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> { } } - if !pkg.manifest().patch().is_empty() { - failure::bail!("published crates cannot contain [patch] sections"); - } - let (mut registry, reg_id) = registry( opts.config, opts.token.clone(), diff --git a/src/doc/man/cargo-publish.adoc b/src/doc/man/cargo-publish.adoc index ff9f782f47d..ae247f48641 100644 --- a/src/doc/man/cargo-publish.adoc +++ b/src/doc/man/cargo-publish.adoc @@ -19,7 +19,6 @@ registry. The default registry is https://crates.io. This performs the following steps: . Performs a few checks, including: - - No `[patch]` sections are allowed in the manifest. - Checks the `package.publish` key in the manifest for restrictions on which registries you are allowed to publish to. . Create a `.crate` file by following the steps in man:cargo-package[1]. diff --git a/tests/testsuite/publish.rs b/tests/testsuite/publish.rs index 66c51b9d152..11e9d23ba49 100644 --- a/tests/testsuite/publish.rs +++ b/tests/testsuite/publish.rs @@ -930,17 +930,71 @@ fn publish_with_patch() { bar = { path = "bar" } "#, ) - .file("src/main.rs", "extern crate bar; fn main() {}") + .file( + "src/main.rs", + "extern crate bar; + fn main() { + bar::newfunc(); + }", + ) .file("bar/Cargo.toml", &basic_manifest("bar", "1.0.0")) - .file("bar/src/lib.rs", "") + .file("bar/src/lib.rs", "pub fn newfunc() {}") .build(); // Check that it works with the patched crate. p.cargo("build").run(); + // Check that verify fails with patched crate which has new functionality. p.cargo("publish --index") .arg(registry_url().to_string()) + .with_stderr_contains("[..]newfunc[..]") .with_status(101) - .with_stderr_contains("[ERROR] published crates cannot contain [patch] sections") .run(); + + // Remove the usage of new functionality and try again. + p.change_file("src/main.rs", "extern crate bar; pub fn main() {}"); + + p.cargo("publish --index") + .arg(registry_url().to_string()) + .run(); + + // Note, use of `registry` in the deps here is an artifact that this + // publishes to a fake, local registry that is pretending to be crates.io. + // Normal publishes would set it to null. + publish::validate_upload( + r#" + { + "authors": [], + "badges": {}, + "categories": [], + "deps": [ + { + "default_features": true, + "features": [], + "kind": "normal", + "name": "bar", + "optional": false, + "registry": "https://github.com/rust-lang/crates.io-index", + "target": null, + "version_req": "^1.0" + } + ], + "description": "foo", + "documentation": null, + "features": {}, + "homepage": null, + "keywords": [], + "license": "MIT", + "license_file": null, + "links": null, + "name": "foo", + "readme": null, + "readme_file": null, + "repository": null, + "vers": "0.0.1" + } + "#, + "foo-0.0.1.crate", + &["Cargo.toml", "Cargo.toml.orig", "src/main.rs"], + ); }