Skip to content

Commit 621af4a

Browse files
committed
add read_file_by_commit function and invoke from parse_inner
1 parent 2213b7a commit 621af4a

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
}
@@ -2746,3 +2753,21 @@ pub(crate) fn ci_llvm_root(
27462753
assert!(llvm_from_ci);
27472754
out.join(host_target).join("ci-llvm")
27482755
}
2756+
2757+
/// Returns the content of the given file at a specific commit.
2758+
pub(crate) fn read_file_by_commit(
2759+
exec_ctx: &ExecutionContext,
2760+
src: &Path,
2761+
rust_info: &channel::GitInfo,
2762+
file: &Path,
2763+
commit: &str,
2764+
) -> String {
2765+
assert!(
2766+
rust_info.is_managed_git_subrepository(),
2767+
"`Config::read_file_by_commit` is not supported in non-git sources."
2768+
);
2769+
2770+
let mut git = helpers::git(Some(src));
2771+
git.arg("show").arg(format!("{commit}:{}", file.to_str().unwrap()));
2772+
git.run_capture_stdout(exec_ctx).stdout()
2773+
}

0 commit comments

Comments
 (0)