about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbit-aloo <sshourya17@gmail.com>2025-08-09 07:53:56 +0530
committerbit-aloo <sshourya17@gmail.com>2025-08-09 07:53:56 +0530
commit621af4a580436013e7af848f5abea9bc21b21c9b (patch)
tree346aaf8f0712a1a5bb85ff7fbb6e42332d0d22cc
parent2213b7a8f9c3e778a32cddfc19ec58efefcb902c (diff)
downloadrust-621af4a580436013e7af848f5abea9bc21b21c9b.tar.gz
rust-621af4a580436013e7af848f5abea9bc21b21c9b.zip
add read_file_by_commit function and invoke from parse_inner
-rw-r--r--src/bootstrap/src/core/config/config.rs29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs
index ef8d541500f..af6edb1242c 100644
--- a/src/bootstrap/src/core/config/config.rs
+++ b/src/bootstrap/src/core/config/config.rs
@@ -1168,8 +1168,15 @@ impl Config {
                 "WARNING: `rust.download-rustc` is enabled. The `rust.channel` option will be overridden by the CI rustc's channel."
             );
 
-            let channel =
-                config.read_file_by_commit(Path::new("src/ci/channel"), commit).trim().to_owned();
+            let channel = read_file_by_commit(
+                &config.exec_ctx,
+                &config.src,
+                &config.rust_info,
+                Path::new("src/ci/channel"),
+                commit,
+            )
+            .trim()
+            .to_owned();
 
             config.channel = channel;
         }
@@ -2746,3 +2753,21 @@ pub(crate) fn ci_llvm_root(
     assert!(llvm_from_ci);
     out.join(host_target).join("ci-llvm")
 }
+
+/// Returns the content of the given file at a specific commit.
+pub(crate) fn read_file_by_commit(
+    exec_ctx: &ExecutionContext,
+    src: &Path,
+    rust_info: &channel::GitInfo,
+    file: &Path,
+    commit: &str,
+) -> String {
+    assert!(
+        rust_info.is_managed_git_subrepository(),
+        "`Config::read_file_by_commit` is not supported in non-git sources."
+    );
+
+    let mut git = helpers::git(Some(src));
+    git.arg("show").arg(format!("{commit}:{}", file.to_str().unwrap()));
+    git.run_capture_stdout(exec_ctx).stdout()
+}