about summary refs log tree commit diff
path: root/src/bootstrap
diff options
context:
space:
mode:
authoryukang <moorekang@gmail.com>2023-07-23 00:53:39 +0800
committeryukang <moorekang@gmail.com>2023-07-23 00:53:39 +0800
commitd46804c62a3c9c5e1ce680093c2e73f61a249229 (patch)
tree13ba116824b22b2154ea247403116a7d9ad59f24 /src/bootstrap
parent42f5419dd29046612138413cbde4567def218341 (diff)
downloadrust-d46804c62a3c9c5e1ce680093c2e73f61a249229.tar.gz
rust-d46804c62a3c9c5e1ce680093c2e73f61a249229.zip
Fix test panics for submodule of book is not updated
Diffstat (limited to 'src/bootstrap')
-rw-r--r--src/bootstrap/doc.rs18
-rw-r--r--src/bootstrap/lib.rs6
-rw-r--r--src/bootstrap/util.rs4
3 files changed, 19 insertions, 9 deletions
diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs
index e58f736d67f..d4807aff4d6 100644
--- a/src/bootstrap/doc.rs
+++ b/src/bootstrap/doc.rs
@@ -16,7 +16,7 @@ use crate::cache::{Interned, INTERNER};
 use crate::compile;
 use crate::config::{Config, TargetSelection};
 use crate::tool::{self, prepare_tool_cargo, SourceType, Tool};
-use crate::util::{symlink_dir, t, up_to_date};
+use crate::util::{dir_is_empty, symlink_dir, t, up_to_date};
 use crate::Mode;
 
 macro_rules! submodule_helper {
@@ -197,11 +197,21 @@ impl Step for TheBook {
         let compiler = self.compiler;
         let target = self.target;
 
+        let absolute_path = builder.src.join(&relative_path);
+        let redirect_path = absolute_path.join("redirects");
+        if !absolute_path.exists()
+            || !redirect_path.exists()
+            || dir_is_empty(&absolute_path)
+            || dir_is_empty(&redirect_path)
+        {
+            eprintln!("Please checkout submodule: {}", relative_path.display());
+            crate::exit!(1);
+        }
         // build book
         builder.ensure(RustbookSrc {
             target,
             name: INTERNER.intern_str("book"),
-            src: INTERNER.intern_path(builder.src.join(&relative_path)),
+            src: INTERNER.intern_path(absolute_path.clone()),
             parent: Some(self),
         });
 
@@ -210,7 +220,7 @@ impl Step for TheBook {
             builder.ensure(RustbookSrc {
                 target,
                 name: INTERNER.intern_string(format!("book/{}", edition)),
-                src: INTERNER.intern_path(builder.src.join(&relative_path).join(edition)),
+                src: INTERNER.intern_path(absolute_path.join(edition)),
                 // There should only be one book that is marked as the parent for each target, so
                 // treat the other editions as not having a parent.
                 parent: Option::<Self>::None,
@@ -225,7 +235,7 @@ impl Step for TheBook {
 
         // build the redirect pages
         let _guard = builder.msg_doc(compiler, "book redirect pages", target);
-        for file in t!(fs::read_dir(builder.src.join(&relative_path).join("redirects"))) {
+        for file in t!(fs::read_dir(redirect_path)) {
             let file = t!(file);
             let path = file.path();
             let path = path.to_str().unwrap();
diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs
index 059eb9ffc7b..3dd4d8d6617 100644
--- a/src/bootstrap/lib.rs
+++ b/src/bootstrap/lib.rs
@@ -36,7 +36,7 @@ use once_cell::sync::OnceCell;
 use crate::builder::Kind;
 use crate::config::{LlvmLibunwind, TargetSelection};
 use crate::util::{
-    exe, libdir, mtime, output, run, run_suppressed, symlink_dir, try_run_suppressed,
+    dir_is_empty, exe, libdir, mtime, output, run, run_suppressed, symlink_dir, try_run_suppressed,
 };
 
 mod bolt;
@@ -535,10 +535,6 @@ impl Build {
     ///
     /// `relative_path` should be relative to the root of the git repository, not an absolute path.
     pub(crate) fn update_submodule(&self, relative_path: &Path) {
-        fn dir_is_empty(dir: &Path) -> bool {
-            t!(std::fs::read_dir(dir)).next().is_none()
-        }
-
         if !self.config.submodules(&self.rust_info()) {
             return;
         }
diff --git a/src/bootstrap/util.rs b/src/bootstrap/util.rs
index 2725813aba3..84ed2985464 100644
--- a/src/bootstrap/util.rs
+++ b/src/bootstrap/util.rs
@@ -493,3 +493,7 @@ pub fn lld_flag_no_threads(is_windows: bool) -> &'static str {
     });
     if is_windows { windows } else { other }
 }
+
+pub fn dir_is_empty(dir: &Path) -> bool {
+    t!(std::fs::read_dir(dir)).next().is_none()
+}