Skip to content

Commit

Permalink
Detect standalone android compiler with regex
Browse files Browse the repository at this point in the history
  • Loading branch information
gianluca-hilton committed Aug 3, 2020
1 parent 369eeac commit 4a01c44
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ edition = "2018"

[dependencies]
jobserver = { version = "0.1.16", optional = true }
regex = "1.3.9"

[features]
parallel = ["jobserver"]
Expand Down
16 changes: 13 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ use std::path::{Path, PathBuf};
use std::process::{Child, Command, Stdio};
use std::sync::{Arc, Mutex};
use std::thread::{self, JoinHandle};
use regex::Regex;

// These modules are all glue to support reading the MSVC version from
// the registry and from COM interfaces
Expand Down Expand Up @@ -2839,9 +2840,18 @@ static NEW_STANDALONE_ANDROID_COMPILERS: [&str; 4] = [
// So to construct proper command line check if
// `--target` argument would be passed or not to clang
fn android_clang_compiler_uses_target_arg_internally(clang_path: &Path) -> bool {
NEW_STANDALONE_ANDROID_COMPILERS
.iter()
.any(|x| Some(x.as_ref()) == clang_path.file_name())
let re = Regex::new(r"^.*\d{2}-clang(\+\+)?$").unwrap();
re.is_match(clang_path.to_str().unwrap())
}

#[test]
fn test_android_clang_compiler_uses_target_arg_internally() {
for version in 16..21 {
assert!(android_clang_compiler_uses_target_arg_internally(&PathBuf::from(format!("armv7a-linux-androideabi{}-clang", version))));
assert!(android_clang_compiler_uses_target_arg_internally(&PathBuf::from(format!("armv7a-linux-androideabi{}-clang++", version))));
}
assert!(!android_clang_compiler_uses_target_arg_internally(&PathBuf::from("clang")));
assert!(!android_clang_compiler_uses_target_arg_internally(&PathBuf::from("clang++")));
}

fn autodetect_android_compiler(target: &str, host: &str, gnu: &str, clang: &str) -> String {
Expand Down

0 comments on commit 4a01c44

Please sign in to comment.