Skip to content

Commit 07f872a

Browse files
committed
build: export repository information
The repository string is made available via the `CARGO_PKG_REPOSITORY` environment variable similar to other metadata.
1 parent e6c3a17 commit 07f872a

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

src/cargo/core/compiler/compilation.rs

+4
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,10 @@ impl<'cfg> Compilation<'cfg> {
236236
"CARGO_PKG_HOMEPAGE",
237237
metadata.homepage.as_ref().unwrap_or(&String::new()),
238238
)
239+
.env(
240+
"CARGO_PKG_REPOSITORY",
241+
metadata.repository.as_ref().unwrap_or(&String::new()),
242+
)
239243
.env("CARGO_PKG_AUTHORS", &pkg.authors().join(":"))
240244
.cwd(pkg.root());
241245
Ok(cmd)

src/doc/src/reference/environment-variables.md

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ let version = env!("CARGO_PKG_VERSION");
6363
* `CARGO_PKG_NAME` - The name of your package.
6464
* `CARGO_PKG_DESCRIPTION` - The description of your package.
6565
* `CARGO_PKG_HOMEPAGE` - The home page of your package.
66+
* `CARGO_PKG_REPOSITORY` - The repository of your package.
6667
* `OUT_DIR` - If the package has a build script, this is set to the folder where the build
6768
script should place its output. See below for more information.
6869

tests/testsuite/build.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,7 @@ fn crate_env_vars() {
13381338
version = "0.5.1-alpha.1"
13391339
description = "This is foo"
13401340
homepage = "http://example.com"
1341+
repository = "http://example.com/repo.git"
13411342
authors = ["wycats@example.com"]
13421343
"#,
13431344
).file(
@@ -1354,6 +1355,7 @@ fn crate_env_vars() {
13541355
static CARGO_MANIFEST_DIR: &'static str = env!("CARGO_MANIFEST_DIR");
13551356
static PKG_NAME: &'static str = env!("CARGO_PKG_NAME");
13561357
static HOMEPAGE: &'static str = env!("CARGO_PKG_HOMEPAGE");
1358+
static REPOSITORY: &'static str = env!("CARGO_PKG_REPOSITORY");
13571359
static DESCRIPTION: &'static str = env!("CARGO_PKG_DESCRIPTION");
13581360
13591361
fn main() {
@@ -1364,6 +1366,7 @@ fn crate_env_vars() {
13641366
println!("{}", s);
13651367
assert_eq!("foo", PKG_NAME);
13661368
assert_eq!("http://example.com", HOMEPAGE);
1369+
assert_eq!("http://example.com/repo.git", REPOSITORY);
13671370
assert_eq!("This is foo", DESCRIPTION);
13681371
let s = format!("{}.{}.{}-{}", VERSION_MAJOR,
13691372
VERSION_MINOR, VERSION_PATCH, VERSION_PRE);

0 commit comments

Comments
 (0)