Skip to content

Commit c8cc751

Browse files
Shourya742ZhongyaoChen
authored andcommitted
add read_file_by_commit function and invoke from parse_inner
1 parent 248b7f9 commit c8cc751

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

src/bootstrap/src/core/config/config.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,8 +1168,15 @@ impl Config {
11681168
"WARNING: `rust.download-rustc` is enabled. The `rust.channel` option will be overridden by the CI rustc's channel."
11691169
);
11701170

1171-
let channel =
1172-
config.read_file_by_commit(Path::new("src/ci/channel"), commit).trim().to_owned();
1171+
let channel = read_file_by_commit(
1172+
&config.exec_ctx,
1173+
&config.src,
1174+
&config.rust_info,
1175+
Path::new("src/ci/channel"),
1176+
commit,
1177+
)
1178+
.trim()
1179+
.to_owned();
11731180

11741181
config.channel = channel;
11751182
}
@@ -2751,3 +2758,21 @@ pub(crate) fn ci_llvm_root(
27512758
assert!(llvm_from_ci);
27522759
out.join(host_target).join("ci-llvm")
27532760
}
2761+
2762+
/// Returns the content of the given file at a specific commit.
2763+
pub(crate) fn read_file_by_commit(
2764+
exec_ctx: &ExecutionContext,
2765+
src: &Path,
2766+
rust_info: &channel::GitInfo,
2767+
file: &Path,
2768+
commit: &str,
2769+
) -> String {
2770+
assert!(
2771+
rust_info.is_managed_git_subrepository(),
2772+
"`Config::read_file_by_commit` is not supported in non-git sources."
2773+
);
2774+
2775+
let mut git = helpers::git(Some(src));
2776+
git.arg("show").arg(format!("{commit}:{}", file.to_str().unwrap()));
2777+
git.run_capture_stdout(exec_ctx).stdout()
2778+
}

0 commit comments

Comments
 (0)