Skip to content

Commit

Permalink
Don't re-look-up tables to avoid dots problem
Browse files Browse the repository at this point in the history
If a `links` value has a `.` in the name Cargo would previously panic, but this
alters the code to be more principled about lookup in tables to ensure that we
don't misinterpret the names.

Closes #2786
  • Loading branch information
alexcrichton committed Jun 17, 2016
1 parent 5a26b65 commit 53b7422
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 18 deletions.
34 changes: 16 additions & 18 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ fn scrape_target_config(config: &Config, triple: &str)
Some(table) => table.val,
None => return Ok(ret),
};
for (lib_name, _) in table.into_iter() {
for (lib_name, value) in table {
if lib_name == "ar" || lib_name == "linker" || lib_name == "rustflags" {
continue
}
Expand All @@ -488,39 +488,37 @@ fn scrape_target_config(config: &Config, triple: &str)
rerun_if_changed: Vec::new(),
warnings: Vec::new(),
};
let key = format!("{}.{}", key, lib_name);
let table = try!(config.get_table(&key)).unwrap().val;
for (k, _) in table.into_iter() {
for (k, value) in try!(value.table()).0 {
let key = format!("{}.{}", key, k);
match &k[..] {
"rustc-flags" => {
let flags = try!(config.get_string(&key)).unwrap();
let (flags, definition) = try!(value.string());
let whence = format!("in `{}` (in {})", key,
flags.definition);
definition.display());
let (paths, links) = try!(
BuildOutput::parse_rustc_flags(&flags.val, &whence)
BuildOutput::parse_rustc_flags(&flags, &whence)
);
output.library_paths.extend(paths.into_iter());
output.library_links.extend(links.into_iter());
output.library_paths.extend(paths);
output.library_links.extend(links);
}
"rustc-link-lib" => {
let list = try!(config.get_list(&key)).unwrap();
output.library_links.extend(list.val.into_iter()
.map(|v| v.0));
let list = try!(value.list());
output.library_links.extend(list.iter()
.map(|v| v.0.clone()));
}
"rustc-link-search" => {
let list = try!(config.get_list(&key)).unwrap();
output.library_paths.extend(list.val.into_iter().map(|v| {
let list = try!(value.list());
output.library_paths.extend(list.iter().map(|v| {
PathBuf::from(&v.0)
}));
}
"rustc-cfg" => {
let list = try!(config.get_list(&key)).unwrap();
output.cfgs.extend(list.val.into_iter().map(|v| v.0));
let list = try!(value.list());
output.cfgs.extend(list.iter().map(|v| v.0.clone()));
}
_ => {
let val = try!(config.get_string(&key)).unwrap();
output.metadata.push((k, val.val));
let val = try!(value.string()).0;
output.metadata.push((k.clone(), val.to_string()));
}
}
}
Expand Down
31 changes: 31 additions & 0 deletions tests/build-script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2175,3 +2175,34 @@ stderr
[RUNNING] `rustc [..]`
"));
}

#[test]
fn links_with_dots() {
let target = rustc_host();

let p = project("foo")
.file("Cargo.toml", r#"
[project]
name = "foo"
version = "0.5.0"
authors = []
build = "build.rs"
links = "a.b"
"#)
.file("src/lib.rs", "")
.file("build.rs", r#"
fn main() {
println!("cargo:rustc-link-search=bar")
}
"#)
.file(".cargo/config", &format!(r#"
[target.{}.'a.b']
rustc-link-search = ["foo"]
"#, target));

assert_that(p.cargo_process("build").arg("-v"),
execs().with_status(0)
.with_stderr_contains("\
[RUNNING] `rustc [..] --crate-name foo [..] -L foo[..]`
"));
}

0 comments on commit 53b7422

Please sign in to comment.