Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit ae4fe1d

Browse files
committed
Use get_file_name in tests
1 parent 437b441 commit ae4fe1d

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

build_system/build_sysroot.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::fs;
22
use std::path::{Path, PathBuf};
33
use std::process::{self, Command};
44

5-
use super::rustc_info::{get_file_name, get_rustc_version};
5+
use super::rustc_info::{get_file_name, get_wrapper_file_name, get_rustc_version};
66
use super::utils::{spawn_and_wait, try_hard_link};
77
use super::SysrootKind;
88

@@ -37,10 +37,7 @@ pub(crate) fn build_sysroot(
3737

3838
// Build and copy rustc and cargo wrappers
3939
for wrapper in ["rustc-clif", "cargo-clif"] {
40-
let crate_name = wrapper.replace('-', "_");
41-
let wrapper_name = get_file_name(&crate_name, "bin", target_triple);
42-
let wrapper_name = wrapper_name.replace('_', "-");
43-
40+
let wrapper_name = get_wrapper_file_name(wrapper, "bin", target_triple);
4441

4542
let mut build_cargo_wrapper_cmd = Command::new("rustc");
4643
build_cargo_wrapper_cmd

build_system/rustc_info.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,12 @@ pub(crate) fn get_file_name(crate_name: &str, crate_type: &str, target: &str) ->
6565
assert!(file_name.contains(crate_name));
6666
file_name
6767
}
68+
69+
/// Similar to `get_file_name`, but converts any dashes (`-`) in the `crate_name` to
70+
/// underscores (`_`). This is specially made for the the rustc and cargo wrappers
71+
/// which have a dash in the name, and that is not allowed in a crate name.
72+
pub(crate) fn get_wrapper_file_name(crate_name: &str, crate_type: &str, target: &str) -> String {
73+
let crate_name = crate_name.replace('-', "_");
74+
let wrapper_name = get_file_name(&crate_name, crate_type, target);
75+
wrapper_name.replace('_', "-")
76+
}

build_system/tests.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::build_sysroot;
22
use super::config;
3+
use super::rustc_info::get_wrapper_file_name;
34
use super::utils::{spawn_and_wait, spawn_and_wait_with_input};
45
use build_system::SysrootKind;
56
use std::env;
@@ -407,10 +408,7 @@ impl TestRunner {
407408
{
408409
let mut rustc_clif = self.root_dir.clone();
409410
rustc_clif.push("build");
410-
rustc_clif.push("rustc-clif");
411-
if cfg!(windows) {
412-
rustc_clif.set_extension("exe");
413-
}
411+
rustc_clif.push(get_wrapper_file_name("rustc-clif", "bin", &self.target_triple));
414412

415413
let mut cmd = Command::new(rustc_clif);
416414
if !self.rust_flags.is_empty() {
@@ -471,10 +469,7 @@ impl TestRunner {
471469
{
472470
let mut cargo_clif = self.root_dir.clone();
473471
cargo_clif.push("build");
474-
cargo_clif.push("cargo-clif");
475-
if cfg!(windows) {
476-
cargo_clif.set_extension("exe");
477-
}
472+
cargo_clif.push(get_wrapper_file_name("cargo-clif", "bin", &self.target_triple));
478473

479474
let mut cmd = Command::new(cargo_clif);
480475
cmd.args(args);

0 commit comments

Comments
 (0)