]> git.lizzy.rs Git - rust.git/commitdiff
Simplify explicit request check
authorGuillaume Gomez <guillaume.gomez@huawei.com>
Wed, 22 Sep 2021 20:25:42 +0000 (22:25 +0200)
committerGuillaume Gomez <guillaume.gomez@huawei.com>
Fri, 24 Sep 2021 10:01:57 +0000 (12:01 +0200)
src/bootstrap/builder.rs
src/bootstrap/doc.rs

index 0a6ed2f49b7877dcc19549b8571ed592509ffbfc..1f2109879d121bc452264f42afbf8f60dae5fecf 100644 (file)
@@ -1617,6 +1617,22 @@ pub(crate) fn ensure_if_default<T, S: Step<Output = Option<T>>>(
         // Only execute if it's supposed to run as default
         if desc.default && should_run.is_really_default() { self.ensure(step) } else { None }
     }
+
+    /// Checks if any of the "should_run" paths is in the `Builder` paths.
+    pub(crate) fn was_invoked_explicitly<S: Step>(&'a self) -> bool {
+        let desc = StepDescription::from::<S>();
+        let should_run = (desc.should_run)(ShouldRun::new(self));
+
+        for path in &self.paths {
+            if should_run.paths.iter().any(|s| s.has(path))
+                && !desc.is_excluded(self, &PathSet::Suite(path.clone()))
+            {
+                return true;
+            }
+        }
+
+        false
+    }
 }
 
 #[cfg(test)]
index af3774b7c7586ef3f33d38747405153b0eb4dff0..1ebaf4ca5190c5d70f0c73625d8aa21d221da191 100644 (file)
@@ -102,18 +102,10 @@ fn open(builder: &Builder<'_>, path: impl AsRef<Path>) {
 // Used for deciding whether a particular step is one requested by the user on
 // the `x.py doc` command line, which determines whether `--open` will open that
 // page.
-fn components_simplified(path: &PathBuf) -> Vec<&str> {
+pub(crate) fn components_simplified(path: &PathBuf) -> Vec<&str> {
     path.iter().map(|component| component.to_str().unwrap_or("???")).collect()
 }
 
-fn is_explicit_request(builder: &Builder<'_>, path: &str) -> bool {
-    builder
-        .paths
-        .iter()
-        .map(components_simplified)
-        .any(|requested| requested.iter().copied().eq(path.split('/')))
-}
-
 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
 pub struct UnstableBook {
     target: TargetSelection,
@@ -248,7 +240,7 @@ fn run(self, builder: &Builder<'_>) {
             invoke_rustdoc(builder, compiler, target, path);
         }
 
-        if is_explicit_request(builder, "src/doc/book") {
+        if builder.was_invoked_explicitly::<Self>() {
             let out = builder.doc_out(target);
             let index = out.join("book").join("index.html");
             open(builder, &index);
@@ -408,7 +400,7 @@ fn run(self, builder: &Builder<'_>) {
 
         // We open doc/index.html as the default if invoked as `x.py doc --open`
         // with no particular explicit doc requested (e.g. library/core).
-        if builder.paths.is_empty() || is_explicit_request(builder, "src/doc") {
+        if builder.paths.is_empty() || builder.was_invoked_explicitly::<Self>() {
             let index = out.join("index.html");
             open(builder, &index);
         }
@@ -553,7 +545,6 @@ fn make_run(run: RunConfig<'_>) {
     fn run(self, builder: &Builder<'_>) {
         let stage = self.stage;
         let target = self.target;
-        let mut is_explicit_request = false;
         builder.info(&format!("Documenting stage{} compiler ({})", stage, target));
 
         let paths = builder
@@ -562,7 +553,6 @@ fn run(self, builder: &Builder<'_>) {
             .map(components_simplified)
             .filter_map(|path| {
                 if path.get(0) == Some(&"compiler") {
-                    is_explicit_request = true;
                     path.get(1).map(|p| p.to_owned())
                 } else {
                     None
@@ -570,7 +560,7 @@ fn run(self, builder: &Builder<'_>) {
             })
             .collect::<Vec<_>>();
 
-        if !builder.config.compiler_docs && !is_explicit_request {
+        if !builder.config.compiler_docs && !builder.was_invoked_explicitly::<Self>() {
             builder.info("\tskipping - compiler/librustdoc docs disabled");
             return;
         }
@@ -700,7 +690,14 @@ fn make_run(run: RunConfig<'_>) {
             fn run(self, builder: &Builder<'_>) {
                 let stage = self.stage;
                 let target = self.target;
-                builder.info(&format!("Documenting stage{} {} ({})", stage, stringify!($tool).to_lowercase(), target));
+                builder.info(
+                    &format!(
+                        "Documenting stage{} {} ({})",
+                        stage,
+                        stringify!($tool).to_lowercase(),
+                        target,
+                    ),
+                );
 
                 // This is the intended out directory for compiler documentation.
                 let out = builder.compiler_doc_out(target);
@@ -708,7 +705,7 @@ fn run(self, builder: &Builder<'_>) {
 
                 let compiler = builder.compiler(stage, builder.config.build);
 
-                if !builder.config.compiler_docs {
+                if !builder.config.compiler_docs && !builder.was_invoked_explicitly::<Self>() {
                     builder.info("\tskipping - compiler/tool docs disabled");
                     return;
                 }
@@ -912,7 +909,7 @@ fn run(self, builder: &Builder<'_>) {
             name: INTERNER.intern_str("rustc"),
             src: INTERNER.intern_path(out_base),
         });
-        if is_explicit_request(builder, "src/doc/rustc") {
+        if builder.was_invoked_explicitly::<Self>() {
             let out = builder.doc_out(self.target);
             let index = out.join("rustc").join("index.html");
             open(builder, &index);