Skip to content

Commit c63780d

Browse files
committed
fix usage of get_command
1 parent 73202bd commit c63780d

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

src/lib.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2399,7 +2399,7 @@ impl Build {
23992399

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

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

3125-
fn get_base_archiver_variant(&self, env: &str, tool: &str) -> Result<(Command, String), Error> {
3125+
fn get_base_archiver_variant(&self, env: &str, tool: &str) -> Result<(Command, PathBuf), Error> {
31263126
let target = self.get_target()?;
3127-
let mut name = String::new();
3127+
let mut name = PathBuf::new();
31283128
let tool_opt: Option<Command> = self
31293129
.env_tool(env)
31303130
.map(|(tool, _wrapper, args)| {
3131+
name = tool.clone();
31313132
let mut cmd = self.cmd(tool);
31323133
cmd.args(args);
31333134
cmd
@@ -3137,11 +3138,11 @@ impl Build {
31373138
// Windows use bat files so we have to be a bit more specific
31383139
if cfg!(windows) {
31393140
let mut cmd = self.cmd("cmd");
3140-
name = format!("em{}.bat", tool);
3141+
name = format!("em{}.bat", tool).into();
31413142
cmd.arg("/c").arg(&name);
31423143
Some(cmd)
31433144
} else {
3144-
name = format!("em{}", tool);
3145+
name = format!("em{}", tool).into();
31453146
Some(self.cmd(&name))
31463147
}
31473148
} else if target.starts_with("wasm32") {
@@ -3152,7 +3153,7 @@ impl Build {
31523153
// of "llvm-ar"...
31533154
let compiler = self.get_base_compiler().ok()?;
31543155
if compiler.is_like_clang() {
3155-
name = format!("llvm-{}", tool);
3156+
name = format!("llvm-{}", tool).into();
31563157
search_programs(&mut self.cmd(&compiler.path), &name, &self.cargo_output)
31573158
.map(|name| self.cmd(name))
31583159
} else {
@@ -3168,10 +3169,10 @@ impl Build {
31683169
Some(t) => t,
31693170
None => {
31703171
if target.contains("android") {
3171-
name = format!("llvm-{}", tool);
3172+
name = format!("llvm-{}", tool).into();
31723173
match Command::new(&name).arg("--version").status() {
31733174
Ok(status) if status.success() => (),
3174-
_ => name = format!("{}-{}", target.replace("armv7", "arm"), tool),
3175+
_ => name = format!("{}-{}", target.replace("armv7", "arm"), tool).into(),
31753176
}
31763177
self.cmd(&name)
31773178
} else if target.contains("msvc") {
@@ -3198,7 +3199,7 @@ impl Build {
31983199
}
31993200

32003201
if lib.is_empty() {
3201-
name = String::from("lib.exe");
3202+
name = PathBuf::from("lib.exe");
32023203
let mut cmd = match windows_registry::find(&target, "lib.exe") {
32033204
Some(t) => t,
32043205
None => self.cmd("lib.exe"),
@@ -3208,15 +3209,15 @@ impl Build {
32083209
}
32093210
cmd
32103211
} else {
3211-
name = lib;
3212+
name = lib.into();
32123213
self.cmd(&name)
32133214
}
32143215
} else if target.contains("illumos") {
32153216
// The default 'ar' on illumos uses a non-standard flags,
32163217
// but the OS comes bundled with a GNU-compatible variant.
32173218
//
32183219
// Use the GNU-variant to match other Unix systems.
3219-
name = format!("g{}", tool);
3220+
name = format!("g{}", tool).into();
32203221
self.cmd(&name)
32213222
} else if self.get_host()? != target {
32223223
match self.prefix_for_target(&target) {
@@ -3236,16 +3237,16 @@ impl Build {
32363237
break;
32373238
}
32383239
}
3239-
name = chosen;
3240+
name = chosen.into();
32403241
self.cmd(&name)
32413242
}
32423243
None => {
3243-
name = default;
3244+
name = default.into();
32443245
self.cmd(&name)
32453246
}
32463247
}
32473248
} else {
3248-
name = default;
3249+
name = default.into();
32493250
self.cmd(&name)
32503251
}
32513252
}
@@ -3937,7 +3938,7 @@ fn which(tool: &Path, path_entries: Option<OsString>) -> Option<PathBuf> {
39373938
}
39383939

39393940
// search for |prog| on 'programs' path in '|cc| -print-search-dirs' output
3940-
fn search_programs(cc: &mut Command, prog: &str, cargo_output: &CargoOutput) -> Option<PathBuf> {
3941+
fn search_programs(cc: &mut Command, prog: &Path, cargo_output: &CargoOutput) -> Option<PathBuf> {
39413942
let search_dirs = run_output(
39423943
cc.arg("-print-search-dirs"),
39433944
"cc",
@@ -3950,7 +3951,7 @@ fn search_programs(cc: &mut Command, prog: &str, cargo_output: &CargoOutput) ->
39503951
let search_dirs = std::str::from_utf8(&search_dirs).ok()?;
39513952
for dirs in search_dirs.split(|c| c == '\r' || c == '\n') {
39523953
if let Some(path) = dirs.strip_prefix("programs: =") {
3953-
return which(Path::new(prog), Some(OsString::from(path)));
3954+
return which(prog, Some(OsString::from(path)));
39543955
}
39553956
}
39563957
None

0 commit comments

Comments
 (0)