Auto merge of #113965 - chenyukang:yukang-fix-113963-panic, r=ozkanonur

Fix test panics for submodule of book is not updated

Fixes #113963
This commit is contained in:
bors 2023-07-23 15:57:50 +00:00
commit d9d80e211e
3 changed files with 19 additions and 9 deletions

View File

@ -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();

View File

@ -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;
}

View File

@ -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()
}