Skip to content

Commit 686c101

Browse files
Make tools which may not build return Option.
This makes it mandatory for other steps to have to handle the potential failure instead of failing in an odd way later down the road.
1 parent 0fcd3e7 commit 686c101

File tree

3 files changed

+65
-53
lines changed

3 files changed

+65
-53
lines changed

src/bootstrap/check.rs

+40-34
Original file line numberDiff line numberDiff line change
@@ -340,25 +340,28 @@ impl Step for Miri {
340340
let host = self.host;
341341
let compiler = builder.compiler(1, host);
342342

343-
let miri = builder.ensure(tool::Miri { compiler, target: self.host });
344-
let mut cargo = builder.cargo(compiler, Mode::Tool, host, "test");
345-
cargo.arg("--manifest-path").arg(build.src.join("src/tools/miri/Cargo.toml"));
346-
347-
// Don't build tests dynamically, just a pain to work with
348-
cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
349-
// miri tests need to know about the stage sysroot
350-
cargo.env("MIRI_SYSROOT", builder.sysroot(compiler));
351-
cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
352-
cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
353-
cargo.env("MIRI_PATH", miri);
354-
355-
builder.add_rustc_lib_path(compiler, &mut cargo);
356-
357-
try_run_expecting(
358-
build,
359-
&mut cargo,
360-
builder.build.config.toolstate.miri.passes(ToolState::Testing),
361-
);
343+
if let Some(miri) = builder.ensure(tool::Miri { compiler, target: self.host }) {
344+
let mut cargo = builder.cargo(compiler, Mode::Tool, host, "test");
345+
cargo.arg("--manifest-path").arg(build.src.join("src/tools/miri/Cargo.toml"));
346+
347+
// Don't build tests dynamically, just a pain to work with
348+
cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
349+
// miri tests need to know about the stage sysroot
350+
cargo.env("MIRI_SYSROOT", builder.sysroot(compiler));
351+
cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
352+
cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
353+
cargo.env("MIRI_PATH", miri);
354+
355+
builder.add_rustc_lib_path(compiler, &mut cargo);
356+
357+
try_run_expecting(
358+
build,
359+
&mut cargo,
360+
builder.build.config.toolstate.miri.passes(ToolState::Testing),
361+
);
362+
} else {
363+
eprintln!("failed to test miri: could not build");
364+
}
362365
}
363366
}
364367

@@ -391,24 +394,27 @@ impl Step for Clippy {
391394
let host = self.host;
392395
let compiler = builder.compiler(stage, host);
393396

394-
let clippy = builder.ensure(tool::Clippy { compiler, target: self.host });
395-
let mut cargo = builder.cargo(compiler, Mode::Tool, host, "test");
396-
cargo.arg("--manifest-path").arg(build.src.join("src/tools/clippy/Cargo.toml"));
397+
if let Some(clippy) = builder.ensure(tool::Clippy { compiler, target: self.host }) {
398+
let mut cargo = builder.cargo(compiler, Mode::Tool, host, "test");
399+
cargo.arg("--manifest-path").arg(build.src.join("src/tools/clippy/Cargo.toml"));
397400

398-
// Don't build tests dynamically, just a pain to work with
399-
cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
400-
// clippy tests need to know about the stage sysroot
401-
cargo.env("SYSROOT", builder.sysroot(compiler));
402-
// clippy tests need to find the driver
403-
cargo.env("CLIPPY_DRIVER_PATH", clippy);
401+
// Don't build tests dynamically, just a pain to work with
402+
cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
403+
// clippy tests need to know about the stage sysroot
404+
cargo.env("SYSROOT", builder.sysroot(compiler));
405+
// clippy tests need to find the driver
406+
cargo.env("CLIPPY_DRIVER_PATH", clippy);
404407

405-
builder.add_rustc_lib_path(compiler, &mut cargo);
408+
builder.add_rustc_lib_path(compiler, &mut cargo);
406409

407-
try_run_expecting(
408-
build,
409-
&mut cargo,
410-
builder.build.config.toolstate.clippy.passes(ToolState::Testing),
411-
);
410+
try_run_expecting(
411+
build,
412+
&mut cargo,
413+
builder.build.config.toolstate.clippy.passes(ToolState::Testing),
414+
);
415+
} else {
416+
eprintln!("failed to test clippy: could not build");
417+
}
412418
}
413419
}
414420

src/bootstrap/dist.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1073,10 +1073,12 @@ impl Step for Rls {
10731073
t!(fs::create_dir_all(&image));
10741074

10751075
// Prepare the image directory
1076+
// We expect RLS to build, because we've exited this step above if tool
1077+
// state for RLS isn't testing.
10761078
let rls = builder.ensure(tool::Rls {
10771079
compiler: builder.compiler(stage, build.build),
10781080
target
1079-
});
1081+
}).expect("Rls to build: toolstate is testing");
10801082
install(&rls, &image.join("bin"), 0o755);
10811083
let doc = image.join("share/doc/rls");
10821084
install(&src.join("README.md"), &doc, 0o644);

src/bootstrap/tool.rs

+22-18
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ struct ToolBuild {
8686
}
8787

