about summary refs log tree commit diff
path: root/src/bootstrap
diff options
context:
space:
mode:
authoronur-ozkan <work@onurozkan.dev>2024-06-08 12:48:19 +0300
committeronur-ozkan <work@onurozkan.dev>2024-06-09 22:48:56 +0300
commite61d3b8372f988ba8b6573deac2290d59d72b76f (patch)
tree8cf4a609028865b6f6ec6cbe9407451a9315544b /src/bootstrap
parent16e8803579e5914a17a4924f47faaefc040a982d (diff)
downloadrust-e61d3b8372f988ba8b6573deac2290d59d72b76f.tar.gz
rust-e61d3b8372f988ba8b6573deac2290d59d72b76f.zip
fix `Builder::doc_rust_lang_org_channel`
Previously, we were unable to use `rust.download-rustc` with the beta or stable
channel settings through `rust.channel` due to breaking rustdoc UI tests.
This was because when using a precompiled nightly compiler from CI, we must use the
channel of precompiled compiler and ignore `rust.channel` from the configuration.

This change addresses that issue in `Builder::doc_rust_lang_org_channel` and allows rustdoc
UI tests to work with the precompiled compiler even if the channel specified in config.toml is
"beta" or "stable".

Signed-off-by: onur-ozkan <work@onurozkan.dev>
Diffstat (limited to 'src/bootstrap')
-rw-r--r--src/bootstrap/src/core/builder.rs26
-rw-r--r--src/bootstrap/src/core/config/config.rs26
2 files changed, 38 insertions, 14 deletions
diff --git a/src/bootstrap/src/core/builder.rs b/src/bootstrap/src/core/builder.rs
index b3d8465cda9..3b890a6516f 100644
--- a/src/bootstrap/src/core/builder.rs
+++ b/src/bootstrap/src/core/builder.rs
@@ -1038,14 +1038,26 @@ impl<'a> Builder<'a> {
     }
 
     pub fn doc_rust_lang_org_channel(&self) -> String {
-        let channel = match &*self.config.channel {
-            "stable" => &self.version,
-            "beta" => "beta",
-            "nightly" | "dev" => "nightly",
-            // custom build of rustdoc maybe? link to the latest stable docs just in case
-            _ => "stable",
+        // When using precompiled compiler from CI, we need to use CI rustc's channel and
+        // ignore `rust.channel` from the configuration. Otherwise most of the rustdoc tests
+        // will fail due to incompatible `DOC_RUST_LANG_ORG_CHANNEL`.
+        let channel = if let Some(commit) = self.config.download_rustc_commit() {
+            self.config
+                .read_file_by_commit(&PathBuf::from("src/ci/channel"), commit)
+                .trim()
+                .to_owned()
+        } else {
+            match &*self.config.channel {
+                "stable" => &self.version,
+                "beta" => "beta",
+                "nightly" | "dev" => "nightly",
+                // custom build of rustdoc maybe? link to the latest stable docs just in case
+                _ => "stable",
+            }
+            .to_owned()
         };
-        "https://doc.rust-lang.org/".to_owned() + channel
+
+        format!("https://doc.rust-lang.org/{channel}")
     }
 
     fn run_step_descriptions(&self, v: &[StepDescription], paths: &[PathBuf]) {
diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs
index 17e37c1ecd2..2d87fb4aa60 100644
--- a/src/bootstrap/src/core/config/config.rs
+++ b/src/bootstrap/src/core/config/config.rs
@@ -2134,17 +2134,29 @@ impl Config {
         args
     }
 
+    /// Returns the content of the given file at a specific commit.
+    pub(crate) fn read_file_by_commit(&self, file: &Path, commit: &str) -> String {
+        assert!(
+            self.rust_info.is_managed_git_subrepository(),
+            "`Config::read_file_by_commit` is not supported in non-git sources."
+        );
+
+        let mut git = self.git();
+        git.arg("show").arg(format!("{commit}:{}", file.to_str().unwrap()));
+        output(&mut git)
+    }
+
     /// Bootstrap embeds a version number into the name of shared libraries it uploads in CI.
     /// Return the version it would have used for the given commit.
     pub(crate) fn artifact_version_part(&self, commit: &str) -> String {
         let (channel, version) = if self.rust_info.is_managed_git_subrepository() {
-            let mut channel = self.git();
-            channel.arg("show").arg(format!("{commit}:src/ci/channel"));
-            let channel = output(&mut channel);
-            let mut version = self.git();
-            version.arg("show").arg(format!("{commit}:src/version"));
-            let version = output(&mut version);
-            (channel.trim().to_owned(), version.trim().to_owned())
+            let channel = self
+                .read_file_by_commit(&PathBuf::from("src/ci/channel"), commit)
+                .trim()
+                .to_owned();
+            let version =
+                self.read_file_by_commit(&PathBuf::from("src/version"), commit).trim().to_owned();
+            (channel, version)
         } else {
             let channel = fs::read_to_string(self.src.join("src/ci/channel"));
             let version = fs::read_to_string(self.src.join("src/version"));