Skip to content

Commit ead4a8f

Browse files
committed
Auto merge of rust-lang#135096 - jieyouxu:fix-doc-submodule-handling, r=onur-ozkan
bootstrap: correctly handle doc paths within submodules Fixes rust-lang#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`
2 parents 2a8af4f + 4406f42 commit ead4a8f

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

Diff for: src/bootstrap/src/core/build_steps/doc.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::core::builder::{
1818
self, Alias, Builder, Compiler, Kind, RunConfig, ShouldRun, Step, crate_description,
1919
};
2020
use crate::core::config::{Config, TargetSelection};
21-
use crate::helpers::{is_path_in_submodule, symlink_dir, t, up_to_date};
21+
use crate::helpers::{submodule_path_of, symlink_dir, t, up_to_date};
2222

2323
macro_rules! book {
2424
($($name:ident, $path:expr, $book_name:expr, $lang:expr ;)+) => {
@@ -44,8 +44,8 @@ macro_rules! book {
4444
}
4545

4646
fn run(self, builder: &Builder<'_>) {
47-
if is_path_in_submodule(&builder, $path) {
48-
builder.require_submodule($path, None);
47+
if let Some(submodule_path) = submodule_path_of(&builder, $path) {
48+
builder.require_submodule(&submodule_path, None)
4949
}
5050

5151
builder.ensure(RustbookSrc {
@@ -933,9 +933,9 @@ macro_rules! tool_doc {
933933
fn run(self, builder: &Builder<'_>) {
934934
let mut source_type = SourceType::InTree;
935935

936-
if is_path_in_submodule(&builder, $path) {
936+
if let Some(submodule_path) = submodule_path_of(&builder, $path) {
937937
source_type = SourceType::Submodule;
938-
builder.require_submodule($path, None);
938+
builder.require_submodule(&submodule_path, None);
939939
}
940940

941941
let stage = builder.top_stage;

Diff for: src/bootstrap/src/utils/helpers.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@ pub fn is_dylib(path: &Path) -> bool {
6060
})
6161
}
6262

63-
/// Returns `true` if the given path is part of a submodule.
64-
pub fn is_path_in_submodule(builder: &Builder<'_>, path: &str) -> bool {
63+
/// Return the path to the containing submodule if available.
64+
pub fn submodule_path_of(builder: &Builder<'_>, path: &str) -> Option<String> {
6565
let submodule_paths = build_helper::util::parse_gitmodules(&builder.src);
66-
submodule_paths.iter().any(|submodule_path| path.starts_with(submodule_path))
66+
submodule_paths.iter().find_map(|submodule_path| {
67+
if path.starts_with(submodule_path) { Some(submodule_path.to_string()) } else { None }
68+
})
6769
}
6870

6971
fn is_aix_shared_archive(path: &Path) -> bool {

Diff for: src/bootstrap/src/utils/helpers/tests.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use std::io::Write;
33
use std::path::PathBuf;
44

55
use crate::utils::helpers::{
6-
check_cfg_arg, extract_beta_rev, hex_encode, is_path_in_submodule, make, program_out_of_date,
7-
set_file_times, symlink_dir,
6+
check_cfg_arg, extract_beta_rev, hex_encode, make, program_out_of_date, set_file_times,
7+
submodule_path_of, symlink_dir,
88
};
99
use crate::{Config, Flags};
1010

@@ -117,16 +117,22 @@ fn test_set_file_times_sanity_check() {
117117
}
118118

119119
#[test]
120-
fn test_is_path_in_submodule() {
120+
fn test_submodule_path_of() {
121121
let config = Config::parse_inner(Flags::parse(&["build".into(), "--dry-run".into()]), |&_| {
122122
Ok(Default::default())
123123
});
124124

125125
let build = crate::Build::new(config.clone());
126126
let builder = crate::core::builder::Builder::new(&build);
127-
assert!(!is_path_in_submodule(&builder, "invalid/path"));
128-
assert!(is_path_in_submodule(&builder, "src/tools/cargo"));
129-
assert!(is_path_in_submodule(&builder, "src/llvm-project"));
127+
assert_eq!(submodule_path_of(&builder, "invalid/path"), None);
128+
assert_eq!(submodule_path_of(&builder, "src/tools/cargo"), Some("src/tools/cargo".to_string()));
129+
assert_eq!(
130+
submodule_path_of(&builder, "src/llvm-project"),
131+
Some("src/llvm-project".to_string())
132+
);
130133
// Make sure subdirs are handled properly
131-
assert!(is_path_in_submodule(&builder, "src/tools/cargo/random-subdir"));
134+
assert_eq!(
135+
submodule_path_of(&builder, "src/tools/cargo/random-subdir"),
136+
Some("src/tools/cargo".to_string())
137+
);
132138
}

0 commit comments

Comments
 (0)