about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-11-05 00:02:04 +0100
committerGitHub <noreply@github.com>2022-11-05 00:02:04 +0100
commit68c8d6d1c12856f22646accfdae6d90c2406f06e (patch)
treea0b4a31d76d6dfe6e3fbb121d42cdf7b78b82317
parentad01a37ca9d88db738267b4529914dc26bd624d6 (diff)
parent29490098c2dbb9c90c5059ce7a9448dca345b0fb (diff)
downloadrust-68c8d6d1c12856f22646accfdae6d90c2406f06e.tar.gz
rust-68c8d6d1c12856f22646accfdae6d90c2406f06e.zip
Rollup merge of #103878 - Mark-Simulacrum:fix-stable-ci-download, r=jyn514
Fix artifact version/channel detection for stable

On stable, our artifacts are uploaded with the raw version number (e.g., 1.65.0), not the channel. This adjusts our detection logic to use the version number from src/version when we detect the stable channel.

This is really only important for stable channel re-builds, I think, but those do happen from time to time. I'm backporting a similar commit in https://github.com/rust-lang/rust/pull/103859 to make that PR pass CI.
-rw-r--r--src/bootstrap/config.rs55
-rw-r--r--src/bootstrap/native.rs4
2 files changed, 42 insertions, 17 deletions
diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs
index 34d5504827c..21dc11c4808 100644
--- a/src/bootstrap/config.rs
+++ b/src/bootstrap/config.rs
@@ -1380,21 +1380,46 @@ impl Config {
         git
     }
 
-    pub(crate) fn artifact_channel(&self, builder: &Builder<'_>, commit: &str) -> String {
-        if builder.rust_info.is_managed_git_subrepository() {
+    /// 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, builder: &Builder<'_>, commit: &str) -> String {
+        let (channel, version) = if builder.rust_info.is_managed_git_subrepository() {
             let mut channel = self.git();
             channel.arg("show").arg(format!("{}:src/ci/channel", commit));
             let channel = output(&mut channel);
-            channel.trim().to_owned()
-        } else if let Ok(channel) = fs::read_to_string(builder.src.join("src/ci/channel")) {
-            channel.trim().to_owned()
+            let mut version = self.git();
+            version.arg("show").arg(format!("{}:src/version", commit));
+            let version = output(&mut version);
+            (channel.trim().to_owned(), version.trim().to_owned())
         } else {
-            let src = builder.src.display();
-            eprintln!("error: failed to determine artifact channel");
-            eprintln!(
-                "help: either use git or ensure that {src}/src/ci/channel contains the name of the channel to use"
-            );
-            panic!();
+            let channel = fs::read_to_string(builder.src.join("src/ci/channel"));
+            let version = fs::read_to_string(builder.src.join("src/version"));
+            match (channel, version) {
+                (Ok(channel), Ok(version)) => {
+                    (channel.trim().to_owned(), version.trim().to_owned())
+                }
+                (channel, version) => {
+                    let src = builder.src.display();
+                    eprintln!("error: failed to determine artifact channel and/or version");
+                    eprintln!(
+                        "help: consider using a git checkout or ensure these files are readable"
+                    );
+                    if let Err(channel) = channel {
+                        eprintln!("reading {}/src/ci/channel failed: {:?}", src, channel);
+                    }
+                    if let Err(version) = version {
+                        eprintln!("reading {}/src/version failed: {:?}", src, version);
+                    }
+                    panic!();
+                }
+            }
+        };
+
+        match channel.as_str() {
+            "stable" => version,
+            "beta" => channel,
+            "nightly" => channel,
+            other => unreachable!("{:?} is not recognized as a valid channel", other),
         }
     }
 
@@ -1637,7 +1662,7 @@ fn maybe_download_rustfmt(builder: &Builder<'_>) -> Option<PathBuf> {
 
 fn download_ci_rustc(builder: &Builder<'_>, commit: &str) {
     builder.verbose(&format!("using downloaded stage2 artifacts from CI (commit {commit})"));
-    let channel = builder.config.artifact_channel(builder, commit);
+    let version = builder.config.artifact_version_part(builder, commit);
     let host = builder.config.build.triple;
     let bin_root = builder.out.join(host).join("ci-rustc");
     let rustc_stamp = bin_root.join(".rustc-stamp");
@@ -1646,13 +1671,13 @@ fn download_ci_rustc(builder: &Builder<'_>, commit: &str) {
         if bin_root.exists() {
             t!(fs::remove_dir_all(&bin_root));
         }
-        let filename = format!("rust-std-{channel}-{host}.tar.xz");
+        let filename = format!("rust-std-{version}-{host}.tar.xz");
         let pattern = format!("rust-std-{host}");
         download_ci_component(builder, filename, &pattern, commit);
-        let filename = format!("rustc-{channel}-{host}.tar.xz");
+        let filename = format!("rustc-{version}-{host}.tar.xz");
         download_ci_component(builder, filename, "rustc", commit);
         // download-rustc doesn't need its own cargo, it can just use beta's.
-        let filename = format!("rustc-dev-{channel}-{host}.tar.xz");
+        let filename = format!("rustc-dev-{version}-{host}.tar.xz");
         download_ci_component(builder, filename, "rustc-dev", commit);
 
         builder.fix_bin_or_dylib(&bin_root.join("bin").join("rustc"));
diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs
index 2f856c2761c..94a61b727a3 100644
--- a/src/bootstrap/native.rs
+++ b/src/bootstrap/native.rs
@@ -269,8 +269,8 @@ fn download_ci_llvm(builder: &Builder<'_>, llvm_sha: &str) {
     } else {
         &builder.config.stage0_metadata.config.artifacts_server
     };
-    let channel = builder.config.artifact_channel(builder, llvm_sha);
-    let filename = format!("rust-dev-{}-{}.tar.xz", channel, builder.build.build.triple);
+    let version = builder.config.artifact_version_part(builder, llvm_sha);
+    let filename = format!("rust-dev-{}-{}.tar.xz", version, builder.build.build.triple);
     let tarball = rustc_cache.join(&filename);
     if !tarball.exists() {
         let help_on_error = "error: failed to download llvm from ci