diff --git a/src/cargo/core/compiler/compilation.rs b/src/cargo/core/compiler/compilation.rs index b8fb670c299..67e7fe8af57 100644 --- a/src/cargo/core/compiler/compilation.rs +++ b/src/cargo/core/compiler/compilation.rs @@ -287,6 +287,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 f1c96f1ac39..0ea01157f6c 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. * `CARGO_CRATE_NAME` — The name of the crate that is currently being compiled. * `CARGO_BIN_NAME` — The name of the binary that is currently being compiled (if it is a binary). This name does not include any file extension, such as `.exe`. * `OUT_DIR` — If the package has a build script, this is set to the folder where the build diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index a63bc7a569d..0c42e3a969b 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 OR Apache-2.0" [[bin]] name = "foo-bar" @@ -1251,6 +1252,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"); static BIN_NAME: &'static str = env!("CARGO_BIN_NAME"); static CRATE_NAME: &'static str = env!("CARGO_CRATE_NAME"); @@ -1267,6 +1269,7 @@ fn crate_env_vars() { assert_eq!("foo_bar", CRATE_NAME); assert_eq!("https://example.com", HOMEPAGE); assert_eq!("https://example.com/repo.git", REPOSITORY); + 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);