diff --git a/src/bin/command_prelude.rs b/src/bin/command_prelude.rs index 2583f249980..96d857c7ee1 100644 --- a/src/bin/command_prelude.rs +++ b/src/bin/command_prelude.rs @@ -4,7 +4,7 @@ use std::fs; use clap::{self, SubCommand}; use cargo::CargoResult; use cargo::core::{Workspace, Package, PackageIdSpec}; -use cargo::ops::{CompileFilter, CompileMode, CompileOptions, MessageFormat, NewOptions, Packages, +use cargo::ops::{CompileFilter, CompileMode, CompileOptions, MessageFormat, NewOptions, VersionControl, RequestedPackages}; use cargo::util::paths; use cargo::util::important_paths::find_root_manifest_for_wd; @@ -252,8 +252,11 @@ pub trait ArgMatchesExt { ws: &Workspace<'a>, mode: CompileMode, ) -> CargoResult> { - let mut compile_opts = self.compile_options(ws, mode)?; - compile_opts.spec = Packages::Packages(self._values_of("package")); + let compile_opts = self.compile_options(ws, mode)?; + if compile_opts.requested.specs.len() != 1 { + ws.current()?; + unreachable!("More than one package requested => current should be Err") + } Ok(compile_opts) } @@ -317,12 +320,6 @@ pub trait ArgMatchesExt { } }; - let spec = Packages::from_flags( - self._is_present("all"), - self._values_of("exclude"), - self._values_of("package"), - )?; - let message_format = match self._value_of("message-format") { None => MessageFormat::Human, Some(f) => { @@ -343,7 +340,6 @@ pub trait ArgMatchesExt { features: self._values_of("features"), all_features: self._is_present("all-features"), no_default_features: self._is_present("no-default-features"), - spec, requested, mode, release: self._is_present("release"), diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 12621750ea5..3053523addc 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -50,7 +50,6 @@ pub struct CompileOptions<'a> { /// Flag if the default feature should be built for the root package pub no_default_features: bool, /// A set of packages to build. - pub spec: Packages, pub requested: RequestedPackages, /// Filter to apply to the root package to select which targets will be /// built. @@ -84,7 +83,6 @@ impl<'a> CompileOptions<'a> { features: Vec::new(), all_features: false, no_default_features: false, - spec: ops::Packages::Packages(Vec::new()), requested: RequestedPackages::default(), mode, release: false, @@ -161,26 +159,6 @@ impl RequestedPackages { } } -#[derive(Clone, PartialEq, Eq, Debug)] -pub enum Packages { - Default, - All, - OptOut(Vec), - Packages(Vec), -} - -impl Packages { - pub fn from_flags(all: bool, exclude: Vec, package: Vec) -> CargoResult { - Ok(match (all, exclude.len(), package.len()) { - (false, 0, 0) => Packages::Default, - (false, 0, _) => Packages::Packages(package), - (false, _, _) => bail!("--exclude can only be used together with --all"), - (true, 0, _) => Packages::All, - (true, _, _) => Packages::OptOut(exclude), - }) - } -} - #[derive(Debug)] pub enum FilterRule { All, @@ -242,7 +220,6 @@ pub fn compile_ws<'a>( config, jobs, ref target, - spec: _, ref features, all_features, no_default_features, diff --git a/src/cargo/ops/cargo_package.rs b/src/cargo/ops/cargo_package.rs index be19a203298..78c2f190f02 100644 --- a/src/cargo/ops/cargo_package.rs +++ b/src/cargo/ops/cargo_package.rs @@ -343,7 +343,6 @@ fn run_verify(ws: &Workspace, tar: &FileLock, opts: &PackageOpts) -> CargoResult features: Vec::new(), no_default_features: false, all_features: false, - spec: ops::Packages::Packages(Vec::new()), requested, filter: ops::CompileFilter::Default { required_features_filterable: true, diff --git a/src/cargo/ops/cargo_run.rs b/src/cargo/ops/cargo_run.rs index b609a0ea376..a1502bc5a03 100644 --- a/src/cargo/ops/cargo_run.rs +++ b/src/cargo/ops/cargo_run.rs @@ -1,6 +1,6 @@ use std::path::Path; -use ops::{self, Packages}; +use ops; use util::{self, CargoResult, ProcessError}; use core::Workspace; @@ -9,21 +9,19 @@ pub fn run( options: &ops::CompileOptions, args: &[String], ) -> CargoResult> { - let config = ws.config(); - - let pkg = match options.spec { - Packages::All | Packages::Default | Packages::OptOut(_) => { - unreachable!("cargo run supports single package only") - } - Packages::Packages(ref xs) => match xs.len() { - 0 => ws.current()?, - 1 => ws.members() - .find(|pkg| *pkg.name() == xs[0]) - .ok_or_else(|| { - format_err!("package `{}` is not a member of the workspace", xs[0]) - })?, - _ => unreachable!("cargo run supports single package only"), - }, + let pkg = { + let spec = if options.requested.specs.len() == 1 { + &options.requested.specs[0] + } else { + unreachable!( + "cargo run supports single package only, handled at the argument parsing layer" + ) + }; + ws.members() + .find(|pkg| spec.matches(pkg.package_id())) + .ok_or_else(|| { + format_err!("package `{}` is not a member of the workspace", spec) + })? }; let bins: Vec<_> = pkg.manifest() @@ -65,6 +63,7 @@ pub fn run( let compile = ops::compile(ws, options)?; assert_eq!(compile.binaries.len(), 1); let exe = &compile.binaries[0]; + let config = ws.config(); let exe = match util::without_prefix(exe, config.cwd()) { Some(path) if path.file_name() == Some(path.as_os_str()) => { Path::new(".").join(path).to_path_buf() diff --git a/src/cargo/ops/mod.rs b/src/cargo/ops/mod.rs index cfcf272f0fd..87bc5dc995a 100644 --- a/src/cargo/ops/mod.rs +++ b/src/cargo/ops/mod.rs @@ -1,6 +1,6 @@ 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, FilterRule, MessageFormat, Packages, RequestedPackages}; +pub use self::cargo_compile::{CompileFilter, CompileMode, FilterRule, MessageFormat, RequestedPackages}; pub use self::cargo_read_manifest::{read_package, read_packages}; pub use self::cargo_run::run; pub use self::cargo_install::{install, install_list, uninstall};