Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d94e7ff

Browse files
refactor cargo invocations with strongly-typed subcommand
Signed-off-by: onur-ozkan <work@onurozkan.dev>
1 parent a526d7c commit d94e7ff

File tree

9 files changed

+117
-109
lines changed

9 files changed

+117
-109
lines changed

‎src/bootstrap/src/core/build_steps/check.rs‎

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,6 @@ use crate::core::config::TargetSelection;
1111
use crate::{Compiler, Mode, Subcommand};
1212
use std::path::{Path, PathBuf};
1313

14-
pub fn cargo_subcommand(kind: Kind) -> &'static str {
15-
match kind {
16-
Kind::Check
17-
// We ensure check steps for both std and rustc from build_steps/clippy, so handle `Kind::Clippy` as well.
18-
| Kind::Clippy => "check",
19-
Kind::Fix => "fix",
20-
_ => unreachable!(),
21-
}
22-
}
23-
2414
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2515
pub struct Std {
2616
pub target: TargetSelection,
@@ -63,7 +53,7 @@ impl Step for Std {
6353
Mode::Std,
6454
SourceType::InTree,
6555
target,
66-
cargo_subcommand(builder.kind),
56+
builder.kind,
6757
);
6858

6959
std_cargo(builder, target, compiler.stage, &mut cargo);
@@ -117,7 +107,7 @@ impl Step for Std {
117107
Mode::Std,
118108
SourceType::InTree,
119109
target,
120-
cargo_subcommand(builder.kind),
110+
builder.kind,
121111
);
122112

123113
// If we're not in stage 0, tests and examples will fail to compile
@@ -212,7 +202,7 @@ impl Step for Rustc {
212202
Mode::Rustc,
213203
SourceType::InTree,
214204
target,
215-
cargo_subcommand(builder.kind),
205+
builder.kind,
216206
);
217207

218208
rustc_cargo(builder, &mut cargo, target, &compiler);
@@ -290,7 +280,7 @@ impl Step for CodegenBackend {
290280
Mode::Codegen,
291281
SourceType::InTree,
292282
target,
293-
cargo_subcommand(builder.kind),
283+
builder.kind,
294284
);
295285

296286
cargo
@@ -348,7 +338,7 @@ impl Step for RustAnalyzer {
348338
compiler,
349339
Mode::ToolRustc,
350340
target,
351-
cargo_subcommand(builder.kind),
341+
builder.kind,
352342
"src/tools/rust-analyzer",
353343
SourceType::InTree,
354344
&["in-rust-tree".to_owned()],
@@ -416,7 +406,7 @@ macro_rules! tool_check_step {
416406
compiler,
417407
Mode::ToolRustc,
418408
target,
419-
cargo_subcommand(builder.kind),
409+
builder.kind,
420410
$path,
421411
$source_type,
422412
&[],

‎src/bootstrap/src/core/build_steps/clean.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::path::Path;
1111

1212
use crate::core::builder::{crate_description, Builder, RunConfig, ShouldRun, Step};
1313
use crate::utils::helpers::t;
14-
use crate::{Build, Compiler, Mode, Subcommand};
14+
use crate::{Build, Compiler, Kind,Mode, Subcommand};
1515

1616
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1717
pub struct CleanAll {}
@@ -66,7 +66,7 @@ macro_rules! clean_crate_tree {
6666
fn run(self, builder: &Builder<'_>) -> Self::Output {
6767
let compiler = self.compiler;
6868
let target = compiler.host;
69-
let mut cargo = builder.bare_cargo(compiler, $mode, target, "clean");
69+
let mut cargo = builder.bare_cargo(compiler, $mode, target, Kind::Clean);
7070

7171
// Since https://github.com/rust-lang/rust/pull/111076 enables
7272
// unstable cargo feature (`public-dependency`), we need to ensure

‎src/bootstrap/src/core/build_steps/clippy.rs‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,14 @@ impl Step for Std {
132132
let target = self.target;
133133
let compiler = builder.compiler(builder.top_stage, builder.config.build);
134134

135-
let mut cargo =
136-
builder::Cargo::new(builder, compiler, Mode::Std, SourceType::InTree, target, "clippy");
135+
let mut cargo = builder::Cargo::new(
136+
builder,
137+
compiler,
138+
Mode::Std,
139+
SourceType::InTree,
140+
target,
141+
Kind::Clippy,
142+
);
137143

138144
std_cargo(builder, target, compiler.stage, &mut cargo);
139145

@@ -203,7 +209,7 @@ impl Step for Rustc {
203209
Mode::Rustc,
204210
SourceType::InTree,
205211
target,
206-
"clippy",
212+
Kind::Clippy,
207213
);
208214

209215
rustc_cargo(builder, &mut cargo, target, &compiler);
@@ -268,7 +274,7 @@ macro_rules! lint_any {
268274
compiler,
269275
Mode::ToolRustc,
270276
target,
271-
"clippy",
277+
Kind::Clippy,
272278
$path,
273279
SourceType::InTree,
274280
&[],

‎src/bootstrap/src/core/build_steps/compile.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ impl Step for Std {
246246
Mode::Std,
247247
SourceType::InTree,
248248
target,
249-
"check",
249+
Kind::Check,
250250
);
251251
cargo.rustflag("-Zalways-encode-mir");
252252
cargo.arg("--manifest-path").arg(builder.src.join("library/sysroot/Cargo.toml"));
@@ -258,7 +258,7 @@ impl Step for Std {
258258
Mode::Std,
259259
SourceType::InTree,
260260
target,
261-
"build",
261+
Kind::Build,
262262
);
263263
std_cargo(builder, target, compiler.stage, &mut cargo);
264264
for krate in &*self.crates {
@@ -916,7 +916,7 @@ impl Step for Rustc {
916916
Mode::Rustc,
917917
SourceType::InTree,
918918
target,
919-
"build",
919+
Kind::Build,
920920
);
921921

922922
rustc_cargo(builder, &mut cargo, target, &compiler);
@@ -1356,7 +1356,7 @@ impl Step for CodegenBackend {
13561356
Mode::Codegen,
13571357
SourceType::InTree,
13581358
target,
1359-
"build",
1359+
Kind::Build,
13601360
);
13611361
cargo
13621362
.arg("--manifest-path")

‎src/bootstrap/src/core/build_steps/doc.rs‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ fn doc_std(
712712
let out_dir = target_dir.join(target.triple).join("doc");
713713

714714
let mut cargo =
715-
builder::Cargo::new(builder, compiler, Mode::Std, SourceType::InTree, target, "doc");
715+
builder::Cargo::new(builder, compiler, Mode::Std, SourceType::InTree, target, Kind::Doc);
716716

717717
compile::std_cargo(builder, target, compiler.stage, &mut cargo);
718718
cargo
@@ -814,8 +814,14 @@ impl Step for Rustc {
814814
);
815815

816816
// Build cargo command.
817-
let mut cargo =
818-
builder::Cargo::new(builder, compiler, Mode::Rustc, SourceType::InTree, target, "doc");
817+
let mut cargo = builder::Cargo::new(
818+
builder,
819+
compiler,
820+
Mode::Rustc,
821+
SourceType::InTree,
822+
target,
823+
Kind::Doc,
824+
);
819825

820826
cargo.rustdocflag("--document-private-items");
821827
// Since we always pass --document-private-items, there's no need to warn about linking to private items.
@@ -962,7 +968,7 @@ macro_rules! tool_doc {
962968
compiler,
963969
Mode::ToolRustc,
964970
target,
965-
"doc",
971+
Kind::Doc,
966972
$path,
967973
source_type,
968974
&[],

‎src/bootstrap/src/core/build_steps/run.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::path::PathBuf;
88
use crate::core::build_steps::dist::distdir;
99
use crate::core::build_steps::test;
1010
use crate::core::build_steps::tool::{self, SourceType, Tool};
11-
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
11+
use crate::core::builder::{Builder, Kind,RunConfig, ShouldRun, Step};
1212
use crate::core::config::flags::get_completion;
1313
use crate::core::config::TargetSelection;
1414
use crate::utils::exec::command;
@@ -142,7 +142,7 @@ impl Step for Miri {
142142
host_compiler,
143143
Mode::ToolRustc,
144144
host,
145-
"run",
145+
Kind::Run,
146146
"src/tools/miri",
147147
SourceType::InTree,
148148
&[],

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /