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

Commit 60764e6

Browse files
committed
run_make_support: move target checks into targets module
1 parent c761cb2 commit 60764e6

File tree

2 files changed

+48
-38
lines changed

2 files changed

+48
-38
lines changed

src/tools/run-make-support/src/lib.rs

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ mod macros;
1313
pub mod run;
1414
pub mod rustc;
1515
pub mod rustdoc;
16+
pub mod targets;
1617

1718
use std::env;
1819
use std::ffi::OsString;
@@ -37,6 +38,7 @@ pub use llvm::{
3738
pub use run::{cmd, run, run_fail, run_with_args};
3839
pub use rustc::{aux_build, bare_rustc, rustc, Rustc};
3940
pub use rustdoc::{bare_rustdoc, rustdoc, Rustdoc};
41+
pub use targets::{is_darwin, is_msvc, is_windows, target, uname};
4042

4143
use command::{Command, CompletedProcess};
4244

@@ -58,12 +60,6 @@ pub fn env_var_os(name: &str) -> OsString {
5860
}
5961
}
6062

61-
/// `TARGET`
62-
#[must_use]
63-
pub fn target() -> String {
64-
env_var("TARGET")
65-
}
66-
6763
/// `AR`
6864
#[track_caller]
6965
pub fn ar(inputs: &[impl AsRef<Path>], output_path: impl AsRef<Path>) {
@@ -77,24 +73,6 @@ pub fn ar(inputs: &[impl AsRef<Path>], output_path: impl AsRef<Path>) {
7773
}
7874
}
7975

80-
/// Check if target is windows-like.
81-
#[must_use]
82-
pub fn is_windows() -> bool {
83-
target().contains("windows")
84-
}
85-
86-
/// Check if target uses msvc.
87-
#[must_use]
88-
pub fn is_msvc() -> bool {
89-
target().contains("msvc")
90-
}
91-
92-
/// Check if target uses macOS.
93-
#[must_use]
94-
pub fn is_darwin() -> bool {
95-
target().contains("darwin")
96-
}
97-
9876
#[track_caller]
9977
#[must_use]
10078
pub fn python_command() -> Command {
@@ -341,20 +319,11 @@ pub fn cygpath_windows<P: AsRef<Path>>(path: P) -> String {
341319
output.stdout_utf8().trim().to_string()
342320
}
343321

344-
/// Run `uname`. This assumes that `uname` is available on the platform!
345-
#[track_caller]
346-
#[must_use]
347-
pub fn uname() -> String {
348-
let caller = panic::Location::caller();
349-
let mut uname = Command::new("uname");
350-
let output = uname.run();
351-
if !output.status().success() {
352-
handle_failed_output(&uname, output, caller.line());
353-
}
354-
output.stdout_utf8()
355-
}
356-
357-
fn handle_failed_output(cmd: &Command, output: CompletedProcess, caller_line_number: u32) -> ! {
322+
pub(crate) fn handle_failed_output(
323+
cmd: &Command,
324+
output: CompletedProcess,
325+
caller_line_number: u32,
326+
) -> ! {
358327
if output.status().success() {
359328
eprintln!("command unexpectedly succeeded at line {caller_line_number}");
360329
} else {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use std::panic;
2+
3+
use crate::command::Command;
4+
use crate::{env_var, handle_failed_output};
5+
6+
/// `TARGET`
7+
#[must_use]
8+
pub fn target() -> String {
9+
env_var("TARGET")
10+
}
11+
12+
/// Check if target is windows-like.
13+
#[must_use]
14+
pub fn is_windows() -> bool {
15+
target().contains("windows")
16+
}
17+
18+
/// Check if target uses msvc.
19+
#[must_use]
20+
pub fn is_msvc() -> bool {
21+
target().contains("msvc")
22+
}
23+
24+
/// Check if target uses macOS.
25+
#[must_use]
26+
pub fn is_darwin() -> bool {
27+
target().contains("darwin")
28+
}
29+
30+
/// Run `uname`. This assumes that `uname` is available on the platform!
31+
#[track_caller]
32+
#[must_use]
33+
pub fn uname() -> String {
34+
let caller = panic::Location::caller();
35+
let mut uname = Command::new("uname");
36+
let output = uname.run();
37+
if !output.status().success() {
38+
handle_failed_output(&uname, output, caller.line());
39+
}
40+
output.stdout_utf8()
41+
}

0 commit comments

Comments
 (0)