Skip to content

Commit 8e87b19

Browse files
committed
refactor: Add UserIntent::Install
1 parent bb34b9d commit 8e87b19

File tree

5 files changed

+24
-17
lines changed

5 files changed

+24
-17
lines changed

src/bin/cargo/commands/install.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
216216

217217
let mut compile_opts = args.compile_options(
218218
gctx,
219-
UserIntent::Build,
219+
UserIntent::Install,
220220
workspace.as_ref(),
221221
ProfileChecking::Custom,
222222
)?;

src/cargo/core/compiler/build_config.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,10 @@ impl CompileMode {
301301
pub enum UserIntent {
302302
/// Build benchmark binaries, e.g., `cargo bench`
303303
Bench,
304-
/// Build binaries and libraries, e.g., `cargo run`, `cargo install`, `cargo build`.
304+
/// Build binaries and libraries, e.g., `cargo run`, `cargo build`, `cargo rustc`.
305305
Build,
306+
/// Build binaries and libraries for installing, e.g. `cargo install`.
307+
Install,
306308
/// Perform type-check, e.g., `cargo check`.
307309
Check { test: bool },
308310
/// Document packages.

src/cargo/ops/cargo_compile/compile_filter.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -219,17 +219,18 @@ impl CompileFilter {
219219
match intent {
220220
UserIntent::Test | UserIntent::Doctest | UserIntent::Bench => true,
221221
UserIntent::Check { test: true } => true,
222-
UserIntent::Build | UserIntent::Doc { .. } | UserIntent::Check { test: false } => {
223-
match *self {
224-
CompileFilter::Default { .. } => false,
225-
CompileFilter::Only {
226-
ref examples,
227-
ref tests,
228-
ref benches,
229-
..
230-
} => examples.is_specific() || tests.is_specific() || benches.is_specific(),
231-
}
232-
}
222+
UserIntent::Build
223+
| UserIntent::Install
224+
| UserIntent::Doc { .. }
225+
| UserIntent::Check { test: false } => match *self {
226+
CompileFilter::Default { .. } => false,
227+
CompileFilter::Only {
228+
ref examples,
229+
ref tests,
230+
ref benches,
231+
..
232+
} => examples.is_specific() || tests.is_specific() || benches.is_specific(),
233+
},
233234
}
234235
}
235236

src/cargo/ops/cargo_compile/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,11 @@ pub fn create_bcx<'a, 'gctx>(
228228

229229
// Perform some pre-flight validation.
230230
match build_config.intent {
231-
UserIntent::Test | UserIntent::Build | UserIntent::Check { .. } | UserIntent::Bench => {
231+
UserIntent::Test
232+
| UserIntent::Build
233+
| UserIntent::Install
234+
| UserIntent::Check { .. }
235+
| UserIntent::Bench => {
232236
if ws.gctx().get_env("RUST_FLAGS").is_ok() {
233237
gctx.shell().warn(
234238
"Cargo does not read `RUST_FLAGS` environment variable. Did you mean `RUSTFLAGS`?",

src/cargo/ops/cargo_compile/unit_generator.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl<'a> UnitGenerator<'a, '_> {
182182
.iter()
183183
.filter(|t| t.tested() || t.is_example())
184184
.collect(),
185-
UserIntent::Build | UserIntent::Check { .. } => targets
185+
UserIntent::Build | UserIntent::Install | UserIntent::Check { .. } => targets
186186
.iter()
187187
.filter(|t| t.is_bin() || t.is_lib())
188188
.collect(),
@@ -453,7 +453,7 @@ impl<'a> UnitGenerator<'a, '_> {
453453
FilterRule::Just(_) => Target::is_test,
454454
};
455455
let test_mode = match self.intent {
456-
UserIntent::Build => CompileMode::Test,
456+
UserIntent::Build | UserIntent::Install => CompileMode::Test,
457457
UserIntent::Check { .. } => CompileMode::Check { test: true },
458458
_ => default_mode,
459459
};
@@ -775,7 +775,7 @@ Rustdoc did not scrape the following examples because they require dev-dependenc
775775
fn to_compile_mode(intent: UserIntent) -> CompileMode {
776776
match intent {
777777
UserIntent::Test | UserIntent::Bench => CompileMode::Test,
778-
UserIntent::Build => CompileMode::Build,
778+
UserIntent::Build | UserIntent::Install => CompileMode::Build,
779779
UserIntent::Check { test } => CompileMode::Check { test },
780780
UserIntent::Doc { .. } => CompileMode::Doc,
781781
UserIntent::Doctest => CompileMode::Doctest,

0 commit comments

Comments
 (0)