Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove command prototype #3193

Merged
merged 1 commit into from
Oct 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/cargo/ops/cargo_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ pub fn run(ws: &Workspace,
Some(path) => path.to_path_buf(),
None => exe.to_path_buf(),
};
let mut process = try!(compile.target_process(exe, &root))
.into_process_builder();
let mut process = try!(compile.target_process(exe, &root));
process.args(args).cwd(config.cwd());

try!(config.shell().status("Running", process.to_string()));
Expand Down
89 changes: 0 additions & 89 deletions src/cargo/ops/cargo_rustc/command.rs

This file was deleted.

35 changes: 25 additions & 10 deletions src/cargo/ops/cargo_rustc/compilation.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use std::collections::{HashMap, HashSet};
use std::ffi::OsStr;
use std::ffi::{OsStr, OsString};
use std::path::PathBuf;
use semver::Version;

use core::{PackageId, Package, Target};
use util::{self, CargoResult, Config};

use super::{CommandType, CommandPrototype};
use util::{self, CargoResult, Config, ProcessBuilder, process};

/// A structure returning the result of a compilation.
pub struct Compilation<'cfg> {
Expand Down Expand Up @@ -49,6 +47,18 @@ pub struct Compilation<'cfg> {
config: &'cfg Config,
}

#[derive(Clone, Debug)]
pub enum CommandType {
Rustc,
Rustdoc,

/// The command is to be executed for the target architecture.
Target(OsString),

/// The command is to be executed for the host architecture.
Host(OsString),
}

