Skip to content

Implement install --all #5060

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

Closed
Closed
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
23 changes: 21 additions & 2 deletions src/bin/install.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use cargo::ops;
use cargo::core::{SourceId, GitReference};
use cargo::core::{SourceId, GitReference, Workspace};
use cargo::core::manifest::Target;
use cargo::util::important_paths::{find_root_manifest_for_wd};
use cargo::util::{CliResult, Config, ToUrl};

#[derive(Deserialize)]
Expand All @@ -21,6 +23,7 @@ pub struct Options {
flag_force: bool,
flag_frozen: bool,
flag_locked: bool,
flag_all: bool,

arg_crate: Vec<String>,
flag_vers: Option<String>,
Expand Down Expand Up @@ -54,6 +57,7 @@ Specifying what crate to install:

Build and install options:
-h, --help Print this message
--all Install all crates from the workspace
-j N, --jobs N Number of parallel jobs, defaults to # of CPUs
-f, --force Force overwriting existing crates or binaries
--features FEATURES Space-separated list of features to activate
Expand Down Expand Up @@ -106,6 +110,9 @@ specified by setting the `CARGO_TARGET_DIR` environment variable to a relative
path. In particular, this can be useful for caching build artifacts on
continuous integration systems.

All packages in the workspace are built if the `--all` flag is supplied. The
`--all` flag is automatically assumed for a virtual manifest.

The `--list` option will list all installed packages (and their versions).
";

Expand Down Expand Up @@ -158,7 +165,19 @@ pub fn execute(options: Options, config: &mut Config) -> CliResult {
SourceId::crates_io(config)?
};

let krates = options.arg_crate.iter().map(|s| &s[..]).collect::<Vec<_>>();
let krates = if options.flag_all {
let root = find_root_manifest_for_wd(None, config.cwd())?;
let ws = Workspace::new(&root, config)?;
ws.members()
.filter(|mem| mem.manifest().targets().iter().any(Target::is_bin))
.map(|p| String::from(p.name()))
.collect::<Vec<_>>()
} else {
options.arg_crate
};

let krates = krates.iter().map(|s| &s[..]).collect::<Vec<_>>();

let vers = match (&options.flag_vers, &options.flag_version) {
(&Some(_), &Some(_)) => return Err(format_err!("invalid arguments").into()),
(&Some(ref v), _) | (_, &Some(ref v)) => Some(v.as_ref()),
Expand Down