Skip to content

Commit 544dda3

Browse files
committed
run_make_support: move target checks into targets module
1 parent 427cf94 commit 544dda3

File tree

2 files changed

+59
-36
lines changed

2 files changed

+59
-36
lines changed

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

Lines changed: 18 additions & 36 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,28 +60,17 @@ 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-
67-
/// Check if target is windows-like.
68-
#[must_use]
69-
pub fn is_windows() -> bool {
70-
target().contains("windows")
71-
}
72-
73-
/// Check if target uses msvc.
74-
#[must_use]
75-
pub fn is_msvc() -> bool {
76-
target().contains("msvc")
77-
}
78-
79-
/// Check if target uses macOS.
80-
#[must_use]
81-
pub fn is_darwin() -> bool {
82-
target().contains("darwin")
63+
/// `AR`
64+
#[track_caller]
65+
pub fn ar(inputs: &[impl AsRef<Path>], output_path: impl AsRef<Path>) {
66+
let output = fs::File::create(&output_path).expect(&format!(
67+
"the file in path \"{}\" could not be created",
68+
output_path.as_ref().display()
69+
));
70+
let mut builder = ar::Builder::new(output);
71+
for input in inputs {
72+
builder.append_path(input).unwrap();
73+
}
8374
}
8475

8576
#[track_caller]
@@ -348,20 +339,11 @@ pub fn cygpath_windows<P: AsRef<Path>>(path: P) -> String {
348339
output.stdout_utf8().trim().to_string()
349340
}
350341

351-
/// Run `uname`. This assumes that `uname` is available on the platform!
352-
#[track_caller]
353-
#[must_use]
354-
pub fn uname() -> String {
355-
let caller = panic::Location::caller();
356-
let mut uname = Command::new("uname");
357-
let output = uname.run();
358-
if !output.status().success() {
359-
handle_failed_output(&uname, output, caller.line());
360-
}
361-
output.stdout_utf8()
362-
}
363-
364-
fn handle_failed_output(cmd: &Command, output: CompletedProcess, caller_line_number: u32) -> ! {
342+
pub(crate) fn handle_failed_output(
343+
cmd: &Command,
344+
output: CompletedProcess,
345+
caller_line_number: u32,
346+
) -> ! {
365347
if output.status().success() {
366348
eprintln!("command unexpectedly succeeded at line {caller_line_number}");
367349
} 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)