Skip to content

Commit 852bef9

Browse files
Add build_helper::command_ext which extends std::process::Command.
1 parent 78166b9 commit 852bef9

File tree

18 files changed

+150
-18
lines changed

18 files changed

+150
-18
lines changed

src/bootstrap/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ use std::fs;
1717
use std::hash::Hash;
1818
use std::ops::Deref;
1919
use std::path::{Path, PathBuf};
20-
use std::process::Command;
2120
use std::time::{Instant, Duration};
2221
use std::collections::HashMap;
2322

23+
use build_helper::command_ext::Command;
2424
use compile;
2525
use install;
2626
use dist;

src/bootstrap/cc_detect.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
use std::collections::HashSet;
3535
use std::{env, iter};
3636
use std::path::{Path, PathBuf};
37-
use std::process::Command;
3837

3938
use build_helper::output;
39+
use build_helper::command_ext::Command;
4040
use cc;
4141

4242
use Build;
@@ -158,7 +158,9 @@ fn set_compiler(cfg: &mut cc::Build,
158158
return
159159
}
160160

161-
let output = output(c.to_command().arg("--version"));
161+
162+
let output = output(Command::from_std_command(c.to_command())
163+
.arg("--version"));
162164
let i = match output.find(" 4.") {
163165
Some(i) => i,
164166
None => return,

src/bootstrap/channel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
//! print out as part of its version information.
1717
1818
use std::path::Path;
19-
use std::process::Command;
2019

2120
use build_helper::output;
21+
use build_helper::command_ext::Command;
2222

2323
use Build;
2424
use config::Config;

src/bootstrap/compile.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ use std::fs::{self, File};
2222
use std::io::BufReader;
2323
use std::io::prelude::*;
2424
use std::path::{Path, PathBuf};
25-
use std::process::{Command, Stdio};
25+
use std::process::Stdio;
2626
use std::str;
2727
use std::cmp::min;
2828

2929
use build_helper::{output, mtime, up_to_date};
30+
use build_helper::command_ext::Command;
3031
use filetime::FileTime;
3132
use serde_json;
3233

src/bootstrap/dist.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ use std::env;
2222
use std::fs::{self, File};
2323
use std::io::{Read, Write};
2424
use std::path::{PathBuf, Path};
25-
use std::process::{Command, Stdio};
25+
use std::process::Stdio;
2626

2727
use build_helper::output;
28+
use build_helper::command_ext::Command;
2829

2930
use {Compiler, Mode};
3031
use channel;

src/bootstrap/install.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
use std::env;
1717
use std::fs;
1818
use std::path::{Path, PathBuf, Component};
19-
use std::process::Command;
2019

2120
use dist::{self, pkgname, sanitize_sh, tmpdir};
2221

2322
use builder::{Builder, RunConfig, ShouldRun, Step};
23+
use build_helper::command_ext::Command;
2424
use cache::Interned;
2525
use config::Config;
2626

src/bootstrap/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,12 @@ use std::env;
145145
use std::fs::{self, OpenOptions, File};
146146
use std::io::{self, Seek, SeekFrom, Write, Read};
147147
use std::path::{PathBuf, Path};
148-
use std::process::{self, Command};
148+
use std::process;
149149
use std::slice;
150150
use std::str;
151151

152152
use build_helper::{run_silent, run_suppressed, try_run_silent, try_run_suppressed, output, mtime};
153+
use build_helper::command_ext::Command;
153154
use filetime::FileTime;
154155

155156
use util::{exe, libdir, OutputFolder, CiEnv};

src/bootstrap/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
// except according to those terms.
1010

1111
use std::collections::HashMap;
12-
use std::process::Command;
1312
use std::path::PathBuf;
1413

1514
use build_helper::output;
15+
use build_helper::command_ext::Command;
1616
use serde_json;
1717

1818
use {Build, Crate};

src/bootstrap/native.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ use std::ffi::OsString;
2323
use std::fs::{self, File};
2424
use std::io::{Read, Write};
2525
use std::path::{Path, PathBuf};
26-
use std::process::Command;
2726

2827
use build_helper::output;
28+
use build_helper::command_ext::Command;
2929
use cmake;
3030
use cc;
3131

src/bootstrap/sanity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ use std::ffi::{OsString, OsStr};
2424
use std::fs::{self, File};
2525
use std::io::Read;
2626
use std::path::PathBuf;
27-
use std::process::Command;
2827

2928
use build_helper::output;
29+
use build_helper::command_ext::Command;
3030

3131
use Build;
3232

src/bootstrap/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ use std::iter;
1919
use std::fmt;
2020
use std::fs::{self, File};
2121
use std::path::{PathBuf, Path};
22-
use std::process::Command;
2322
use std::io::Read;
2423

2524
use build_helper::{self, output};
25+
use build_helper::command_ext::Command;
2626

2727
use builder::{Kind, RunConfig, ShouldRun, Builder, Compiler, Step};
2828
use Crate as CargoCrate;

src/bootstrap/tool.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ use std::fs;
1212
use std::env;
1313
use std::iter;
1414
use std::path::PathBuf;
15-
use std::process::{Command, exit};
15+
use std::process::exit;
1616

1717
use Mode;
1818
use Compiler;
1919
use builder::{Step, RunConfig, ShouldRun, Builder};
20+
use build_helper::command_ext::Command;
2021
use util::{exe, add_lib_path};
2122
use compile::{self, libtest_stamp, libstd_stamp, librustc_stamp};
2223
use native;

src/bootstrap/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ use std::str;
1818
use std::fs;
1919
use std::io::{self, Write};
2020
use std::path::{Path, PathBuf};
21-
use std::process::Command;
2221
use std::time::{SystemTime, Instant};
2322

2423
use config::Config;
2524
use builder::Builder;
25+
use build_helper::command_ext::Command;
2626

2727
/// Returns the `name` as the filename of a static library for `target`.
2828
pub fn staticlib(name: &str, target: &str) -> String {

src/build_helper/command_ext.rs

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
// Copyright 2017 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+
use std::ffi::{OsStr, OsString};
12+
use std::io::Result;
13+
use std::process;
14+
use std::path::Path;
15+
16+
// std::process::Command but with addition support for add arguments past
17+
// the `--` when invoking `cargo rustc`
18+
#[derive(Debug)]
19+
pub struct Command {
20+
cmd: process::Command,
21+
deferred_args: Vec<OsString>,
22+
}
23+
24+
impl Command {
25+
26+
pub fn new<S: AsRef<OsStr>>(program: S) -> Command {
27+
Command {
28+
cmd: process::Command::new(program),
29+
deferred_args: vec![],
30+
}
31+
}
32+
33+
pub fn from_std_command(cmd: process::Command) -> Command {
34+
Command {
35+
cmd,
36+
deferred_args: vec![],
37+
}
38+
}
39+
40+
pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Self {
41+
self.cmd.arg(arg);
42+
self
43+
}
44+
45+
pub fn args<I, S>(&mut self, args: I) -> &mut Command
46+
where
47+
I: IntoIterator<Item = S>,
48+
S: AsRef<OsStr>,
49+
{
50+
self.cmd.args(args);
51+
self
52+
}
53+
54+
pub fn deferred_arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Self {
55+
self.deferred_args.push(arg.as_ref().to_owned());
56+
self
57+
}
58+
59+
pub fn env<K, V>(&mut self, key: K, val: V) -> &mut Self
60+
where
61+
K: AsRef<OsStr>,
62+
V: AsRef<OsStr>,
63+
{
64+
self.cmd.env(key, val);
65+
self
66+
}
67+
68+
pub fn envs<I, K, V>(&mut self, vars: I) -> &mut Command
69+
where
70+
I: IntoIterator<Item = (K, V)>,
71+
K: AsRef<OsStr>,
72+
V: AsRef<OsStr>,
73+
{
74+
self.cmd.envs(vars);
75+
self
76+
}
77+
78+
pub fn env_remove<K: AsRef<OsStr>>(&mut self, key: K) -> &mut Self {
79+
self.cmd.env_remove(key);
80+
self
81+
}
82+
83+
pub fn env_clear(&mut self) -> &mut Command {
84+
self.cmd.env_clear();
85+
self
86+
}
87+
88+
pub fn current_dir<P: AsRef<Path>>(&mut self, dir: P) -> &mut Command {
89+
self.cmd.current_dir(dir);
90+
self
91+
}
92+
93+
pub fn stdin<T: Into<process::Stdio>>(&mut self, cfg: T) -> &mut Command {
94+
self.cmd.stdin(cfg);
95+
self
96+
}
97+
98+
pub fn stdout<T: Into<process::Stdio>>(&mut self, cfg: T) -> &mut Command {
99+
self.cmd.stdout(cfg);
100+
self
101+
}
102+
103+
pub fn stderr<T: Into<process::Stdio>>(&mut self, cfg: T) -> &mut Command {
104+
self.cmd.stderr(cfg);
105+
self
106+
}
107+
108+
pub fn spawn(&mut self) -> Result<process::Child> {
109+
self.cmd.args(self.deferred_args.clone().into_iter());
110+
self.cmd.spawn()
111+
}
112+
113+
pub fn output(&mut self) -> Result<process::Output> {
114+
self.cmd.args(self.deferred_args.clone().into_iter());
115+
self.cmd.output()
116+
}
117+
118+
pub fn status(&mut self) -> Result<process::ExitStatus> {
119+
self.cmd.args(self.deferred_args.clone().into_iter());
120+
self.cmd.status()
121+
}
122+
}

src/build_helper/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@
1010

1111
use std::fs::File;
1212
use std::path::{Path, PathBuf};
13-
use std::process::{Command, Stdio};
13+
use std::process::Stdio;
1414
use std::time::{SystemTime, UNIX_EPOCH};
1515
use std::{env, fs};
1616

17+
pub mod command_ext;
18+
19+
use command_ext::Command;
20+
1721
/// A helper macro to `unwrap` a result except also print out details like:
1822
///
1923
/// * The file/line of the panic

src/liballoc_jemalloc/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ extern crate cc;
1515

1616
use std::env;
1717
use std::path::PathBuf;
18-
use std::process::Command;
1918
use build_helper::{run, native_lib_boilerplate};
19+
use build_helper::command_ext::Command;
2020

2121
fn main() {
2222
// FIXME: This is a hack to support building targets that don't

src/librustc_llvm/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
extern crate cc;
1212
extern crate build_helper;
1313

14-
use std::process::Command;
1514
use std::env;
1615
use std::path::{PathBuf, Path};
1716

1817
use build_helper::output;
18+
use build_helper::command_ext::Command;
1919

2020
fn detect_llvm_link() -> (&'static str, &'static str) {
2121
// Force the link mode we want, preferring static by default, but

src/libstd/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
extern crate build_helper;
1414

1515
use std::env;
16-
use std::process::Command;
1716
use build_helper::{run, native_lib_boilerplate};
17+
use build_helper::command_ext::Command;
1818

1919
fn main() {
2020
let target = env::var("TARGET").expect("TARGET was not set");

0 commit comments

Comments
 (0)