Skip to content

Commit d46804c

Browse files
committed
Fix test panics for submodule of book is not updated
1 parent 42f5419 commit d46804c

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

src/bootstrap/doc.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::cache::{Interned, INTERNER};
1616
use crate::compile;
1717
use crate::config::{Config, TargetSelection};
1818
use crate::tool::{self, prepare_tool_cargo, SourceType, Tool};
19-
use crate::util::{symlink_dir, t, up_to_date};
19+
use crate::util::{dir_is_empty, symlink_dir, t, up_to_date};
2020
use crate::Mode;
2121

2222
macro_rules! submodule_helper {
@@ -197,11 +197,21 @@ impl Step for TheBook {
197197
let compiler = self.compiler;
198198
let target = self.target;
199199

200+
let absolute_path = builder.src.join(&relative_path);
201+
let redirect_path = absolute_path.join("redirects");
202+
if !absolute_path.exists()
203+
|| !redirect_path.exists()
204+
|| dir_is_empty(&absolute_path)
205+
|| dir_is_empty(&redirect_path)
206+
{
207+
eprintln!("Please checkout submodule: {}", relative_path.display());
208+
crate::exit!(1);
209+
}
200210
// build book
201211
builder.ensure(RustbookSrc {
202212
target,
203213
name: INTERNER.intern_str("book"),
204-
src: INTERNER.intern_path(builder.src.join(&relative_path)),
214+
src: INTERNER.intern_path(absolute_path.clone()),
205215
parent: Some(self),
206216
});
207217

@@ -210,7 +220,7 @@ impl Step for TheBook {
210220
builder.ensure(RustbookSrc {
211221
target,
212222
name: INTERNER.intern_string(format!("book/{}", edition)),
213-
src: INTERNER.intern_path(builder.src.join(&relative_path).join(edition)),
223+
src: INTERNER.intern_path(absolute_path.join(edition)),
214224
// There should only be one book that is marked as the parent for each target, so
215225
// treat the other editions as not having a parent.
216226
parent: Option::<Self>::None,
@@ -225,7 +235,7 @@ impl Step for TheBook {
225235

226236
// build the redirect pages
227237
let _guard = builder.msg_doc(compiler, "book redirect pages", target);
228-
for file in t!(fs::read_dir(builder.src.join(&relative_path).join("redirects"))) {
238+
for file in t!(fs::read_dir(redirect_path)) {
229239
let file = t!(file);
230240
let path = file.path();
231241
let path = path.to_str().unwrap();

src/bootstrap/lib.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use once_cell::sync::OnceCell;
3636
use crate::builder::Kind;
3737
use crate::config::{LlvmLibunwind, TargetSelection};
3838
use crate::util::{
39-
exe, libdir, mtime, output, run, run_suppressed, symlink_dir, try_run_suppressed,
39+
dir_is_empty, exe, libdir, mtime, output, run, run_suppressed, symlink_dir, try_run_suppressed,
4040
};
4141

4242
mod bolt;
@@ -535,10 +535,6 @@ impl Build {
535535
///
536536
/// `relative_path` should be relative to the root of the git repository, not an absolute path.
537537
pub(crate) fn update_submodule(&self, relative_path: &Path) {
538-
fn dir_is_empty(dir: &Path) -> bool {
539-
t!(std::fs::read_dir(dir)).next().is_none()
540-
}
541-
542538
if !self.config.submodules(&self.rust_info()) {
543539
return;
544540
}

src/bootstrap/util.rs

+4
Original file line numberDiff line numberDiff line change
@@ -493,3 +493,7 @@ pub fn lld_flag_no_threads(is_windows: bool) -> &'static str {
493493
});
494494
if is_windows { windows } else { other }
495495
}
496+
497+
pub fn dir_is_empty(dir: &Path) -> bool {
498+
t!(std::fs::read_dir(dir)).next().is_none()
499+
}

0 commit comments

Comments
 (0)