Skip to content
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

Don't compile on install without binaries #10842

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/bin/cargo/commands/install.rs
Expand Up @@ -4,6 +4,7 @@ use cargo::core::{GitReference, SourceId, Workspace};
use cargo::ops;
use cargo::util::IntoUrl;

use cargo::ops::{CompileFilter, FilterRule, LibRule};
use cargo_util::paths;

pub fn cli() -> App {
Expand Down Expand Up @@ -161,6 +162,17 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
if args.flag("list") {
ops::install_list(root, config)?;
} else {
if !compile_opts.filter.is_specific() {
compile_opts.filter = CompileFilter::Only {
all_targets: false,
lib: LibRule::False,
bins: FilterRule::All,
examples: FilterRule::none(),
tests: FilterRule::none(),
benches: FilterRule::none(),
};
}

ops::install(
config,
root,
Expand Down
10 changes: 6 additions & 4 deletions tests/testsuite/install.rs
Expand Up @@ -725,12 +725,14 @@ fn no_binaries() {
cargo_process("install --path")
.arg(p.root())
.arg("foo")
.with_status(101)
.with_status(0)
.with_stderr(
"\
[ERROR] there is nothing to install in `foo v0.0.1 ([..])`, because it has no binaries[..]
[..]
[..]",
[INSTALLING] foo v0.0.1 ([..])
warning: Target filter `bins` specified, but no targets matched. This is a no-op
[FINISHED] release [optimized] target(s) in [..]
warning: none of the package's binaries are available for install using the selected features
",
)
.run();
}
Expand Down
3 changes: 3 additions & 0 deletions tests/testsuite/required_features.rs
Expand Up @@ -653,6 +653,7 @@ fn install_default_features() {
.with_stderr(
"\
[INSTALLING] foo v0.0.1 ([..])
warning: Target filter `bins` specified, but no targets matched. This is a no-op
[FINISHED] release [optimized] target(s) in [..]
[WARNING] none of the package's binaries are available for install using the selected features
",
Expand Down Expand Up @@ -805,6 +806,7 @@ fn install_multiple_required_features() {
.with_stderr(
"\
[INSTALLING] foo v0.0.1 ([..])
warning: Target filter `bins` specified, but no targets matched. This is a no-op
[FINISHED] release [optimized] target(s) in [..]
[WARNING] none of the package's binaries are available for install using the selected features
",
Expand Down Expand Up @@ -1093,6 +1095,7 @@ Consider enabling them by passing, e.g., `--features=\"bar/a\"`
.with_stderr(
"\
[INSTALLING] foo v0.0.1 ([..])
warning: Target filter `bins` specified, but no targets matched. This is a no-op
[FINISHED] release [optimized] target(s) in [..]
[WARNING] none of the package's binaries are available for install using the selected features
",
Expand Down