]>
Commit | Line | Data |
---|---|---|
7453a54e SL |
1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT |
2 | // file at the top-level directory of this distribution and at | |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
10 | ||
11 | #![deny(warnings)] | |
12 | ||
13 | use std::process::{Command, Stdio}; | |
14 | use std::path::{Path, PathBuf}; | |
15 | ||
16 | pub fn run(cmd: &mut Command) { | |
17 | println!("running: {:?}", cmd); | |
18 | run_silent(cmd); | |
19 | } | |
20 | ||
21 | pub fn run_silent(cmd: &mut Command) { | |
22 | let status = match cmd.status() { | |
23 | Ok(status) => status, | |
24 | Err(e) => fail(&format!("failed to execute command: {}", e)), | |
25 | }; | |
26 | if !status.success() { | |
27 | fail(&format!("command did not execute successfully: {:?}\n\ | |
28 | expected success, got: {}", cmd, status)); | |
29 | } | |
30 | } | |
31 | ||
32 | pub fn gnu_target(target: &str) -> String { | |
33 | match target { | |
34 | "i686-pc-windows-msvc" => "i686-pc-win32".to_string(), | |
35 | "x86_64-pc-windows-msvc" => "x86_64-pc-win32".to_string(), | |
36 | "i686-pc-windows-gnu" => "i686-w64-mingw32".to_string(), | |
37 | "x86_64-pc-windows-gnu" => "x86_64-w64-mingw32".to_string(), | |
38 | s => s.to_string(), | |
39 | } | |
40 | } | |
41 | ||
42 | pub fn cc2ar(cc: &Path, target: &str) -> PathBuf { | |
43 | if target.contains("musl") || target.contains("msvc") { | |
44 | PathBuf::from("ar") | |
45 | } else { | |
54a0048b | 46 | let parent = cc.parent().unwrap(); |
7453a54e | 47 | let file = cc.file_name().unwrap().to_str().unwrap(); |
54a0048b SL |
48 | for suffix in &["gcc", "cc", "clang"] { |
49 | if let Some(idx) = file.rfind(suffix) { | |
50 | let mut file = file[..idx].to_owned(); | |
51 | file.push_str("ar"); | |
52 | return parent.join(&file); | |
53 | } | |
54 | } | |
55 | parent.join(file) | |
7453a54e SL |
56 | } |
57 | } | |
58 | ||
59 | pub fn output(cmd: &mut Command) -> String { | |
60 | let output = match cmd.stderr(Stdio::inherit()).output() { | |
61 | Ok(status) => status, | |
62 | Err(e) => fail(&format!("failed to execute command: {}", e)), | |
63 | }; | |
64 | if !output.status.success() { | |
65 | panic!("command did not execute successfully: {:?}\n\ | |
66 | expected success, got: {}", cmd, output.status); | |
67 | } | |
68 | String::from_utf8(output.stdout).unwrap() | |
69 | } | |
70 | ||
71 | fn fail(s: &str) -> ! { | |
72 | println!("\n\n{}\n\n", s); | |
73 | std::process::exit(1); | |
74 | } |