impl<'cfg> Compilation<'cfg> {
pub fn new(config: &'cfg Config) -> Compilation<'cfg> {
Compilation {
Expand All @@ -67,25 +77,25 @@ impl<'cfg> Compilation<'cfg> {
}

/// See `process`.
pub fn rustc_process(&self, pkg: &Package) -> CargoResult<CommandPrototype> {
pub fn rustc_process(&self, pkg: &Package) -> CargoResult<ProcessBuilder> {
self.process(CommandType::Rustc, pkg)
}

/// See `process`.
pub fn rustdoc_process(&self, pkg: &Package)
-> CargoResult<CommandPrototype> {
-> CargoResult<ProcessBuilder> {
self.process(CommandType::Rustdoc, pkg)
}

/// See `process`.
pub fn target_process<T: AsRef<OsStr>>(&self, cmd: T, pkg: &Package)
-> CargoResult<CommandPrototype> {
-> CargoResult<ProcessBuilder> {
self.process(CommandType::Target(cmd.as_ref().to_os_string()), pkg)
}

/// See `process`.
pub fn host_process<T: AsRef<OsStr>>(&self, cmd: T, pkg: &Package)
-> CargoResult<CommandPrototype> {
-> CargoResult<ProcessBuilder> {
self.process(CommandType::Host(cmd.as_ref().to_os_string()), pkg)
}

Expand All @@ -95,7 +105,7 @@ impl<'cfg> Compilation<'cfg> {
/// The package argument is also used to configure environment variables as
/// well as the working directory of the child process.
pub fn process(&self, cmd: CommandType, pkg: &Package)
-> CargoResult<CommandPrototype> {
-> CargoResult<ProcessBuilder> {
let mut search_path = vec![];

// Add -L arguments, after stripping off prefixes like "native=" or "framework=".
Expand All @@ -121,7 +131,12 @@ impl<'cfg> Compilation<'cfg> {
search_path.extend(util::dylib_path().into_iter());
let search_path = try!(util::join_paths(&search_path,
util::dylib_path_envvar()));
let mut cmd = try!(CommandPrototype::new(cmd, self.config));
let mut cmd = match cmd {
CommandType::Rustc => try!(self.config.rustc()).process(),
CommandType::Rustdoc => process(&*try!(self.config.rustdoc())),
CommandType::Target(ref s) |
CommandType::Host(ref s) => process(s),
};
cmd.env(util::dylib_path_envvar(), &search_path);
if let Some(env) = self.extra_env.get(pkg.package_id()) {
for &(ref k, ref v) in env {
Expand Down
49 changes: 24 additions & 25 deletions src/cargo/ops/cargo_rustc/custom_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use util::{internal, ChainError, profile, paths};

use super::job::Work;
use super::{fingerprint, Kind, Context, Unit};
use super::CommandType;
use super::compilation::CommandType;

/// Contains the parsed output of a custom build script.
#[derive(Clone, Debug, Hash)]
Expand Down Expand Up @@ -98,30 +98,30 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>)
// package's library profile.
let profile = cx.lib_profile(unit.pkg.package_id());
let to_exec = to_exec.into_os_string();
let mut p = try!(super::process(CommandType::Host(to_exec), unit.pkg, cx));
p.env("OUT_DIR", &build_output)
.env("CARGO_MANIFEST_DIR", unit.pkg.root())
.env("NUM_JOBS", &cx.jobs().to_string())
.env("TARGET", &match unit.kind {
Kind::Host => cx.host_triple(),
Kind::Target => cx.target_triple(),
})
.env("DEBUG", &profile.debuginfo.to_string())
.env("OPT_LEVEL", &profile.opt_level)
.env("PROFILE", if cx.build_config.release {"release"} else {"debug"})
.env("HOST", cx.host_triple())
.env("RUSTC", &try!(cx.config.rustc()).path)
.env("RUSTDOC", &*try!(cx.config.rustdoc()));

if let Some(links) = unit.pkg.manifest().links(){
p.env("CARGO_MANIFEST_LINKS", links);
}
let mut cmd = try!(super::process(CommandType::Host(to_exec), unit.pkg, cx));
cmd.env("OUT_DIR", &build_output)
.env("CARGO_MANIFEST_DIR", unit.pkg.root())
.env("NUM_JOBS", &cx.jobs().to_string())
.env("TARGET", &match unit.kind {
Kind::Host => cx.host_triple(),
Kind::Target => cx.target_triple(),
})
.env("DEBUG", &profile.debuginfo.to_string())
.env("OPT_LEVEL", &profile.opt_level)
.env("PROFILE", if cx.build_config.release { "release" } else { "debug" })
.env("HOST", cx.host_triple())
.env("RUSTC", &try!(cx.config.rustc()).path)
.env("RUSTDOC", &*try!(cx.config.rustdoc()));

if let Some(links) = unit.pkg.manifest().links() {
cmd.env("CARGO_MANIFEST_LINKS", links);
}

// Be sure to pass along all enabled features for this package, this is the
// last piece of statically known information that we have.
if let Some(features) = cx.resolve.features(unit.pkg.package_id()) {
for feat in features.iter() {
p.env(&format!("CARGO_FEATURE_{}", super::envify(feat)), "1");
cmd.env(&format!("CARGO_FEATURE_{}", super::envify(feat)), "1");
}
}

Expand Down Expand Up @@ -192,19 +192,18 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>)
}));
let data = &state.metadata;
for &(ref key, ref value) in data.iter() {
p.env(&format!("DEP_{}_{}", super::envify(&name),
super::envify(key)), value);
cmd.env(&format!("DEP_{}_{}", super::envify(&name),
super::envify(key)), value);
}
}
if let Some(build_scripts) = build_scripts {
try!(super::add_plugin_deps(&mut p, &build_state,
try!(super::add_plugin_deps(&mut cmd, &build_state,
&build_scripts));
}
}

// And now finally, run the build command itself!
state.running(&p);
let cmd = p.into_process_builder();
state.running(&cmd);
let output = try!(cmd.exec_with_streaming(
&mut |out_line| { state.stdout(out_line); Ok(()) },
&mut |err_line| { state.stderr(err_line); Ok(()) },
Expand Down
5 changes: 2 additions & 3 deletions src/cargo/ops/cargo_rustc/job_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ use term::color::YELLOW;

use core::{PackageId, Target, Profile};
use util::{Config, DependencyQueue, Fresh, Dirty, Freshness};
use util::{CargoResult, profile, internal};
use util::{CargoResult, ProcessBuilder, profile, internal};

use super::{Context, Kind, Unit};
use super::job::Job;
use super::command::CommandPrototype;

/// A management structure of the entire dependency graph to compile.
///
Expand Down Expand Up @@ -64,7 +63,7 @@ enum Message {
}

impl<'a> JobState<'a> {
pub fn running(&self, cmd: &CommandPrototype) {
pub fn running(&self, cmd: &ProcessBuilder) {
let _ = self.tx.send((self.key, Message::Run(cmd.to_string())));
}

Expand Down
Loading