8888
impl Step for ToolBuild {
89-
type Output = PathBuf;
89+
type Output = Option<PathBuf>;
9090

9191
fn should_run(run: ShouldRun) -> ShouldRun {
9292
run.never()
@@ -96,7 +96,7 @@ impl Step for ToolBuild {
9696
///
9797
/// This will build the specified tool with the specified `host` compiler in
9898
/// `stage` into the normal cargo output directory.
99-
fn run(self, builder: &Builder) -> PathBuf {
99+
fn run(self, builder: &Builder) -> Option<PathBuf> {
100100
let build = builder.build;
101101
let compiler = self.compiler;
102102
let target = self.target;
@@ -116,11 +116,15 @@ impl Step for ToolBuild {
116116

117117
let mut cargo = prepare_tool_cargo(builder, compiler, target, "build", path);
118118
build.run_expecting(&mut cargo, expectation);
119-
let cargo_out = build.cargo_out(compiler, Mode::Tool, target)
120-
.join(exe(tool, &compiler.host));
121-
let bin = build.tools_dir(compiler).join(exe(tool, &compiler.host));
122-
copy(&cargo_out, &bin);
123-
bin
119+
if expectation == BuildExpectation::Succeeding || expectation == BuildExpectation::None {
120+
let cargo_out = build.cargo_out(compiler, Mode::Tool, target)
121+
.join(exe(tool, &compiler.host));
122+
let bin = build.tools_dir(compiler).join(exe(tool, &compiler.host));
123+
copy(&cargo_out, &bin);
124+
Some(bin)
125+
} else {
126+
None
127+
}
124128
}
125129
}
126130

@@ -229,7 +233,7 @@ macro_rules! tool {
229233
mode: $mode,
230234
path: $path,
231235
expectation: BuildExpectation::None,
232-
})
236+
}).expect("expected to build -- BuildExpectation::None")
233237
}
234238
}
235239
)+
@@ -277,7 +281,7 @@ impl Step for RemoteTestServer {
277281
mode: Mode::Libstd,
278282
path: "src/tools/remote-test-server",
279283
expectation: BuildExpectation::None,
280-
})
284+
}).expect("expected to build -- BuildExpectation::None")
281285
}
282286
}
283287

@@ -395,7 +399,7 @@ impl Step for Cargo {
395399
mode: Mode::Librustc,
396400
path: "src/tools/cargo",
397401
expectation: BuildExpectation::None,
398-
})
402+
}).expect("BuildExpectation::None - expected to build")
399403
}
400404
}
401405

@@ -406,7 +410,7 @@ pub struct Clippy {
406410
}
407411

408412
impl Step for Clippy {
409-
type Output = PathBuf;
413+
type Output = Option<PathBuf>;
410414
const DEFAULT: bool = true;
411415
const ONLY_HOSTS: bool = true;
412416

@@ -421,7 +425,7 @@ impl Step for Clippy {
421425
});
422426
}
423427

424-
fn run(self, builder: &Builder) -> PathBuf {
428+
fn run(self, builder: &Builder) -> Option<PathBuf> {
425429
// Clippy depends on procedural macros (serde), which requires a full host
426430
// compiler to be available, so we need to depend on that.
427431
builder.ensure(compile::Rustc {
@@ -446,7 +450,7 @@ pub struct Rls {
446450
}
447451

448452
impl Step for Rls {
449-
type Output = PathBuf;
453+
type Output = Option<PathBuf>;
450454
const DEFAULT: bool = true;
451455
const ONLY_HOSTS: bool = true;
452456

@@ -462,7 +466,7 @@ impl Step for Rls {
462466
});
463467
}
464468

465-
fn run(self, builder: &Builder) -> PathBuf {
469+
fn run(self, builder: &Builder) -> Option<PathBuf> {
466470
builder.ensure(native::Openssl {
467471
target: self.target,
468472
});
@@ -490,7 +494,7 @@ pub struct Rustfmt {
490494
}
491495

492496
impl Step for Rustfmt {
493-
type Output = PathBuf;
497+
type Output = Option<PathBuf>;
494498
const DEFAULT: bool = true;
495499
const ONLY_HOSTS: bool = true;
496500

@@ -506,7 +510,7 @@ impl Step for Rustfmt {
506510
});
507511
}
508512

509-
fn run(self, builder: &Builder) -> PathBuf {
513+
fn run(self, builder: &Builder) -> Option<PathBuf> {
510514
builder.ensure(ToolBuild {
511515
compiler: self.compiler,
512516
target: self.target,
@@ -526,7 +530,7 @@ pub struct Miri {
526530
}
527531

528532
impl Step for Miri {
529-
type Output = PathBuf;
533+
type Output = Option<PathBuf>;
530534
const DEFAULT: bool = true;
531535
const ONLY_HOSTS: bool = true;
532536

@@ -542,7 +546,7 @@ impl Step for Miri {
542546
});
543547
}
544548

545-
fn run(self, builder: &Builder) -> PathBuf {
549+
fn run(self, builder: &Builder) -> Option<PathBuf> {
546550
builder.ensure(ToolBuild {
547551
compiler: self.compiler,
548552
target: self.target,

0 commit comments

Comments
 (0)