Skip to content

Commit

Permalink
Auto merge of #3110 - jsgf:topic-license-metadata, r=alexcrichton
Browse files Browse the repository at this point in the history
cargo: add license and license_file to cargo metadata output

Proposed fix for #3108
  • Loading branch information
bors authored Sep 26, 2016
2 parents dd91250 + 85d09d0 commit 4215ef8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/cargo/core/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ struct SerializedPackage<'a> {
name: &'a str,
version: &'a str,
id: &'a PackageId,
license: Option<&'a str>,
license_file: Option<&'a str>,
source: &'a SourceId,
dependencies: &'a [Dependency],
targets: &'a [Target],
Expand All @@ -40,11 +42,16 @@ impl Encodable for Package {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
let summary = self.manifest.summary();
let package_id = summary.package_id();
let manmeta = self.manifest.metadata();
let license = manmeta.license.as_ref().map(String::as_ref);
let license_file = manmeta.license_file.as_ref().map(String::as_ref);

SerializedPackage {
name: &package_id.name(),
version: &package_id.version().to_string(),
id: package_id,
license: license,
license_file: license_file,
source: summary.source_id(),
dependencies: summary.dependencies(),
targets: &self.manifest.targets(),
Expand Down
18 changes: 18 additions & 0 deletions tests/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ fn cargo_metadata_simple() {
"id": "foo[..]",
"source": null,
"dependencies": [],
"license": null,
"license_file": null,
"targets": [
{
"kind": [
Expand Down Expand Up @@ -80,6 +82,8 @@ fn cargo_metadata_with_deps_and_version() {
"manifest_path": "[..]Cargo.toml",
"name": "baz",
"source": "registry+[..]",
"license": null,
"license_file": null,
"targets": [
{
"kind": [
Expand Down Expand Up @@ -109,6 +113,8 @@ fn cargo_metadata_with_deps_and_version() {
"manifest_path": "[..]Cargo.toml",
"name": "bar",
"source": "registry+[..]",
"license": null,
"license_file": null,
"targets": [
{
"kind": [
Expand Down Expand Up @@ -138,6 +144,8 @@ fn cargo_metadata_with_deps_and_version() {
"manifest_path": "[..]Cargo.toml",
"name": "foo",
"source": null,
"license": "MIT",
"license_file": null,
"targets": [
{
"kind": [
Expand Down Expand Up @@ -198,6 +206,8 @@ fn workspace_metadata() {
"id": "bar[..]",
"source": null,
"dependencies": [],
"license": null,
"license_file": null,
"targets": [
{
"kind": [ "lib" ],
Expand All @@ -214,6 +224,8 @@ fn workspace_metadata() {
"id": "baz[..]",
"source": null,
"dependencies": [],
"license": null,
"license_file": null,
"targets": [
{
"kind": [ "lib" ],
Expand Down Expand Up @@ -265,6 +277,8 @@ fn workspace_metadata_no_deps() {
"id": "bar[..]",
"source": null,
"dependencies": [],
"license": null,
"license_file": null,
"targets": [
{
"kind": [ "lib" ],
Expand All @@ -281,6 +295,8 @@ fn workspace_metadata_no_deps() {
"id": "baz[..]",
"source": null,
"dependencies": [],
"license": null,
"license_file": null,
"targets": [
{
"kind": [ "lib" ],
Expand Down Expand Up @@ -320,6 +336,8 @@ const MANIFEST_OUTPUT: &'static str=
"id":"foo[..]0.5.0[..](path+file://[..]/foo)",
"source":null,
"dependencies":[],
"license": null,
"license_file": null,
"targets":[{
"kind":["bin"],
"name":"foo",
Expand Down
2 changes: 2 additions & 0 deletions tests/read-manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ fn read_manifest_output() -> String {
"name":"foo",
"version":"0.5.0",
"id":"foo[..]0.5.0[..](path+file://[..]/foo)",
"license": null,
"license_file": null,
"source":null,
"dependencies":[],
"targets":[{
Expand Down

0 comments on commit 4215ef8

Please sign in to comment.