From 07f872a64096c9649dc6334893b3dca23cbbfa7b Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Tue, 25 Sep 2018 16:27:10 -0400 Subject: [PATCH 1/2] build: export repository information The repository string is made available via the `CARGO_PKG_REPOSITORY` environment variable similar to other metadata. --- 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 2427941b4d1..c729d4845e0 100644 --- a/src/cargo/core/compiler/compilation.rs +++ b/src/cargo/core/compiler/compilation.rs @@ -236,6 +236,10 @@ impl<'cfg> Compilation<'cfg> { "CARGO_PKG_HOMEPAGE", metadata.homepage.as_ref().unwrap_or(&String::new()), ) + .env( + "CARGO_PKG_REPOSITORY", + metadata.repository.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 56b059b83d7..d613add9215 100644 --- a/src/doc/src/reference/environment-variables.md +++ b/src/doc/src/reference/environment-variables.md @@ -63,6 +63,7 @@ let version = env!("CARGO_PKG_VERSION"); * `CARGO_PKG_NAME` - The name of your package. * `CARGO_PKG_DESCRIPTION` - The description of your package. * `CARGO_PKG_HOMEPAGE` - The home page of your package. +* `CARGO_PKG_REPOSITORY` - The repository 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. diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index aba5dbf09bc..6679cf74915 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -1338,6 +1338,7 @@ fn crate_env_vars() { version = "0.5.1-alpha.1" description = "This is foo" homepage = "http://example.com" + repository = "http://example.com/repo.git" authors = ["wycats@example.com"] "#, ).file( @@ -1354,6 +1355,7 @@ fn crate_env_vars() { static CARGO_MANIFEST_DIR: &'static str = env!("CARGO_MANIFEST_DIR"); 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 DESCRIPTION: &'static str = env!("CARGO_PKG_DESCRIPTION"); fn main() { @@ -1364,6 +1366,7 @@ fn crate_env_vars() { println!("{}", s); assert_eq!("foo", PKG_NAME); assert_eq!("http://example.com", HOMEPAGE); + assert_eq!("http://example.com/repo.git", REPOSITORY); assert_eq!("This is foo", DESCRIPTION); let s = format!("{}.{}.{}-{}", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_PRE); From ae6b2f66cf052abf5b5eea9c71d77bcae6ff5582 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 27 Sep 2018 16:44:36 -0400 Subject: [PATCH 2/2] docs: clarify where package metadata comes from --- src/doc/src/reference/environment-variables.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/doc/src/reference/environment-variables.md b/src/doc/src/reference/environment-variables.md index d613add9215..4062b9fe340 100644 --- a/src/doc/src/reference/environment-variables.md +++ b/src/doc/src/reference/environment-variables.md @@ -61,9 +61,9 @@ let version = env!("CARGO_PKG_VERSION"); * `CARGO_PKG_VERSION_PRE` - The pre-release version of your package. * `CARGO_PKG_AUTHORS` - Colon separated list of authors from the manifest of your package. * `CARGO_PKG_NAME` - The name of your package. -* `CARGO_PKG_DESCRIPTION` - The description of your package. -* `CARGO_PKG_HOMEPAGE` - The home page of your package. -* `CARGO_PKG_REPOSITORY` - The repository of your package. +* `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. * `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.