Skip to content

Commit

Permalink
auto merge of #974 : alexcrichton/cargo/issue-940, r=wycats
Browse files Browse the repository at this point in the history
This key will support projects with nonstandard licenses and the registry will
display the license as "nonstandard".

Closes #940
  • Loading branch information
bors committed Nov 25, 2014
2 parents f936f35 + 5acb5f5 commit 641c5c2
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub struct ManifestMetadata {
pub authors: Vec<String>,
pub keywords: Vec<String>,
pub license: Option<String>,
pub license_file: Option<String>,
pub description: Option<String>, // not markdown
pub readme: Option<String>, // file, not contents
pub homepage: Option<String>, // url
Expand Down
14 changes: 7 additions & 7 deletions src/cargo/ops/cargo_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,26 +75,26 @@ fn check_metadata(pkg: &Package, shell: &mut MultiShell) -> CargoResult<()> {
let mut missing = vec![];

macro_rules! lacking {
($($field: ident),*) => {{
($( $($field: ident)||* ),*) => {{
$(
if md.$field.as_ref().map_or(true, |s| s.is_empty()) {
missing.push(stringify!($field))
if $(md.$field.as_ref().map_or(true, |s| s.is_empty()))&&* {
$(missing.push(stringify!($field).replace("_", "-"));)*
}
)*
)*
}}
}
lacking!(description, license)
lacking!(description, license || license_file)

if !missing.is_empty() {
let mut things = missing.slice_to(missing.len() - 1).connect(", ");
// things will be empty if and only if length == 1 (i.e. the only case to have no `or`).
if !things.is_empty() {
things.push_str(" or ");
}
things.push_str(*missing.last().unwrap());
things.push_str(missing.last().unwrap().as_slice());

try!(shell.warn(
format!("Warning: manifest has no {things}. \
format!("warning: manifest has no {things}. \
See http://doc.crates.io/manifest.html#package-metadata for more info.",
things = things).as_slice()))
}
Expand Down
13 changes: 12 additions & 1 deletion src/cargo/ops/registry.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::HashMap;
use std::io::File;
use std::io::fs::PathExtensions;
use std::os;
use term::color::BLACK;

Expand Down Expand Up @@ -87,7 +88,7 @@ fn transmit(pkg: &Package, tarball: &Path, registry: &mut Registry)
let manifest = pkg.get_manifest();
let ManifestMetadata {
ref authors, ref description, ref homepage, ref documentation,
ref keywords, ref readme, ref repository, ref license,
ref keywords, ref readme, ref repository, ref license, ref license_file,
} = *manifest.get_metadata();
let readme = match *readme {
Some(ref readme) => {
Expand All @@ -98,6 +99,15 @@ fn transmit(pkg: &Package, tarball: &Path, registry: &mut Registry)
}
None => None,
};
match *license_file {
Some(ref file) => {
if !pkg.get_root().join(file).exists() {
return Err(human(format!("the license file `{}` does not exist",
file)))
}
}
None => {}
}
registry.publish(&NewCrate {
name: pkg.get_name().to_string(),
vers: pkg.get_version().to_string(),
Expand All @@ -111,6 +121,7 @@ fn transmit(pkg: &Package, tarball: &Path, registry: &mut Registry)
readme: readme,
repository: repository.clone(),
license: license.clone(),
license_file: license_file.clone(),
}, tarball).map_err(|e| {
human(e.to_string())
})
Expand Down
7 changes: 7 additions & 0 deletions src/cargo/util/toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ pub struct TomlProject {
readme: Option<String>,
keywords: Option<Vec<String>>,
license: Option<String>,
license_file: Option<String>,
repository: Option<String>,
}

Expand Down Expand Up @@ -518,6 +519,7 @@ impl TomlManifest {
readme: project.readme.clone(),
authors: project.authors.clone(),
license: project.license.clone(),
license_file: project.license_file.clone(),
repository: project.repository.clone(),
keywords: project.keywords.clone().unwrap_or(Vec::new()),
};
Expand All @@ -541,6 +543,11 @@ impl TomlManifest {
manifest.add_warning(format!(" For more information, see \
http://doc.crates.io/build-script.html"));
}
if project.license_file.is_some() && project.license.is_some() {
manifest.add_warning(format!("warning: only one of `license` or \
`license-file` is necessary"));
}

Ok((manifest, nested_paths))
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/doc/manifest.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,14 @@ keywords = ["...", "..."]

# This is a string description of the license for this package. Currently
# crates.io will validate the license provided against a whitelist of known
# license identifiers from http://spdx.org/licenses/. Multiple licenses can
# license identifiers from http://spdx.org/licenses/. Multiple licenses can
# be separated with a `/`
license = "..."

# If a project is using a nonstandard license, then this key may be specified in
# lieu of the above key and must point to a file relative to this manifest
# (similar to the readme key)
license-file = "..."
```

The [crates.io](https://crates.io) registry will render the description, display
Expand Down
1 change: 1 addition & 0 deletions src/registry/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub struct NewCrate {
pub readme: Option<String>,
pub keywords: Vec<String>,
pub license: Option<String>,
pub license_file: Option<String>,
pub repository: Option<String>,
}

Expand Down
10 changes: 6 additions & 4 deletions tests/test_cargo_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ test!(metadata_warning {
verifying = VERIFYING,
compiling = COMPILING,
dir = p.url()).as_slice())
.with_stderr("Warning: manifest has no description or license. See \
http://doc.crates.io/manifest.html#package-metadata for more info."));
.with_stderr("\
warning: manifest has no description, license or license-file. See \
http://doc.crates.io/manifest.html#package-metadata for more info."));

let p = project("one")
.file("Cargo.toml", r#"
Expand All @@ -104,8 +105,9 @@ test!(metadata_warning {
verifying = VERIFYING,
compiling = COMPILING,
dir = p.url()).as_slice())
.with_stderr("Warning: manifest has no description. See \
http://doc.crates.io/manifest.html#package-metadata for more info."));
.with_stderr("\
warning: manifest has no description. See \
http://doc.crates.io/manifest.html#package-metadata for more info."));

let p = project("both")
.file("Cargo.toml", format!(r#"
Expand Down
19 changes: 19 additions & 0 deletions tests/test_cargo_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,3 +480,22 @@ test!(login_with_no_cargo_dir {
.env("HOME", Some(home)),
execs().with_status(0));
})

test!(bad_license_file {
let p = project("all")
.file("Cargo.toml", r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
license-file = "foo"
description = "bar"
"#)
.file("src/main.rs", r#"
fn main() {}
"#);
assert_that(p.cargo_process("publish"),
execs().with_status(101)
.with_stderr("\
the license file `foo` does not exist"));
})

0 comments on commit 641c5c2

Please sign in to comment.