Skip to content

Commit b1b576d

Browse files
committed
handle submodules automatically on doc steps
Signed-off-by: onur-ozkan <[email protected]>
1 parent 41b5796 commit b1b576d

File tree

2 files changed

+23
-30
lines changed

2 files changed

+23
-30
lines changed

src/bootstrap/src/core/build_steps/doc.rs

+17-30
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,10 @@ 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::utils::helpers::{symlink_dir, t, up_to_date};
22-
23-
macro_rules! submodule_helper {
24-
($path:expr, submodule) => {
25-
$path
26-
};
27-
($path:expr, submodule = $submodule:literal) => {
28-
$submodule
29-
};
30-
}
21+
use crate::helpers::{is_path_in_submodule, symlink_dir, t, up_to_date};
3122

3223
macro_rules! book {
33-
($($name:ident, $path:expr, $book_name:expr, $lang:expr $(, submodule $(= $submodule:literal)? )? ;)+) => {
24+
($($name:ident, $path:expr, $book_name:expr, $lang:expr ;)+) => {
3425
$(
3526
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
3627
pub struct $name {
@@ -53,10 +44,10 @@ macro_rules! book {
5344
}
5445

5546
fn run(self, builder: &Builder<'_>) {
56-
$(
57-
let path = submodule_helper!( $path, submodule $( = $submodule )? );
58-
builder.require_submodule(path, None);
59-
)?
47+
if is_path_in_submodule(&builder, $path) {
48+
builder.require_submodule($path, None);
49+
}
50+
6051
builder.ensure(RustbookSrc {
6152
target: self.target,
6253
name: $book_name.to_owned(),
@@ -77,12 +68,12 @@ macro_rules! book {
7768
// FIXME: Make checking for a submodule automatic somehow (maybe by having a list of all submodules
7869
// and checking against it?).
7970
book!(
80-
CargoBook, "src/tools/cargo/src/doc", "cargo", &[], submodule = "src/tools/cargo";
71+
CargoBook, "src/tools/cargo/src/doc", "cargo", &[];
8172
ClippyBook, "src/tools/clippy/book", "clippy", &[];
82-
EditionGuide, "src/doc/edition-guide", "edition-guide", &[], submodule;
83-
EmbeddedBook, "src/doc/embedded-book", "embedded-book", &[], submodule;
84-
Nomicon, "src/doc/nomicon", "nomicon", &[], submodule;
85-
RustByExample, "src/doc/rust-by-example", "rust-by-example", &["ja", "zh"], submodule;
73+
EditionGuide, "src/doc/edition-guide", "edition-guide", &[];
74+
EmbeddedBook, "src/doc/embedded-book", "embedded-book", &[];
75+
Nomicon, "src/doc/nomicon", "nomicon", &[];
76+
RustByExample, "src/doc/rust-by-example", "rust-by-example", &["ja", "zh"];
8677
RustdocBook, "src/doc/rustdoc", "rustdoc", &[];
8778
StyleGuide, "src/doc/style-guide", "style-guide", &[];
8879
);
@@ -910,7 +901,6 @@ macro_rules! tool_doc {
910901
$(rustc_tool = $rustc_tool:literal, )?
911902
$(is_library = $is_library:expr,)?
912903
$(crates = $crates:expr)?
913-
$(, submodule $(= $submodule:literal)? )?
914904
) => {
915905
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
916906
pub struct $tool {
@@ -938,14 +928,12 @@ macro_rules! tool_doc {
938928
/// we do not merge it with the other documentation from std, test and
939929
/// proc_macros. This is largely just a wrapper around `cargo doc`.
940930
fn run(self, builder: &Builder<'_>) {
941-
let source_type = SourceType::InTree;
942-
$(
943-
let _ = source_type; // silence the "unused variable" warning
944-
let source_type = SourceType::Submodule;
931+
let mut source_type = SourceType::InTree;
945932

946-
let path = submodule_helper!( $path, submodule $( = $submodule )? );
947-
builder.require_submodule(path, None);
948-
)?
933+
if is_path_in_submodule(&builder, $path) {
934+
source_type = SourceType::Submodule;
935+
builder.require_submodule($path, None);
936+
}
949937

950938
let stage = builder.top_stage;
951939
let target = self.target;
@@ -1054,8 +1042,7 @@ tool_doc!(
10541042
"crates-io",
10551043
"mdman",
10561044
"rustfix",
1057-
],
1058-
submodule = "src/tools/cargo"
1045+
]
10591046
);
10601047
tool_doc!(Tidy, "src/tools/tidy", rustc_tool = false, crates = ["tidy"]);
10611048
tool_doc!(

src/bootstrap/src/utils/helpers.rs

+6
Original file line numberDiff line numberDiff line change
@@ -60,6 +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 {
65+
let submodule_paths = build_helper::util::parse_gitmodules(&builder.src);
66+
submodule_paths.iter().any(|submodule_path| path.starts_with(submodule_path))
67+
}
68+
6369
fn is_aix_shared_archive(path: &Path) -> bool {
6470
let file = match fs::File::open(path) {
6571
Ok(file) => file,

0 commit comments

Comments
 (0)