Skip to content

Commit

Permalink
Fix PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Xion committed May 12, 2017
1 parent 8b744a0 commit f1ae9f8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
6 changes: 6 additions & 0 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,12 @@ fn scrape_target_config(config: &Config, triple: &str)
let list = value.list(&k)?;
output.cfgs.extend(list.iter().map(|v| v.0.clone()));
}
"rustc-env" => {
for (name, val) in value.table(&k)?.0 {
let val = val.string(name)?.0;
output.env.push((name.clone(), val.to_string()));
}
}
"warning" | "rerun-if-changed" => {
bail!("`{}` is not supported in build script overrides", k);
}
Expand Down
15 changes: 5 additions & 10 deletions src/cargo/ops/cargo_rustc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,17 +428,12 @@ fn rustc(cx: &mut Context, unit: &Unit, exec: Arc<Executor>) -> CargoResult<Work
// been put there by one of the `build_scripts`) to the command provided.
fn add_custom_env(rustc: &mut ProcessBuilder,
build_state: &BuildMap,
build_scripts: &BuildScripts,
_: &BuildScripts,
current_id: &PackageId) -> CargoResult<()> {
for key in build_scripts.to_link.iter() {
let output = build_state.get(key).chain_error(|| {
internal(format!("couldn't find build state for {}/{:?}",
key.0, key.1))
})?;
if key.0 == *current_id {
for &(ref name, ref value) in output.env.iter() {
rustc.env(name, value);
}
let key = (current_id.clone(), Kind::Host);
if let Some(output) = build_state.get(&key) {
for &(ref name, ref value) in output.env.iter() {
rustc.env(name, value);
}
}
Ok(())
Expand Down
6 changes: 5 additions & 1 deletion tests/build-script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1587,7 +1587,9 @@ fn env_build() {
"#)
.file("src/main.rs", r#"
const FOO: &'static str = env!("FOO");
fn main() {}
fn main() {
println!("{}", FOO);
}
"#)
.file("build.rs", r#"
fn main() {
Expand All @@ -1596,6 +1598,8 @@ fn env_build() {
"#);
assert_that(build.cargo_process("build").arg("-v"),
execs().with_status(0));
assert_that(build.cargo("run").arg("-v"),
execs().with_status(0).with_stdout("foo\n"));
}

#[test]
Expand Down

0 comments on commit f1ae9f8

Please sign in to comment.