diff options
| author | bors <bors@rust-lang.org> | 2025-01-04 18:26:14 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-01-04 18:26:14 +0000 |
| commit | ead4a8f53624f3b4a9ee833421fbf8a48bc07aca (patch) | |
| tree | 5d9d8d2bd6b0d5db81e1903bbf0580e0121aca65 | |
| parent | 2a8af4f7c8262a90b886bc063fe0c271d2b51a45 (diff) | |
| parent | 4406f42a1851108d745d281449bdd7bbaae35da9 (diff) | |
| download | rust-ead4a8f53624f3b4a9ee833421fbf8a48bc07aca.tar.gz rust-ead4a8f53624f3b4a9ee833421fbf8a48bc07aca.zip | |
Auto merge of #135096 - jieyouxu:fix-doc-submodule-handling, r=onur-ozkan
bootstrap: correctly handle doc paths within submodules Fixes #135041 by passing the correct submodule path when requiring submodules. This PR changes `is_path_in_submodule` to `submodule_path_of`. `submodule_path_of` returns the path of the containing submodule when given a path nested inside a submodule we handle, and `None` otherwise. I tested this manually locally by unregistering the `src/tools/cargo` submodule, then running `./x doc src/tools/cargo/src/doc`. This command fails on master with ``` thread 'main' panicked at src/bootstrap/src/utils/helpers.rs:441:5: std::fs::read_dir(dir) failed with No such file or directory (os error 2) ``` since the require submodule fails as `src/tools/cargo/src/doc` is not a known submodule. Now we use the submodule path if such a nested-in-submodule-path is passed, and thus running this command with cargo submodule unregistered still succeeds: ``` Rustbook (x86_64-unknown-linux-gnu) - cargo Doc path: /home/joe/repos/rust/build/x86_64-unknown-linux-gnu/doc/cargo/index.html Build completed successfully in 0:00:11 ``` r? `@onur-ozkan`
| -rw-r--r-- | src/bootstrap/src/core/build_steps/doc.rs | 10 | ||||
| -rw-r--r-- | src/bootstrap/src/utils/helpers.rs | 8 | ||||
| -rw-r--r-- | src/bootstrap/src/utils/helpers/tests.rs | 20 |
3 files changed, 23 insertions, 15 deletions
diff --git a/src/bootstrap/src/core/build_steps/doc.rs b/src/bootstrap/src/core/build_steps/doc.rs index 75edc8ff781..dc09d2d1093 100644 --- a/src/bootstrap/src/core/build_steps/doc.rs +++ b/src/bootstrap/src/core/build_steps/doc.rs @@ -18,7 +18,7 @@ use crate::core::builder::{ self, Alias, Builder, Compiler, Kind, RunConfig, ShouldRun, Step, crate_description, }; use crate::core::config::{Config, TargetSelection}; -use crate::helpers::{is_path_in_submodule, symlink_dir, t, up_to_date}; +use crate::helpers::{submodule_path_of, symlink_dir, t, up_to_date}; macro_rules! book { ($($name:ident, $path:expr, $book_name:expr, $lang:expr ;)+) => { @@ -44,8 +44,8 @@ macro_rules! book { } fn run(self, builder: &Builder<'_>) { - if is_path_in_submodule(&builder, $path) { - builder.require_submodule($path, None); + if let Some(submodule_path) = submodule_path_of(&builder, $path) { + builder.require_submodule(&submodule_path, None) } builder.ensure(RustbookSrc { @@ -933,9 +933,9 @@ macro_rules! tool_doc { fn run(self, builder: &Builder<'_>) { let mut source_type = SourceType::InTree; - if is_path_in_submodule(&builder, $path) { + if let Some(submodule_path) = submodule_path_of(&builder, $path) { source_type = SourceType::Submodule; - builder.require_submodule($path, None); + builder.require_submodule(&submodule_path, None); } let stage = builder.top_stage; diff --git a/src/bootstrap/src/utils/helpers.rs b/src/bootstrap/src/utils/helpers.rs index 2ff99e7e499..c4780cc56b2 100644 --- a/src/bootstrap/src/utils/helpers.rs +++ b/src/bootstrap/src/utils/helpers.rs @@ -60,10 +60,12 @@ pub fn is_dylib(path: &Path) -> bool { }) } -/// Returns `true` if the given path is part of a submodule. -pub fn is_path_in_submodule(builder: &Builder<'_>, path: &str) -> bool { +/// Return the path to the containing submodule if available. +pub fn submodule_path_of(builder: &Builder<'_>, path: &str) -> Option<String> { let submodule_paths = build_helper::util::parse_gitmodules(&builder.src); - submodule_paths.iter().any(|submodule_path| path.starts_with(submodule_path)) + submodule_paths.iter().find_map(|submodule_path| { + if path.starts_with(submodule_path) { Some(submodule_path.to_string()) } else { None } + }) } fn is_aix_shared_archive(path: &Path) -> bool { diff --git a/src/bootstrap/src/utils/helpers/tests.rs b/src/bootstrap/src/utils/helpers/tests.rs index 7bd2a47c63c..613286cfaa8 100644 --- a/src/bootstrap/src/utils/helpers/tests.rs +++ b/src/bootstrap/src/utils/helpers/tests.rs @@ -3,8 +3,8 @@ use std::io::Write; use std::path::PathBuf; use crate::utils::helpers::{ - check_cfg_arg, extract_beta_rev, hex_encode, is_path_in_submodule, make, program_out_of_date, - set_file_times, symlink_dir, + check_cfg_arg, extract_beta_rev, hex_encode, make, program_out_of_date, set_file_times, + submodule_path_of, symlink_dir, }; use crate::{Config, Flags}; @@ -117,16 +117,22 @@ fn test_set_file_times_sanity_check() { } #[test] -fn test_is_path_in_submodule() { +fn test_submodule_path_of() { let config = Config::parse_inner(Flags::parse(&["build".into(), "--dry-run".into()]), |&_| { Ok(Default::default()) }); let build = crate::Build::new(config.clone()); let builder = crate::core::builder::Builder::new(&build); - assert!(!is_path_in_submodule(&builder, "invalid/path")); - assert!(is_path_in_submodule(&builder, "src/tools/cargo")); - assert!(is_path_in_submodule(&builder, "src/llvm-project")); + assert_eq!(submodule_path_of(&builder, "invalid/path"), None); + assert_eq!(submodule_path_of(&builder, "src/tools/cargo"), Some("src/tools/cargo".to_string())); + assert_eq!( + submodule_path_of(&builder, "src/llvm-project"), + Some("src/llvm-project".to_string()) + ); // Make sure subdirs are handled properly - assert!(is_path_in_submodule(&builder, "src/tools/cargo/random-subdir")); + assert_eq!( + submodule_path_of(&builder, "src/tools/cargo/random-subdir"), + Some("src/tools/cargo".to_string()) + ); } |
