Skip to content

Commit 0aa8154

Browse files
committed
Move freshness test to bootstrap
1 parent 3b03124 commit 0aa8154

File tree

10 files changed

+396
-317
lines changed

10 files changed

+396
-317
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ version = "0.1.0"
304304
dependencies = [
305305
"serde",
306306
"serde_derive",
307-
"tempfile",
308307
]
309308

310309
[[package]]

src/bootstrap/Cargo.lock

Lines changed: 79 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ dependencies = [
5656
"sha2",
5757
"sysinfo",
5858
"tar",
59+
"tempfile",
5960
"termcolor",
6061
"toml",
6162
"tracing",
@@ -233,14 +234,20 @@ dependencies = [
233234
"windows-sys 0.59.0",
234235
]
235236

237+
[[package]]
238+
name = "fastrand"
239+
version = "2.3.0"
240+
source = "registry+https://github.com/rust-lang/crates.io-index"
241+
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
242+
236243
[[package]]
237244
name = "fd-lock"
238245
version = "4.0.2"
239246
source = "registry+https://github.com/rust-lang/crates.io-index"
240247
checksum = "7e5768da2206272c81ef0b5e951a41862938a6070da63bcea197899942d3b947"
241248
dependencies = [
242249
"cfg-if",
243-
"rustix",
250+
"rustix 0.38.40",
244251
"windows-sys 0.52.0",
245252
]
246253

@@ -266,6 +273,18 @@ dependencies = [
266273
"version_check",
267274
]
268275

276+
[[package]]
277+
name = "getrandom"
278+
version = "0.3.2"
279+
source = "registry+https://github.com/rust-lang/crates.io-index"
280+
checksum = "73fea8450eea4bac3940448fb7ae50d91f034f941199fcd9d909a5a07aa455f0"
281+
dependencies = [
282+
"cfg-if",
283+
"libc",
284+
"r-efi",
285+
"wasi",
286+
]
287+
269288
[[package]]
270289
name = "globset"
271290
version = "0.4.15"
@@ -355,6 +374,12 @@ version = "0.4.14"
355374
source = "registry+https://github.com/rust-lang/crates.io-index"
356375
checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89"
357376

377+
[[package]]
378+
name = "linux-raw-sys"
379+
version = "0.9.3"
380+
source = "registry+https://github.com/rust-lang/crates.io-index"
381+
checksum = "fe7db12097d22ec582439daf8618b8fdd1a7bef6270e9af3b1ebcd30893cf413"
382+
358383
[[package]]
359384
name = "log"
360385
version = "0.4.22"
@@ -486,6 +511,12 @@ dependencies = [
486511
"proc-macro2",
487512
]
488513

514+
[[package]]
515+
name = "r-efi"
516+
version = "5.2.0"
517+
source = "registry+https://github.com/rust-lang/crates.io-index"
518+
checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5"
519+
489520
[[package]]
490521
name = "redox_syscall"
491522
version = "0.5.7"
@@ -548,10 +579,23 @@ dependencies = [
548579
"bitflags",
549580
"errno",
550581
"libc",
551-
"linux-raw-sys",
582+
"linux-raw-sys 0.4.14",
552583
"windows-sys 0.52.0",
553584
]
554585

586+
[[package]]
587+
name = "rustix"
588+
version = "1.0.2"
589+
source = "registry+https://github.com/rust-lang/crates.io-index"
590+
checksum = "f7178faa4b75a30e269c71e61c353ce2748cf3d76f0c44c393f4e60abf49b825"
591+
dependencies = [
592+
"bitflags",
593+
"errno",
594+
"libc",
595+
"linux-raw-sys 0.9.3",
596+
"windows-sys 0.59.0",
597+
]
598+
555599
[[package]]
556600
name = "ryu"
557601
version = "1.0.18"
@@ -678,6 +722,19 @@ dependencies = [
678722
"xattr",
679723
]
680724

725+
[[package]]
726+
name = "tempfile"
727+
version = "3.19.0"
728+
source = "registry+https://github.com/rust-lang/crates.io-index"
729+
checksum = "488960f40a3fd53d72c2a29a58722561dee8afdd175bd88e3db4677d7b2ba600"
730+
dependencies = [
731+
"fastrand",
732+
"getrandom",
733+
"once_cell",
734+
"rustix 1.0.2",
735+
"windows-sys 0.59.0",
736+
]
737+
681738
[[package]]
682739
name = "termcolor"
683740
version = "1.4.1"
@@ -824,6 +881,15 @@ dependencies = [
824881
"winapi-util",
825882
]
826883

884+
[[package]]
885+
name = "wasi"
886+
version = "0.14.2+wasi-0.2.4"
887+
source = "registry+https://github.com/rust-lang/crates.io-index"
888+
checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3"
889+
dependencies = [
890+
"wit-bindgen-rt",
891+
]
892+
827893
[[package]]
828894
name = "winapi"
829895
version = "0.3.9"
@@ -990,15 +1056,24 @@ version = "0.52.6"
9901056
source = "registry+https://github.com/rust-lang/crates.io-index"
9911057
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
9921058

1059+
[[package]]
1060+
name = "wit-bindgen-rt"
1061+
version = "0.39.0"
1062+
source = "registry+https://github.com/rust-lang/crates.io-index"
1063+
checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1"
1064+
dependencies = [
1065+
"bitflags",
1066+
]
1067+
9931068
[[package]]
9941069
name = "xattr"
9951070
version = "1.3.1"
9961071
source = "registry+https://github.com/rust-lang/crates.io-index"
9971072
checksum = "8da84f1a25939b27f6820d92aed108f83ff920fdf11a7b19366c27c4cda81d4f"
9981073
dependencies = [
9991074
"libc",
1000-
"linux-raw-sys",
1001-
"rustix",
1075+
"linux-raw-sys 0.4.14",
1076+
"rustix 0.38.40",
10021077
]
10031078

10041079
[[package]]

src/bootstrap/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ features = [
8585

8686
[dev-dependencies]
8787
pretty_assertions = "1.4"
88+
tempfile = "3.15.0"
8889

8990
# We care a lot about bootstrap's compile times, so don't include debuginfo for
9091
# dependencies, only bootstrap itself.

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

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::io::Write;
55
use std::path::Path;
66

77
use build_helper::ci::CiEnv;
8+
use build_helper::git::PathFreshness;
89
use clap::CommandFactory;
910
use serde::Deserialize;
1011

@@ -14,6 +15,7 @@ use crate::core::build_steps::clippy::{LintConfig, get_clippy_rules_in_order};
1415
use crate::core::build_steps::llvm;
1516
use crate::core::build_steps::llvm::LLVM_INVALIDATION_PATHS;
1617
use crate::core::config::{LldMode, Target, TargetSelection, TomlConfig};
18+
use crate::utils::tests::git::git_test;
1719

1820
pub(crate) fn parse(config: &str) -> Config {
1921
Config::parse_inner(
@@ -556,3 +558,171 @@ fn test_ci_flag() {
556558
let config = Config::parse_inner(Flags::parse(&["check".into()]), |&_| toml::from_str(""));
557559
assert_eq!(config.is_running_on_ci, CiEnv::is_ci());
558560
}
561+
562+
#[test]
563+
fn test_pr_ci_unchanged_anywhere() {
564+
git_test(|ctx| {
565+
let sha = ctx.create_upstream_merge(&["a"]);
566+
ctx.create_nonupstream_merge(&["b"]);
567+
let src = ctx.check_modifications(&["c"], CiEnv::GitHubActions);
568+
assert_eq!(src, PathFreshness::LastModifiedUpstream { upstream: sha });
569+
});
570+
}
571+
572+
#[test]
573+
fn test_pr_ci_changed_in_pr() {
574+
git_test(|ctx| {
575+
let sha = ctx.create_upstream_merge(&["a"]);
576+
ctx.create_nonupstream_merge(&["b"]);
577+
let src = ctx.check_modifications(&["b"], CiEnv::GitHubActions);
578+
assert_eq!(src, PathFreshness::HasLocalModifications { upstream: sha });
579+
});
580+
}
581+
582+
#[test]
583+
fn test_auto_ci_unchanged_anywhere_select_parent() {
584+
git_test(|ctx| {
585+
let sha = ctx.create_upstream_merge(&["a"]);
586+
ctx.create_upstream_merge(&["b"]);
587+
let src = ctx.check_modifications(&["c"], CiEnv::GitHubActions);
588+
assert_eq!(src, PathFreshness::LastModifiedUpstream { upstream: sha });
589+
});
590+
}
591+
592+
#[test]
593+
fn test_auto_ci_changed_in_pr() {
594+
git_test(|ctx| {
595+
let sha = ctx.create_upstream_merge(&["a"]);
596+
ctx.create_upstream_merge(&["b", "c"]);
597+
let src = ctx.check_modifications(&["c", "d"], CiEnv::GitHubActions);
598+
assert_eq!(src, PathFreshness::HasLocalModifications { upstream: sha });
599+
});
600+
}
601+
602+
#[test]
603+
fn test_local_uncommitted_modifications() {
604+
git_test(|ctx| {
605+
let sha = ctx.create_upstream_merge(&["a"]);
606+
ctx.create_branch("feature");
607+
ctx.modify("a");
608+
609+
assert_eq!(
610+
ctx.check_modifications(&["a", "d"], CiEnv::None),
611+
PathFreshness::HasLocalModifications { upstream: sha }
612+
);
613+
});
614+
}
615+
616+
#[test]
617+
fn test_local_committed_modifications() {
618+
git_test(|ctx| {
619+
let sha = ctx.create_upstream_merge(&["a"]);
620+
ctx.create_upstream_merge(&["b", "c"]);
621+
ctx.create_branch("feature");
622+
ctx.modify("x");
623+
ctx.commit();
624+
ctx.modify("a");
625+
ctx.commit();
626+
627+
assert_eq!(
628+
ctx.check_modifications(&["a", "d"], CiEnv::None),
629+
PathFreshness::HasLocalModifications { upstream: sha }
630+
);
631+
});
632+
}
633+
634+
#[test]
635+
fn test_local_committed_modifications_subdirectory() {
636+
git_test(|ctx| {
637+
let sha = ctx.create_upstream_merge(&["a/b/c"]);
638+
ctx.create_upstream_merge(&["b", "c"]);
639+
ctx.create_branch("feature");
640+
ctx.modify("a/b/d");
641+
ctx.commit();
642+
643+
assert_eq!(
644+
ctx.check_modifications(&["a/b"], CiEnv::None),
645+
PathFreshness::HasLocalModifications { upstream: sha }
646+
);
647+
});
648+
}
649+
650+
#[test]
651+
fn test_local_changes_in_head_upstream() {
652+
git_test(|ctx| {
653+
// We want to resolve to the upstream commit that made modifications to a,
654+
// even if it is currently HEAD
655+
let sha = ctx.create_upstream_merge(&["a"]);
656+
assert_eq!(
657+
ctx.check_modifications(&["a", "d"], CiEnv::None),
658+
PathFreshness::LastModifiedUpstream { upstream: sha }
659+
);
660+
});
661+
}
662+
663+
#[test]
664+
fn test_local_changes_in_previous_upstream() {
665+
git_test(|ctx| {
666+
// We want to resolve to this commit, which modified a
667+
let sha = ctx.create_upstream_merge(&["a", "e"]);
668+
// Not to this commit, which is the latest upstream commit
669+
ctx.create_upstream_merge(&["b", "c"]);
670+
ctx.create_branch("feature");
671+
ctx.modify("d");
672+
ctx.commit();
673+
assert_eq!(
674+
ctx.check_modifications(&["a"], CiEnv::None),
675+
PathFreshness::LastModifiedUpstream { upstream: sha }
676+
);
677+
});
678+
}
679+
680+
#[test]
681+
fn test_local_no_upstream_commit_with_changes() {
682+
git_test(|ctx| {
683+
ctx.create_upstream_merge(&["a", "e"]);
684+
ctx.create_upstream_merge(&["a", "e"]);
685+
// We want to fall back to this commit, because there are no commits
686+
// that modified `x`.
687+
let sha = ctx.create_upstream_merge(&["a", "e"]);
688+
ctx.create_branch("feature");
689+
ctx.modify("d");
690+
ctx.commit();
691+
assert_eq!(
692+
ctx.check_modifications(&["x"], CiEnv::None),
693+
PathFreshness::LastModifiedUpstream { upstream: sha }
694+
);
695+
});
696+
}
697+
698+
#[test]
699+
fn test_local_no_upstream_commit() {
700+
git_test(|ctx| {
701+
let src = ctx.check_modifications(&["c", "d"], CiEnv::None);
702+
assert_eq!(src, PathFreshness::MissingUpstream);
703+
});
704+
}
705+
706+
#[test]
707+
fn test_local_changes_negative_path() {
708+
git_test(|ctx| {
709+
let upstream = ctx.create_upstream_merge(&["a"]);
710+
ctx.create_branch("feature");
711+
ctx.modify("b");
712+
ctx.modify("d");
713+
ctx.commit();
714+
715+
assert_eq!(
716+
ctx.check_modifications(&[":!b", ":!d"], CiEnv::None),
717+
PathFreshness::LastModifiedUpstream { upstream: upstream.clone() }
718+
);
719+
assert_eq!(
720+
ctx.check_modifications(&[":!c"], CiEnv::None),
721+
PathFreshness::HasLocalModifications { upstream: upstream.clone() }
722+
);
723+
assert_eq!(
724+
ctx.check_modifications(&[":!d", ":!x"], CiEnv::None),
725+
PathFreshness::HasLocalModifications { upstream }
726+
);
727+
});
728+
}

src/bootstrap/src/utils/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ pub(crate) mod tracing;
2020
pub(crate) mod metrics;
2121

2222
#[cfg(test)]
23-
mod tests;
23+
pub(crate) mod tests;

0 commit comments

Comments
 (0)