From 4a4f5a20fa15ec440161b658b610122baa2810b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=A9l=20Kerkmann?= Date: Thu, 4 Jun 2020 02:51:16 +0200 Subject: [PATCH 1/2] Adding environment variable CARGO_PKG_LICENSE Fixes #8024 --- src/cargo/core/compiler/compilation.rs | 4 ++++ src/doc/src/reference/environment-variables.md | 1 + tests/testsuite/build.rs | 3 +++ 3 files changed, 8 insertions(+) diff --git a/src/cargo/core/compiler/compilation.rs b/src/cargo/core/compiler/compilation.rs index 7324618ff45..fa85b2d8c7c 100644 --- a/src/cargo/core/compiler/compilation.rs +++ b/src/cargo/core/compiler/compilation.rs @@ -289,6 +289,10 @@ impl<'cfg> Compilation<'cfg> { "CARGO_PKG_REPOSITORY", metadata.repository.as_ref().unwrap_or(&String::new()), ) + .env( + "CARGO_PKG_LICENSE", + metadata.license.as_ref().unwrap_or(&String::new()), + ) .env("CARGO_PKG_AUTHORS", &pkg.authors().join(":")) .cwd(pkg.root()); Ok(cmd) diff --git a/src/doc/src/reference/environment-variables.md b/src/doc/src/reference/environment-variables.md index bb03e5ef454..efe1f25ad77 100644 --- a/src/doc/src/reference/environment-variables.md +++ b/src/doc/src/reference/environment-variables.md @@ -184,6 +184,7 @@ let version = env!("CARGO_PKG_VERSION"); * `CARGO_PKG_DESCRIPTION` — The description from the manifest of your package. * `CARGO_PKG_HOMEPAGE` — The home page from the manifest of your package. * `CARGO_PKG_REPOSITORY` — The repository from the manifest of your package. +* `CARGO_PKG_LICENSE` — The license from the manifest of your package. * `OUT_DIR` — If the package has a build script, this is set to the folder where the build script should place its output. See below for more information. (Only set during compilation.) diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index 260b0f11f76..bcb72681b50 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -1230,6 +1230,7 @@ fn crate_env_vars() { homepage = "https://example.com" repository = "https://example.com/repo.git" authors = ["wycats@example.com"] + license = "MIT" "#, ) .file( @@ -1247,6 +1248,7 @@ fn crate_env_vars() { static PKG_NAME: &'static str = env!("CARGO_PKG_NAME"); static HOMEPAGE: &'static str = env!("CARGO_PKG_HOMEPAGE"); static REPOSITORY: &'static str = env!("CARGO_PKG_REPOSITORY"); + static LICENSE: &'static str = env!("CARGO_PKG_LICENSE"); static DESCRIPTION: &'static str = env!("CARGO_PKG_DESCRIPTION"); fn main() { @@ -1258,6 +1260,7 @@ fn crate_env_vars() { assert_eq!("foo", PKG_NAME); assert_eq!("https://example.com", HOMEPAGE); assert_eq!("https://example.com/repo.git", REPOSITORY); + assert_eq!("MIT", LICENSE); assert_eq!("This is foo", DESCRIPTION); let s = format!("{}.{}.{}-{}", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_PRE); From 8c99e2026b788910ee06f738b48d16b7ff78268b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=A9l=20Kerkmann?= Date: Sat, 6 Jun 2020 10:24:06 +0200 Subject: [PATCH 2/2] Change test 'MIT' license to 'MIT OR Apache-2.0' --- tests/testsuite/build.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index bcb72681b50..94b5c23c9de 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -1230,7 +1230,7 @@ fn crate_env_vars() { homepage = "https://example.com" repository = "https://example.com/repo.git" authors = ["wycats@example.com"] - license = "MIT" + license = "MIT OR Apache-2.0" "#, ) .file( @@ -1260,7 +1260,7 @@ fn crate_env_vars() { assert_eq!("foo", PKG_NAME); assert_eq!("https://example.com", HOMEPAGE); assert_eq!("https://example.com/repo.git", REPOSITORY); - assert_eq!("MIT", LICENSE); + assert_eq!("MIT OR Apache-2.0", LICENSE); assert_eq!("This is foo", DESCRIPTION); let s = format!("{}.{}.{}-{}", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_PRE);