2015-11-19 15:20:12 -08:00
|
|
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
#![deny(warnings)]
|
|
|
|
|
|
|
|
use std::process::{Command, Stdio};
|
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
|
|
|
|
pub fn run(cmd: &mut Command) {
|
|
|
|
println!("running: {:?}", cmd);
|
|
|
|
run_silent(cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn run_silent(cmd: &mut Command) {
|
|
|
|
let status = match cmd.status() {
|
|
|
|
Ok(status) => status,
|
|
|
|
Err(e) => fail(&format!("failed to execute command: {}", e)),
|
|
|
|
};
|
|
|
|
if !status.success() {
|
|
|
|
fail(&format!("command did not execute successfully: {:?}\n\
|
|
|
|
expected success, got: {}", cmd, status));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn gnu_target(target: &str) -> String {
|
|
|
|
match target {
|
|
|
|
"i686-pc-windows-msvc" => "i686-pc-win32".to_string(),
|
|
|
|
"x86_64-pc-windows-msvc" => "x86_64-pc-win32".to_string(),
|
|
|
|
"i686-pc-windows-gnu" => "i686-w64-mingw32".to_string(),
|
|
|
|
"x86_64-pc-windows-gnu" => "x86_64-w64-mingw32".to_string(),
|
|
|
|
s => s.to_string(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn cc2ar(cc: &Path, target: &str) -> PathBuf {
|
|
|
|
if target.contains("musl") || target.contains("msvc") {
|
|
|
|
PathBuf::from("ar")
|
|
|
|
} else {
|
2016-04-04 19:44:38 +10:00
|
|
|
let parent = cc.parent().unwrap();
|
2015-11-19 15:20:12 -08:00
|
|
|
let file = cc.file_name().unwrap().to_str().unwrap();
|
2016-04-04 19:44:38 +10:00
|
|
|
for suffix in &["gcc", "cc", "clang"] {
|
|
|
|
if let Some(idx) = file.rfind(suffix) {
|
|
|
|
let mut file = file[..idx].to_owned();
|
|
|
|
file.push_str(suffix);
|
|
|
|
return parent.join(&file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
parent.join(file)
|
2015-11-19 15:20:12 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn output(cmd: &mut Command) -> String {
|
|
|
|
let output = match cmd.stderr(Stdio::inherit()).output() {
|
|
|
|
Ok(status) => status,
|
|
|
|
Err(e) => fail(&format!("failed to execute command: {}", e)),
|
|
|
|
};
|
|
|
|
if !output.status.success() {
|
|
|
|
panic!("command did not execute successfully: {:?}\n\
|
|
|
|
expected success, got: {}", cmd, output.status);
|
|
|
|
}
|
|
|
|
String::from_utf8(output.stdout).unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn fail(s: &str) -> ! {
|
|
|
|
println!("\n\n{}\n\n", s);
|
|
|
|
std::process::exit(1);
|
|
|
|
}
|