Skip to content
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/bin/cargo/commands/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
if let CompileFilter::Default { .. } = opts.filter {
opts.filter = CompileFilter::Only {
all_targets: true,
warn_unmatched: true,
lib: LibRule::Default,
bins: FilterRule::All,
examples: FilterRule::All,
Expand Down
6 changes: 5 additions & 1 deletion src/bin/cargo/commands/install.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::command_prelude::*;

use cargo::core::{GitReference, SourceId};
use cargo::ops;
use cargo::ops::{self, CompileFilter};
use cargo::util::IntoUrl;

pub fn cli() -> App {
Expand Down Expand Up @@ -137,6 +137,10 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
compile_opts.build_config.requested_profile =
args.get_profile_name(config, "release", ProfileChecking::Custom)?;

if !compile_opts.filter.is_specific() {
compile_opts.filter = CompileFilter::new_bare_install();
}

if args.is_present("list") {
ops::install_list(root, config)?;
} else {
Expand Down
38 changes: 36 additions & 2 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ pub enum CompileFilter {
},
Only {
all_targets: bool,
/// Flag whether to warn when there are unmatched target filters, defaulting to true.
warn_unmatched: bool,
lib: LibRule,
bins: FilterRule,
examples: FilterRule,
Expand Down Expand Up @@ -714,6 +716,7 @@ impl CompileFilter {
{
CompileFilter::Only {
all_targets: false,
warn_unmatched: true,
lib: rule_lib,
bins: rule_bins,
examples: rule_exms,
Expand All @@ -730,6 +733,7 @@ impl CompileFilter {
pub fn new_all_targets() -> CompileFilter {
CompileFilter::Only {
all_targets: true,
warn_unmatched: true,
lib: LibRule::Default,
bins: FilterRule::All,
examples: FilterRule::All,
Expand All @@ -738,6 +742,19 @@ impl CompileFilter {
}
}

/// Construct a CompileFilter with default options for use by `cargo install`
pub fn new_bare_install() -> CompileFilter {
CompileFilter::Only {
all_targets: false,
warn_unmatched: false,
lib: LibRule::False,
bins: FilterRule::All,
examples: FilterRule::none(),
benches: FilterRule::none(),
tests: FilterRule::none(),
}
}

pub fn need_dev_deps(&self, mode: CompileMode) -> bool {
match mode {
CompileMode::Test | CompileMode::Doctest | CompileMode::Bench => true,
Expand Down Expand Up @@ -796,6 +813,21 @@ impl CompileFilter {
}
}

pub fn is_bare_install(&self) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little unclear, why doesn't this just check for the warn_unmatched value?

match *self {
CompileFilter::Default { .. } => false,
CompileFilter::Only {
bins: FilterRule::All,
ref examples,
..
} => match examples {
FilterRule::All => false,
FilterRule::Just(ref targets) => targets.is_empty(),
},
_ => !self.is_specific(),
}
}

pub fn is_all_targets(&self) -> bool {
matches!(
*self,
Expand Down Expand Up @@ -1003,6 +1035,7 @@ fn generate_targets(
ref examples,
ref tests,
ref benches,
..
} => {
if *lib != LibRule::False {
let mut libs = Vec::new();
Expand Down Expand Up @@ -1158,14 +1191,15 @@ fn unmatched_target_filters(
) -> CargoResult<()> {
if let CompileFilter::Only {
all_targets,
lib: _,
warn_unmatched,
ref bins,
ref examples,
ref tests,
ref benches,
..
} = *filter
{
if units.is_empty() {
if units.is_empty() && warn_unmatched {
let mut filters = String::new();
let mut miss_count = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl<'cfg, 'a> InstallablePackage<'cfg, 'a> {
// For bare `cargo install` (no `--bin` or `--example`), check if there is
// *something* to install. Explicit `--bin` or `--example` flags will be
// checked at the start of `compile_ws`.
if !opts.filter.is_specific() && !pkg.targets().iter().any(|t| t.is_bin()) {
if opts.filter.is_bare_install() && !pkg.targets().iter().any(|t| t.is_bin()) {
bail!(
"there is nothing to install in `{}`, because it has no binaries\n\
`cargo install` is only for installing programs, and can't be used with libraries.\n\
Expand Down