Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new CARGO_PKG_AUTHORS environment variable #2465

Merged
merged 1 commit into from Apr 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/cargo/core/package.rs
Expand Up @@ -80,6 +80,7 @@ impl Package {
pub fn summary(&self) -> &Summary { self.manifest.summary() }
pub fn targets(&self) -> &[Target] { self.manifest().targets() }
pub fn version(&self) -> &Version { self.package_id().version() }
pub fn authors(&self) -> &Vec<String> { &self.manifest.metadata().authors }
pub fn publish(&self) -> bool { self.manifest.publish() }

pub fn has_custom_build(&self) -> bool {
Expand Down
1 change: 1 addition & 0 deletions src/cargo/ops/cargo_rustc/compilation.rs
Expand Up @@ -120,6 +120,7 @@ impl<'cfg> Compilation<'cfg> {
.env("CARGO_PKG_NAME", &pkg.name())
.env("CARGO_PKG_DESCRIPTION", metadata.description.as_ref().unwrap_or(&String::new()))
.env("CARGO_PKG_HOMEPAGE", metadata.homepage.as_ref().unwrap_or(&String::new()))
.env("CARGO_PKG_AUTHORS", &pkg.authors().join(":"))
.cwd(pkg.root());
Ok(cmd)
}
Expand Down
1 change: 1 addition & 0 deletions src/doc/environment-variables.md
Expand Up @@ -45,6 +45,7 @@ let version = env!("CARGO_PKG_VERSION");
* `CARGO_PKG_VERSION_MINOR` - The minor version of your package.
* `CARGO_PKG_VERSION_PATCH` - The patch version of your package.
* `CARGO_PKG_VERSION_PRE` - The pre-release version of your package.
* `CARGO_PKG_AUTHORS` - Colon seperated list of authors from the manifest of your package.

# Environment variables Cargo sets for build scripts

Expand Down
38 changes: 38 additions & 0 deletions tests/test_cargo_compile.rs
Expand Up @@ -784,6 +784,44 @@ test!(crate_env_vars {
execs().with_status(0));
});

test!(crate_authors_env_vars {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
name = "foo"
version = "0.5.1-alpha.1"
authors = ["wycats@example.com", "neikos@example.com"]
"#)
.file("src/main.rs", r#"
extern crate foo;

static AUTHORS: &'static str = env!("CARGO_PKG_AUTHORS");

fn main() {
let s = "wycats@example.com:neikos@example.com";
assert_eq!(AUTHORS, foo::authors());
println!("{}", AUTHORS);
assert_eq!(s, AUTHORS);
}
"#)
.file("src/lib.rs", r#"
pub fn authors() -> String {
format!("{}", env!("CARGO_PKG_AUTHORS"))
}
"#);

println!("build");
assert_that(p.cargo_process("build").arg("-v"), execs().with_status(0));

println!("bin");
assert_that(process(&p.bin("foo")),
execs().with_stdout(&format!("wycats@example.com:neikos@example.com")));

println!("test");
assert_that(p.cargo("test").arg("-v"),
execs().with_status(0));
});

// this is testing that src/<pkg-name>.rs still works (for now)
test!(many_crate_types_old_style_lib_location {
let mut p = project("foo");
Expand Down