Accept -j as a command-line parameter

This parameter will be used to control the number of concurrent builds that
cargo has executing.
This commit is contained in:
Alex Crichton 2014-06-28 16:54:16 -07:00
parent 33b77bb059
commit 3db6c2ffa4
5 changed files with 33 additions and 12 deletions

View file

@ -21,11 +21,13 @@ use cargo::util::important_paths::find_project_manifest;
#[deriving(PartialEq,Clone,Decodable,Encodable)]
pub struct Options {
manifest_path: Option<String>,
update_remotes: bool
update_remotes: bool,
jobs: Option<uint>,
}
hammer_config!(Options "Build the current project", |c| {
c.short("update_remotes", 'u')
.short("jobs", 'j')
})
fn main() {
@ -46,8 +48,9 @@ fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
};
let update = options.update_remotes;
let jobs = options.jobs;
ops::compile(&root, update, "compile", shell).map(|_| None).map_err(|err| {
ops::compile(&root, update, "compile", shell, jobs).map(|_| None).map_err(|err| {
CliError::from_boxed(err, 101)
})
}

View file

@ -37,7 +37,9 @@ fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
let source_id = SourceId::for_git(&url, reference.as_slice());
let mut config = try!(Config::new(shell, true).map_err(|e| CliError::from_boxed(e, 1)));
let mut config = try!(Config::new(shell, true, None).map_err(|e| {
CliError::from_boxed(e, 1)
}));
let mut source = GitSource::new(&source_id, &mut config);
try!(source.update().map_err(|e| {

View file

@ -21,10 +21,13 @@ use cargo::util::important_paths::find_project_manifest;
#[deriving(PartialEq,Clone,Decodable)]
struct Options {
manifest_path: Option<String>,
rest: Vec<String>
jobs: Option<uint>,
rest: Vec<String>,
}
hammer_config!(Options "Run the package's test suite")
hammer_config!(Options "Run the package's test suite", |c| {
c.short("jobs", 'j')
})
fn main() {
execute_main_without_stdin(execute);
@ -41,7 +44,8 @@ fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
}))
};
try!(ops::compile(&root, false, "test", shell).map(|_| None::<()>).map_err(|err| {
try!(ops::compile(&root, false, "test", shell, options.jobs)
.map(|_| None::<()>).map_err(|err| {
CliError::from_boxed(err, 101)
}));

View file

@ -31,7 +31,8 @@ use sources::{PathSource};
use util::{CargoResult, Wrap, config, internal, human};
pub fn compile(manifest_path: &Path, update: bool,
env: &str, shell: &mut MultiShell) -> CargoResult<()>
env: &str, shell: &mut MultiShell,
jobs: Option<uint>) -> CargoResult<()>
{
log!(4, "compile; manifest-path={}", manifest_path.display());
@ -51,7 +52,7 @@ pub fn compile(manifest_path: &Path, update: bool,
let source_ids = package.get_source_ids();
let packages = {
let mut config = try!(Config::new(shell, update));
let mut config = try!(Config::new(shell, update, jobs));
let mut registry =
try!(PackageRegistry::new(source_ids, override_ids, &mut config));
@ -70,7 +71,7 @@ pub fn compile(manifest_path: &Path, update: bool,
target.get_profile().get_env() == env
}).collect::<Vec<&Target>>();
let mut config = try!(Config::new(shell, update));
let mut config = try!(Config::new(shell, update, jobs));
try!(ops::compile_targets(targets.as_slice(), &package,
&PackageSet::new(packages.as_slice()), &mut config));

View file

@ -10,18 +10,25 @@ use cargo_toml = util::toml;
pub struct Config<'a> {
home_path: Path,
update_remotes: bool,
shell: &'a mut MultiShell
shell: &'a mut MultiShell,
jobs: uint,
}
impl<'a> Config<'a> {
pub fn new<'a>(shell: &'a mut MultiShell, update_remotes: bool) -> CargoResult<Config<'a>> {
pub fn new<'a>(shell: &'a mut MultiShell,
update_remotes: bool,
jobs: Option<uint>) -> CargoResult<Config<'a>> {
if jobs == Some(0) {
return Err(human("jobs must be at least 1"))
}
Ok(Config {
home_path: try!(os::homedir().require(|| {
human("Cargo couldn't find your home directory. \
This probably means that $HOME was not set.")
})),
update_remotes: update_remotes,
shell: shell
shell: shell,
jobs: jobs.unwrap_or(os::num_cpus()),
})
}
@ -40,6 +47,10 @@ impl<'a> Config<'a> {
pub fn update_remotes(&mut self) -> bool {
self.update_remotes
}
pub fn jobs(&mut self) -> uint {
self.jobs
}
}
#[deriving(Eq,PartialEq,Clone,Encodable,Decodable)]