Skip to content

Commit

Permalink
Merge pull request #115 from rust-lang/isystem
Browse files Browse the repository at this point in the history
Add support for -isystem, -iquote, -idirafter include flags
  • Loading branch information
sdroege committed Oct 13, 2020
2 parents 7a442be + 948f45f commit 9d276ae
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
35 changes: 22 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,16 +518,17 @@ impl Library {
}
};

let mut dirs = Vec::new();
let statik = config.is_static(name);

let words = split_flags(output);

// Handle single-character arguments like `-I/usr/include`
let parts = words
.iter()
.filter(|l| l.len() > 2)
.map(|arg| (&arg[0..2], &arg[2..]))
.collect::<Vec<_>>();

let mut dirs = Vec::new();
let statik = config.is_static(name);
for &(flag, val) in &parts {
.map(|arg| (&arg[0..2], &arg[2..]));
for (flag, val) in parts {
match flag {
"-L" => {
let meta = format!("rustc-link-search=native={}", val);
Expand Down Expand Up @@ -570,6 +571,7 @@ impl Library {
}
}

// Handle multi-character arguments with space-separated value like `-framework foo`
let mut iter = words.iter().flat_map(|arg| {
if arg.starts_with("-Wl,") {
arg[4..].split(',').collect()
Expand All @@ -578,13 +580,20 @@ impl Library {
}
});
while let Some(part) = iter.next() {
if part != "-framework" {
continue;
}
if let Some(lib) = iter.next() {
let meta = format!("rustc-link-lib=framework={}", lib);
config.print_metadata(&meta);
self.frameworks.push(lib.to_string());
match part {
"-framework" => {
if let Some(lib) = iter.next() {
let meta = format!("rustc-link-lib=framework={}", lib);
config.print_metadata(&meta);
self.frameworks.push(lib.to_string());
}
}
"-isystem" | "-iquote" | "-idirafter" => {
if let Some(inc) = iter.next() {
self.include_paths.push(PathBuf::from(inc));
}
}
_ => (),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/foo.pc
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ Description: A dynamic binary instrumentation framework
Version: 3.10.0.SVN
Requires:
Libs: -L${libdir}/valgrind -lcoregrind-amd64-linux -lvex-amd64-linux -lgcc
Cflags: -I${includedir}
Cflags: -I${includedir} -isystem /usr/foo

4 changes: 4 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ fn output_ok() {
assert!(lib.libs.contains(&"gcc".to_string()));
assert!(lib.libs.contains(&"coregrind-amd64-linux".to_string()));
assert!(lib.link_paths.contains(&PathBuf::from("/usr/lib/valgrind")));
assert!(lib
.include_paths
.contains(&PathBuf::from("/usr/include/valgrind")));
assert!(lib.include_paths.contains(&PathBuf::from("/usr/foo")));
}

#[test]
Expand Down

0 comments on commit 9d276ae

Please sign in to comment.