Skip to content

Commit

Permalink
fix usage of get_command
Browse files Browse the repository at this point in the history
  • Loading branch information
russelltg committed Mar 19, 2024
1 parent 73202bd commit c63780d
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2399,7 +2399,7 @@ impl Build {

let target = self.get_target()?;
let (mut ar, cmd, _any_flags) = self.get_ar()?;
if target.contains("msvc") && ! ar.get_program().to_str().unwrap().contains("llvm-") {
if target.contains("msvc") && ! cmd.to_str().unwrap().contains("llvm-") {
// The Rust compiler will look for libfoo.a and foo.lib, but the
// MSVC linker will also be passed foo.lib, so be sure that both
// exist for now.
Expand Down Expand Up @@ -2436,7 +2436,7 @@ impl Build {
let target = self.get_target()?;

let (mut cmd, program, any_flags) = self.get_ar()?;
if target.contains("msvc") && !cmd.get_program().to_str().unwrap().contains("llvm-") {
if target.contains("msvc") && !program.to_str().unwrap().contains("llvm-") {
// NOTE: -out: here is an I/O flag, and so must be included even if $ARFLAGS/ar_flag is
// in use. -nologo on the other hand is just a regular flag, and one that we'll skip if
// the caller has explicitly dictated the flags they want. See
Expand Down Expand Up @@ -3122,12 +3122,13 @@ impl Build {
Ok(self.get_base_archiver_variant("RANLIB", "ranlib")?.0)
}

fn get_base_archiver_variant(&self, env: &str, tool: &str) -> Result<(Command, String), Error> {
fn get_base_archiver_variant(&self, env: &str, tool: &str) -> Result<(Command, PathBuf), Error> {
let target = self.get_target()?;
let mut name = String::new();
let mut name = PathBuf::new();
let tool_opt: Option<Command> = self
.env_tool(env)
.map(|(tool, _wrapper, args)| {
name = tool.clone();
let mut cmd = self.cmd(tool);
cmd.args(args);
cmd
Expand All @@ -3137,11 +3138,11 @@ impl Build {
// Windows use bat files so we have to be a bit more specific
if cfg!(windows) {
let mut cmd = self.cmd("cmd");
name = format!("em{}.bat", tool);
name = format!("em{}.bat", tool).into();
cmd.arg("/c").arg(&name);
Some(cmd)
} else {
name = format!("em{}", tool);
name = format!("em{}", tool).into();
Some(self.cmd(&name))
}
} else if target.starts_with("wasm32") {
Expand All @@ -3152,7 +3153,7 @@ impl Build {
// of "llvm-ar"...
let compiler = self.get_base_compiler().ok()?;
if compiler.is_like_clang() {
name = format!("llvm-{}", tool);
name = format!("llvm-{}", tool).into();
search_programs(&mut self.cmd(&compiler.path), &name, &self.cargo_output)
.map(|name| self.cmd(name))
} else {
Expand All @@ -3168,10 +3169,10 @@ impl Build {
Some(t) => t,
None => {
if target.contains("android") {
name = format!("llvm-{}", tool);
name = format!("llvm-{}", tool).into();
match Command::new(&name).arg("--version").status() {
Ok(status) if status.success() => (),
_ => name = format!("{}-{}", target.replace("armv7", "arm"), tool),
_ => name = format!("{}-{}", target.replace("armv7", "arm"), tool).into(),
}
self.cmd(&name)
} else if target.contains("msvc") {
Expand All @@ -3198,7 +3199,7 @@ impl Build {
}

if lib.is_empty() {
name = String::from("lib.exe");
name = PathBuf::from("lib.exe");
let mut cmd = match windows_registry::find(&target, "lib.exe") {
Some(t) => t,
None => self.cmd("lib.exe"),
Expand All @@ -3208,15 +3209,15 @@ impl Build {
}
cmd
} else {
name = lib;
name = lib.into();
self.cmd(&name)
}
} else if target.contains("illumos") {
// The default 'ar' on illumos uses a non-standard flags,
// but the OS comes bundled with a GNU-compatible variant.
//
// Use the GNU-variant to match other Unix systems.
name = format!("g{}", tool);
name = format!("g{}", tool).into();
self.cmd(&name)
} else if self.get_host()? != target {
match self.prefix_for_target(&target) {
Expand All @@ -3236,16 +3237,16 @@ impl Build {
break;
}
}
name = chosen;
name = chosen.into();
self.cmd(&name)
}
None => {
name = default;
name = default.into();
self.cmd(&name)
}
}
} else {
name = default;
name = default.into();
self.cmd(&name)
}
}
Expand Down Expand Up @@ -3937,7 +3938,7 @@ fn which(tool: &Path, path_entries: Option<OsString>) -> Option<PathBuf> {
}

// search for |prog| on 'programs' path in '|cc| -print-search-dirs' output
fn search_programs(cc: &mut Command, prog: &str, cargo_output: &CargoOutput) -> Option<PathBuf> {
fn search_programs(cc: &mut Command, prog: &Path, cargo_output: &CargoOutput) -> Option<PathBuf> {
let search_dirs = run_output(
cc.arg("-print-search-dirs"),
"cc",
Expand All @@ -3950,7 +3951,7 @@ fn search_programs(cc: &mut Command, prog: &str, cargo_output: &CargoOutput) ->
let search_dirs = std::str::from_utf8(&search_dirs).ok()?;
for dirs in search_dirs.split(|c| c == '\r' || c == '\n') {
if let Some(path) = dirs.strip_prefix("programs: =") {
return which(Path::new(prog), Some(OsString::from(path)));
return which(prog, Some(OsString::from(path)));
}
}
None
Expand Down

0 comments on commit c63780d

Please sign in to comment.