Skip to content

Commit

Permalink
Auto merge of #2321 - JanLikar:private-crate, r=alexcrichton
Browse files Browse the repository at this point in the history
I Accidentally closed #2218, this is the new PR.

[Fix #2202]
  • Loading branch information
bors committed Jan 26, 2016
2 parents fdc200a + d28f8bb commit 6ffd134
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct Manifest {
include: Vec<String>,
metadata: ManifestMetadata,
profiles: Profiles,
publish: bool
}

/// General metadata about a package which is just blindly uploaded to the
Expand Down Expand Up @@ -163,7 +164,8 @@ impl Manifest {
include: Vec<String>,
links: Option<String>,
metadata: ManifestMetadata,
profiles: Profiles) -> Manifest {
profiles: Profiles,
publish: bool) -> Manifest {
Manifest {
summary: summary,
targets: targets,
Expand All @@ -173,6 +175,7 @@ impl Manifest {
links: links,
metadata: metadata,
profiles: profiles,
publish: publish,
}
}

Expand All @@ -187,6 +190,7 @@ impl Manifest {
pub fn version(&self) -> &Version { self.package_id().version() }
pub fn warnings(&self) -> &[String] { &self.warnings }
pub fn profiles(&self) -> &Profiles { &self.profiles }
pub fn publish(&self) -> bool { self.publish }
pub fn links(&self) -> Option<&str> {
self.links.as_ref().map(|s| &s[..])
}
Expand Down
1 change: 1 addition & 0 deletions src/cargo/core/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ impl Package {
pub fn summary(&self) -> &Summary { self.manifest.summary() }
pub fn targets(&self) -> &[Target] { self.manifest().targets() }
pub fn version(&self) -> &Version { self.package_id().version() }
pub fn publish(&self) -> bool { self.manifest.publish() }

pub fn has_custom_build(&self) -> bool {
self.targets().iter().any(|t| t.is_custom_build())
Expand Down
5 changes: 5 additions & 0 deletions src/cargo/ops/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ pub fn publish(manifest_path: &Path,
verify: bool) -> CargoResult<()> {
let pkg = try!(Package::for_path(&manifest_path, config));

if !pkg.publish() {
bail!("some crates cannot be published.\n\
`{}` is marked as unpublishable", pkg.name());
}

let (mut registry, reg_id) = try!(registry(config, token, index));
try!(verify_dependencies(&pkg, &reg_id));

Expand Down
5 changes: 4 additions & 1 deletion src/cargo/util/toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ pub struct TomlProject {
links: Option<String>,
exclude: Option<Vec<String>>,
include: Option<Vec<String>>,
publish: Option<bool>,

// package metadata
description: Option<String>,
Expand Down Expand Up @@ -562,13 +563,15 @@ impl TomlManifest {
keywords: project.keywords.clone().unwrap_or(Vec::new()),
};
let profiles = build_profiles(&self.profile);
let publish = project.publish.unwrap_or(true);
let mut manifest = Manifest::new(summary,
targets,
exclude,
include,
project.links.clone(),
metadata,
profiles);
profiles,
publish);
if project.license_file.is_some() && project.license.is_some() {
manifest.add_warning(format!("warning: only one of `license` or \
`license-file` is necessary"));
Expand Down
12 changes: 12 additions & 0 deletions src/doc/manifest.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ necessary source files may not be included.

[globs]: http://doc.rust-lang.org/glob/glob/struct.Pattern.html


## The `publish` Field (optional)

The `publish` field can be used to prevent a package from being
published to a repository by mistake.

```toml
[package]
# ...
publish = false
```

## Package metadata

There are a number of optional metadata fields also accepted under the
Expand Down
20 changes: 20 additions & 0 deletions tests/test_cargo_publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,23 @@ all path dependencies must have a version specified when publishing.
dependency `bar` does not specify a version
"));
});

test!(unpublishable_crate {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
license = "MIT"
description = "foo"
publish = false
"#)
.file("src/main.rs", "fn main() {}");

assert_that(p.cargo_process("publish"),
execs().with_status(101).with_stderr("\
some crates cannot be published.
`foo` is marked as unpublishable
"));
});

0 comments on commit 6ffd134

Please sign in to comment.