Skip to content

Commit bfcd001

Browse files
committed
add test for ci rustc's if-unchanged logic
Signed-off-by: onur-ozkan <work@onurozkan.dev>
1 parent 9826e3e commit bfcd001

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

src/bootstrap/src/core/builder/tests.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,55 @@ fn alias_and_path_for_library() {
212212
assert_eq!(first(cache.all::<doc::Std>()), &[doc_std!(A => A, stage = 0)]);
213213
}
214214

215+
#[test]
216+
fn ci_rustc_if_unchanged_logic() {
217+
let config = Config::parse_inner(
218+
Flags::parse(&[
219+
"build".to_owned(),
220+
"--dry-run".to_owned(),
221+
"--set=rust.download-rustc='if-unchanged'".to_owned(),
222+
]),
223+
|&_| Ok(Default::default()),
224+
);
225+
226+
let build = Build::new(config.clone());
227+
let builder = Builder::new(&build);
228+
229+
if config.rust_info.is_from_tarball() {
230+
return;
231+
}
232+
233+
if config.out.exists() {
234+
fs::remove_dir_all(&config.out).unwrap();
235+
}
236+
237+
builder.run_step_descriptions(&Builder::get_step_descriptions(config.cmd.kind()), &[]);
238+
239+
let commit = helpers::get_closest_merge_base_commit(
240+
Some(&builder.config.src),
241+
&builder.config.git_config(),
242+
&builder.config.stage0_metadata.config.git_merge_commit_email,
243+
&[],
244+
)
245+
.unwrap();
246+
247+
let compiler_path = build.src.join("compiler");
248+
let library_path = build.src.join("library");
249+
250+
let has_changes = helpers::git(Some(&builder.src))
251+
.args(["diff-index", "--quiet", &commit])
252+
.arg("--")
253+
.args([compiler_path, library_path])
254+
.as_command_mut()
255+
.status()
256+
.unwrap()
257+
.success();
258+
259+
assert!(
260+
has_changes != config.out.join(config.build.to_string()).join("ci-rustc-sysroot").exists()
261+
);
262+
}
263+
215264
mod defaults {
216265
use pretty_assertions::assert_eq;
217266

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use super::{ChangeIdWrapper, Config};
1212
use crate::core::build_steps::clippy::get_clippy_rules_in_order;
1313
use crate::core::config::{LldMode, Target, TargetSelection, TomlConfig};
1414

15-
fn parse(config: &str) -> Config {
15+
pub(crate) fn parse(config: &str) -> Config {
1616
Config::parse_inner(
1717
Flags::parse(&["check".to_string(), "--config=/does/not/exist".to_string()]),
1818
|&_| toml::from_str(&config),

0 commit comments

Comments
 (0)