use std::env;
-use cargo::ops::{self};
-use cargo::ops::cargo_check::{Options, with_check_env};
+use cargo::ops::{self, CompileOptions, MessageFormat};
+use cargo::ops::with_check_ws;
use cargo::util::{CliResult, Config};
-
pub const USAGE: &'static str = "
Check a local package and all of its dependencies for errors
the --release flag will use the `release` profile instead.
";
+#[derive(RustcDecodable)]
+pub struct Options {
+ flag_package: Vec<String>,
+ flag_jobs: Option<u32>,
+ flag_features: Vec<String>,
+ flag_all_features: bool,
+ flag_no_default_features: bool,
+ flag_target: Option<String>,
+ flag_manifest_path: Option<String>,
+ flag_verbose: u32,
+ flag_quiet: Option<bool>,
+ flag_color: Option<String>,
+ flag_message_format: MessageFormat,
+ flag_release: bool,
+ flag_lib: bool,
+ flag_bin: Vec<String>,
+ flag_example: Vec<String>,
+ flag_test: Vec<String>,
+ flag_bench: Vec<String>,
+ flag_locked: bool,
+ flag_frozen: bool,
+}
+
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
debug!("executing; cmd=cargo-check; args={:?}",
env::args().collect::<Vec<_>>());
- with_check_env(options, config, |ws, opts| {
- ops::compile(ws, opts)?;
+ config.configure(options.flag_verbose,
+ options.flag_quiet,
+ &options.flag_color,
+ options.flag_frozen,
+ options.flag_locked)?;
+
+ with_check_ws(options.flag_manifest_path.clone(), config, |ws| {
+ let opts = CompileOptions {
+ config: config,
+ jobs: options.flag_jobs,
+ target: options.flag_target.as_ref().map(|t| &t[..]),
+ features: &options.flag_features,
+ all_features: options.flag_all_features,
+ no_default_features: options.flag_no_default_features,
+ spec: ops::Packages::Packages(&options.flag_package),
+ mode: ops::CompileMode::Check,
+ release: options.flag_release,
+ filter: ops::CompileFilter::new(options.flag_lib,
+ &options.flag_bin,
+ &options.flag_test,
+ &options.flag_example,
+ &options.flag_bench),
+ message_format: options.flag_message_format,
+ target_rustdoc_args: None,
+ target_rustc_args: None,
+ };
+
+ ops::compile(ws, &opts)?;
Ok(None)
})
}
use core::Workspace;
-use ops::{self, CompileOptions, MessageFormat};
-use util::important_paths::{find_root_manifest_for_wd};
+use util::important_paths::find_root_manifest_for_wd;
use util::{CliResult, Config};
-#[derive(RustcDecodable)]
-pub struct Options {
- flag_package: Vec<String>,
- flag_jobs: Option<u32>,
- flag_features: Vec<String>,
- flag_all_features: bool,
- flag_no_default_features: bool,
- flag_target: Option<String>,
- flag_manifest_path: Option<String>,
- flag_verbose: u32,
- flag_quiet: Option<bool>,
- flag_color: Option<String>,
- flag_message_format: MessageFormat,
- flag_release: bool,
- flag_lib: bool,
- flag_bin: Vec<String>,
- flag_example: Vec<String>,
- flag_test: Vec<String>,
- flag_bench: Vec<String>,
- flag_locked: bool,
- flag_frozen: bool,
-}
-
-impl Options {
- pub fn default() -> Options {
- Options {
- flag_package: vec![],
- flag_jobs: None,
- flag_features: vec![],
- flag_all_features: false,
- flag_no_default_features: false,
- flag_target: None,
- flag_manifest_path: None,
- flag_verbose: 0,
- flag_quiet: None,
- flag_color: None,
- flag_message_format: MessageFormat::Human,
- flag_release: false,
- flag_lib: false,
- flag_bin: vec![],
- flag_example: vec![],
- flag_test: vec![],
- flag_bench: vec![],
- flag_locked: false,
- flag_frozen: false,
- }
- }
-}
-
-
-pub fn with_check_env<F>(options: Options, config: &Config, f: F) -> CliResult<Option<()>>
- where F: FnOnce(&Workspace, &CompileOptions) -> CliResult<Option<()>>
+pub fn with_check_ws<F>(flag_manifest_path: Option<String>,
+ config: &Config, f: F)
+ -> CliResult<Option<()>>
+ where F: FnOnce(&Workspace) -> CliResult<Option<()>>
{
- config.configure(options.flag_verbose,
- options.flag_quiet,
- &options.flag_color,
- options.flag_frozen,
- options.flag_locked)?;
-
- let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
-
- let opts = CompileOptions {
- config: config,
- jobs: options.flag_jobs,
- target: options.flag_target.as_ref().map(|t| &t[..]),
- features: &options.flag_features,
- all_features: options.flag_all_features,
- no_default_features: options.flag_no_default_features,
- spec: ops::Packages::Packages(&options.flag_package),
- mode: ops::CompileMode::Check,
- release: options.flag_release,
- filter: ops::CompileFilter::new(options.flag_lib,
- &options.flag_bin,
- &options.flag_test,
- &options.flag_example,
- &options.flag_bench),
- message_format: options.flag_message_format,
- target_rustdoc_args: None,
- target_rustc_args: None,
- };
-
+ let root = find_root_manifest_for_wd(flag_manifest_path, config.cwd())?;
let ws = Workspace::new(&root, config)?;
- f(&ws, &opts)
+ f(&ws)
}
pub target_rustc_args: Option<&'a [String]>,
}
+impl<'a> CompileOptions<'a> {
+ pub fn with_default<F, T>(config: &Config, mode: CompileMode, f: F) -> T
+ where F: FnOnce(CompileOptions) -> T
+ {
+ let opts = CompileOptions {
+ config: config,
+ jobs: None,
+ target: None,
+ features: &[],
+ all_features: false,
+ no_default_features: false,
+ spec: ops::Packages::Packages(&[]),
+ mode: mode,
+ release: false,
+ filter: ops::CompileFilter::new(false, &[], &[], &[], &[]),
+ message_format: MessageFormat::Human,
+ target_rustdoc_args: None,
+ target_rustc_args: None,
+ };
+ f(opts)
+ }
+}
+
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum CompileMode {
Test,
/// directly, we'll use an Executor, giving clients an opportunity to intercept
/// the build calls.
pub trait Executor: Clone + Send + 'static {
- fn init(&mut self, cx: &Context);
+ fn init(&mut self, _cx: &Context) {}
/// If execution succeeds, the ContinueBuild value indicates whether Cargo
/// should continue with the build process for this package.
- fn exec(&self, cmd: ProcessBuilder, id: &PackageId) -> Result<ContinueBuild, ProcessError>;
+ fn exec(&self, cmd: ProcessBuilder, _id: &PackageId) -> Result<ContinueBuild, ProcessError> {
+ cmd.exec()?;
+ Ok(ContinueBuild::Continue)
+ }
+
+ fn exec_json<F1, F2>(&self,
+ cmd: ProcessBuilder,
+ _id: &PackageId,
+ mut handle_stdout: F1,
+ mut handle_srderr: F2)
+ -> Result<ContinueBuild, ProcessError>
+ where F1: FnMut(&str) -> CargoResult<()>,
+ F2: FnMut(&str) -> CargoResult<()>,
+ {
+ cmd.exec_with_streaming(&mut handle_stdout, &mut handle_srderr)?;
+ Ok(ContinueBuild::Continue)
+ }
}
/// A DefaultExecutorcalls rustc without doing anything else. It is Cargo's
#[derive(Copy, Clone)]
pub struct DefaultExecutor;
-impl Executor for DefaultExecutor {
- fn init(&mut self, _cx: &Context) {}
-
- fn exec(&self, cmd: ProcessBuilder, _id: &PackageId) -> Result<ContinueBuild, ProcessError> {
- cmd.exec()?;
- Ok(ContinueBuild::Continue)
- }
-}
+impl Executor for DefaultExecutor {}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ContinueBuild {
state.running(&rustc);
let cont = if json_messages {
- rustc.exec_with_streaming(
- &mut |line| if !line.is_empty() {
+ exec.exec_json(rustc, &package_id,
+ |line| if !line.is_empty() {
Err(internal(&format!("compiler stdout is not empty: `{}`", line)))
} else {
Ok(())
},
- &mut |line| {
+ |line| {
// stderr from rustc can have a mix of JSON and non-JSON output
if line.starts_with("{") {
// Handle JSON lines
writeln!(io::stderr(), "{}", line)?;
}
Ok(())
- },
- ).map(|_| ()).chain_error(|| {
+ }
+ ).chain_error(|| {
human(format!("Could not compile `{}`.", name))
- })?;
- ContinueBuild::Continue
+ })?
} else {
exec.exec(rustc, &package_id).chain_error(|| {
human(format!("Could not compile `{}`.", name))
+pub use self::cargo_check::with_check_ws;
pub use self::cargo_clean::{clean, CleanOptions};
pub use self::cargo_compile::{compile, compile_with_exec, compile_ws, CompileOptions};
pub use self::cargo_compile::{CompileFilter, CompileMode, MessageFormat, Packages};
pub use self::resolve::{resolve_ws, resolve_ws_precisely, resolve_with_previous};
pub use self::cargo_output_metadata::{output_metadata, OutputMetadataOptions, ExportInfo};
-pub mod cargo_check;
+mod cargo_check;
mod cargo_clean;
mod cargo_compile;
mod cargo_doc;