Skip to content

Commit bbe9056

Browse files
committed
Add require_and_update_submodule to ensure submodules exist
This adds a new method `require_and_update_submodule` to replace `update_submodule`. This new method will generate an error if the submodule doesn't actually exist. This replaces some ad-hoc checks that were performing this function. This helps ensure that a good error message is always displayed. This also adds require_and_update_all_submodules which does this for all submodules. Ideally this should not have any change other than better error messages when submodules are missing.
1 parent ee75f24 commit bbe9056

File tree

11 files changed

+87
-50
lines changed

11 files changed

+87
-50
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::core::builder::{
99
};
1010
use crate::core::config::TargetSelection;
1111
use crate::{Compiler, Mode, Subcommand};
12-
use std::path::{Path, PathBuf};
12+
use std::path::PathBuf;
1313

1414
pub fn cargo_subcommand(kind: Kind) -> &'static str {
1515
match kind {
@@ -52,7 +52,7 @@ impl Step for Std {
5252
}
5353

5454
fn run(self, builder: &Builder<'_>) {
55-
builder.update_submodule(&Path::new("library").join("stdarch"));
55+
builder.require_and_update_submodule("library/stdarch", None);
5656

5757
let target = self.target;
5858
let compiler = builder.compiler(builder.top_stage, builder.config.build);

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! Implementation of running clippy on the compiler, standard library and various tools.
22
3-
use std::path::Path;
4-
53
use crate::builder::Builder;
64
use crate::builder::ShouldRun;
75
use crate::core::builder;
@@ -127,7 +125,7 @@ impl Step for Std {
127125
}
128126

129127
fn run(self, builder: &Builder<'_>) {
130-
builder.update_submodule(&Path::new("library").join("stdarch"));
128+
builder.require_and_update_submodule("library/stdarch", None);
131129

132130
let target = self.target;
133131
let compiler = builder.compiler(builder.top_stage, builder.config.build);

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,14 @@ impl Step for Std {
182182
return;
183183
}
184184

185-
builder.update_submodule(&Path::new("library").join("stdarch"));
185+
builder.require_and_update_submodule("library/stdarch", None);
186186

187187
// Profiler information requires LLVM's compiler-rt
188188
if builder.config.profiler {
189-
builder.update_submodule(Path::new("src/llvm-project"));
189+
builder.require_and_update_submodule(
190+
"src/llvm-project",
191+
Some("The `build.profiler` config option requires compiler-rt sources."),
192+
);
190193
}
191194

192195
let mut target_deps = builder.ensure(StartupObjects { compiler, target });
@@ -456,13 +459,15 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car
456459
// That's probably ok? At least, the difference wasn't enforced before. There's a comment in
457460
// the compiler_builtins build script that makes me nervous, though:
458461
// https://github.com/rust-lang/compiler-builtins/blob/31ee4544dbe47903ce771270d6e3bea8654e9e50/build.rs#L575-L579
459-
builder.update_submodule(&Path::new("src").join("llvm-project"));
462+
builder.require_and_update_submodule(
463+
"src/llvm-project",
464+
Some(
465+
"need LLVM sources available to build `compiler-rt`, but they weren't present; \
466+
consider disabling `optimized-compiler-builtins`",
467+
),
468+
);
460469
let compiler_builtins_root = builder.src.join("src/llvm-project/compiler-rt");
461-
if !compiler_builtins_root.exists() {
462-
panic!(
463-
"need LLVM sources available to build `compiler-rt`, but they weren't present; consider enabling `build.submodules = true` or disabling `optimized-compiler-builtins`"
464-
);
465-
}
470+
assert!(compiler_builtins_root.exists());
466471
// Note that `libprofiler_builtins/build.rs` also computes this so if
467472
// you're changing something here please also change that.
468473
cargo.env("RUST_COMPILER_RT_ROOT", &compiler_builtins_root);

src/bootstrap/src/core/build_steps/dist.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ impl Step for Src {
907907
/// Creates the `rust-src` installer component
908908
fn run(self, builder: &Builder<'_>) -> GeneratedTarball {
909909
if !builder.config.dry_run() {
910-
builder.update_submodule(Path::new("src/llvm-project"));
910+
builder.require_and_update_submodule("src/llvm-project", None);
911911
}
912912

913913
let tarball = Tarball::new_targetless(builder, "rust-src");
@@ -1022,10 +1022,7 @@ impl Step for PlainSourceTarball {
10221022
// FIXME: This code looks _very_ similar to what we have in `src/core/build_steps/vendor.rs`
10231023
// perhaps it should be removed in favor of making `dist` perform the `vendor` step?
10241024

1025-
// Ensure we have all submodules from src and other directories checked out.
1026-
for submodule in build_helper::util::parse_gitmodules(&builder.src) {
1027-
builder.update_submodule(Path::new(submodule));
1028-
}
1025+
builder.require_and_update_all_submodules();
10291026

10301027
// Vendor all Cargo dependencies
10311028
let mut cmd = command(&builder.initial_cargo);

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

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::core::build_steps::tool::{self, prepare_tool_cargo, SourceType, Tool}
1616
use crate::core::builder::{self, crate_description};
1717
use crate::core::builder::{Alias, Builder, Compiler, Kind, RunConfig, ShouldRun, Step};
1818
use crate::core::config::{Config, TargetSelection};
19-
use crate::utils::helpers::{dir_is_empty, symlink_dir, t, up_to_date};
19+
use crate::utils::helpers::{symlink_dir, t, up_to_date};
2020
use crate::Mode;
2121

2222
macro_rules! submodule_helper {
@@ -53,8 +53,8 @@ macro_rules! book {
5353

5454
fn run(self, builder: &Builder<'_>) {
5555
$(
56-
let path = Path::new(submodule_helper!( $path, submodule $( = $submodule )? ));
57-
builder.update_submodule(&path);
56+
let path = submodule_helper!( $path, submodule $( = $submodule )? );
57+
builder.require_and_update_submodule(path, None);
5858
)?
5959
builder.ensure(RustbookSrc {
6060
target: self.target,
@@ -217,22 +217,14 @@ impl Step for TheBook {
217217
/// * Index page
218218
/// * Redirect pages
219219
fn run(self, builder: &Builder<'_>) {
220-
let relative_path = Path::new("src").join("doc").join("book");
221-
builder.update_submodule(&relative_path);
220+
builder.require_and_update_submodule("src/doc/book", None);
222221

223222
let compiler = self.compiler;
224223
let target = self.target;
225224

226-
let absolute_path = builder.src.join(&relative_path);
225+
let absolute_path = builder.src.join("src/doc/book");
227226
let redirect_path = absolute_path.join("redirects");
228-
if !absolute_path.exists()
229-
|| !redirect_path.exists()
230-
|| dir_is_empty(&absolute_path)
231-
|| dir_is_empty(&redirect_path)
232-
{
233-
eprintln!("Please checkout submodule: {}", relative_path.display());
234-
crate::exit!(1);
235-
}
227+
236228
// build book
237229
builder.ensure(RustbookSrc {
238230
target,
@@ -932,8 +924,8 @@ macro_rules! tool_doc {
932924
let _ = source_type; // silence the "unused variable" warning
933925
let source_type = SourceType::Submodule;
934926

935-
let path = Path::new(submodule_helper!( $path, submodule $( = $submodule )? ));
936-
builder.update_submodule(&path);
927+
let path = submodule_helper!( $path, submodule $( = $submodule )? );
928+
builder.require_and_update_submodule(path, None);
937929
)?
938930

939931
let stage = builder.top_stage;

src/bootstrap/src/core/build_steps/llvm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub fn prebuilt_llvm_config(builder: &Builder<'_>, target: TargetSelection) -> L
110110
}
111111

112112
// Initialize the llvm submodule if not initialized already.
113-
builder.update_submodule(&Path::new("src").join("llvm-project"));
113+
builder.require_and_update_submodule("src/llvm-project", None);
114114

115115
let root = "src/llvm-project/llvm";
116116
let out_dir = builder.llvm_out(target);
@@ -1197,7 +1197,7 @@ impl Step for CrtBeginEnd {
11971197

11981198
/// Build crtbegin.o/crtend.o for musl target.
11991199
fn run(self, builder: &Builder<'_>) -> Self::Output {
1200-
builder.update_submodule(Path::new("src/llvm-project"));
1200+
builder.require_and_update_submodule("src/llvm-project", None);
12011201

12021202
let out_dir = builder.native_dir(self.target).join("crt");
12031203

@@ -1270,7 +1270,7 @@ impl Step for Libunwind {
12701270

12711271
/// Build libunwind.a
12721272
fn run(self, builder: &Builder<'_>) -> Self::Output {
1273-
builder.update_submodule(Path::new("src/llvm-project"));
1273+
builder.require_and_update_submodule("src/llvm-project", None);
12741274

12751275
if builder.config.dry_run() {
12761276
return PathBuf::new();

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2398,8 +2398,8 @@ impl Step for RustcGuide {
23982398
}
23992399

24002400
fn run(self, builder: &Builder<'_>) {
2401-
let relative_path = Path::new("src").join("doc").join("rustc-dev-guide");
2402-
builder.update_submodule(&relative_path);
2401+
let relative_path = "src/doc/rustc-dev-guide";
2402+
builder.require_and_update_submodule(relative_path, None);
24032403

24042404
let src = builder.src.join(relative_path);
24052405
let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook).delay_failure();
@@ -3009,7 +3009,7 @@ impl Step for Bootstrap {
30093009
let _guard = builder.msg(Kind::Test, 0, "bootstrap", host, host);
30103010

30113011
// Some tests require cargo submodule to be present.
3012-
builder.build.update_submodule(Path::new("src/tools/cargo"));
3012+
builder.build.require_and_update_submodule("src/tools/cargo", None);
30133013

30143014
let mut check_bootstrap = command(builder.python());
30153015
check_bootstrap

src/bootstrap/src/core/build_steps/tool.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::env;
22
use std::fs;
3-
use std::path::{Path, PathBuf};
3+
use std::path::PathBuf;
44

55
use crate::core::build_steps::compile;
66
use crate::core::build_steps::toolstate::ToolState;
@@ -290,7 +290,7 @@ macro_rules! bootstrap_tool {
290290
fn run(self, builder: &Builder<'_>) -> PathBuf {
291291
$(
292292
for submodule in $submodules {
293-
builder.update_submodule(Path::new(submodule));
293+
builder.require_and_update_submodule(submodule, None);
294294
}
295295
)*
296296
builder.ensure(ToolBuild {
@@ -373,7 +373,7 @@ impl Step for OptimizedDist {
373373
fn run(self, builder: &Builder<'_>) -> PathBuf {
374374
// We need to ensure the rustc-perf submodule is initialized when building opt-dist since
375375
// the tool requires it to be in place to run.
376-
builder.update_submodule(Path::new("src/tools/rustc-perf"));
376+
builder.require_and_update_submodule("src/tools/rustc-perf", None);
377377

378378
builder.ensure(ToolBuild {
379379
compiler: self.compiler,
@@ -414,7 +414,7 @@ impl Step for RustcPerf {
414414

415415
fn run(self, builder: &Builder<'_>) -> PathBuf {
416416
// We need to ensure the rustc-perf submodule is initialized.
417-
builder.update_submodule(Path::new("src/tools/rustc-perf"));
417+
builder.require_and_update_submodule("src/tools/rustc-perf", None);
418418

419419
let tool = ToolBuild {
420420
compiler: self.compiler,
@@ -715,7 +715,7 @@ impl Step for Cargo {
715715
}
716716

717717
fn run(self, builder: &Builder<'_>) -> PathBuf {
718-
builder.build.update_submodule(Path::new("src/tools/cargo"));
718+
builder.build.require_and_update_submodule("src/tools/cargo", None);
719719

720720
builder.ensure(ToolBuild {
721721
compiler: self.compiler,

src/bootstrap/src/core/build_steps/vendor.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
22
use crate::utils::exec::command;
3-
use std::path::{Path, PathBuf};
3+
use std::path::PathBuf;
44

55
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
66
pub(crate) struct Vendor {
@@ -35,8 +35,8 @@ impl Step for Vendor {
3535
}
3636

3737
// These submodules must be present for `x vendor` to work.
38-
for path in ["src/tools/cargo", "src/doc/book"] {
39-
builder.build.update_submodule(Path::new(path));
38+
for submodule in ["src/tools/cargo", "src/doc/book"] {
39+
builder.build.require_and_update_submodule(submodule, None);
4040
}
4141

4242
// Sync these paths by default.

src/bootstrap/src/core/builder/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn configure_with_args(cmd: &[String], host: &[&str], target: &[&str]) -> Config
2121
rust_codegen_backends: vec![],
2222
..Config::parse(&["check".to_owned()])
2323
});
24-
submodule_build.update_submodule(Path::new("src/doc/book"));
24+
submodule_build.require_and_update_submodule("src/doc/book", None);
2525
config.submodules = Some(false);
2626

2727
config.ninja_in_file = false;

0 commit comments

Comments
 (0)