Skip to content

Commit

Permalink
Jettison Packages struct
Browse files Browse the repository at this point in the history
  • Loading branch information
matklad committed Apr 12, 2018
1 parent dff6d4c commit 51661da
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 51 deletions.
16 changes: 6 additions & 10 deletions src/bin/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -252,8 +252,11 @@ pub trait ArgMatchesExt {
ws: &Workspace<'a>,
mode: CompileMode,
) -> CargoResult<CompileOptions<'a>> {
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)
}

Expand Down Expand Up @@ -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) => {
Expand All @@ -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"),
Expand Down
23 changes: 0 additions & 23 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -161,26 +159,6 @@ impl RequestedPackages {
}
}

#[derive(Clone, PartialEq, Eq, Debug)]
pub enum Packages {
Default,
All,
OptOut(Vec<String>),
Packages(Vec<String>),
}

impl Packages {
pub fn from_flags(all: bool, exclude: Vec<String>, package: Vec<String>) -> CargoResult<Self> {
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,
Expand Down Expand Up @@ -242,7 +220,6 @@ pub fn compile_ws<'a>(
config,
jobs,
ref target,
spec: _,
ref features,
all_features,
no_default_features,
Expand Down
1 change: 0 additions & 1 deletion src/cargo/ops/cargo_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
31 changes: 15 additions & 16 deletions src/cargo/ops/cargo_run.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::path::Path;

use ops::{self, Packages};
use ops;
use util::{self, CargoResult, ProcessError};
use core::Workspace;

Expand All @@ -9,21 +9,19 @@ pub fn run(
options: &ops::CompileOptions,
args: &[String],
) -> CargoResult<Option<ProcessError>> {
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()
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/mod.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down

0 comments on commit 51661da

Please sign in to comment.