|
| 1 | +use std::env::VarError; |
1 | 2 | use std::{panic, thread};
|
2 | 3 |
|
| 4 | +use build_helper::stage0_parser::parse_stage0_file; |
3 | 5 | use llvm::prebuilt_llvm_config;
|
4 | 6 |
|
5 | 7 | use super::*;
|
6 | 8 | use crate::Flags;
|
7 | 9 | use crate::core::build_steps::doc::DocumentationFormat;
|
8 | 10 | use crate::core::config::Config;
|
| 11 | +use crate::utils::tests::git::{GitCtx, git_test}; |
9 | 12 |
|
10 | 13 | static TEST_TRIPLE_1: &str = "i686-unknown-haiku";
|
11 | 14 | static TEST_TRIPLE_2: &str = "i686-unknown-hurd-gnu";
|
@@ -239,42 +242,80 @@ fn alias_and_path_for_library() {
|
239 | 242 | }
|
240 | 243 |
|
241 | 244 | #[test]
|
242 |
| -fn ci_rustc_if_unchanged_logic() { |
243 |
| - let config = Config::parse_inner( |
244 |
| - Flags::parse(&[ |
245 |
| - "build".to_owned(), |
246 |
| - "--dry-run".to_owned(), |
247 |
| - "--set=rust.download-rustc='if-unchanged'".to_owned(), |
248 |
| - ]), |
249 |
| - |&_| Ok(Default::default()), |
250 |
| - ); |
251 |
| - |
252 |
| - let build = Build::new(config.clone()); |
253 |
| - let builder = Builder::new(&build); |
254 |
| - |
255 |
| - if config.out.exists() { |
256 |
| - fs::remove_dir_all(&config.out).unwrap(); |
257 |
| - } |
| 245 | +fn ci_rustc_if_unchanged_invalidate_on_compiler_changes() { |
| 246 | + git_test(|ctx| { |
| 247 | + prepare_rustc_checkout(ctx); |
| 248 | + ctx.create_upstream_merge(&["compiler/bar"]); |
| 249 | + // This change should invalidate download-ci-rustc |
| 250 | + ctx.create_nonupstream_merge(&["compiler/foo"]); |
| 251 | + |
| 252 | + let config = parse_config_download_rustc_at(ctx.get_path(), "if-unchanged", true); |
| 253 | + assert_eq!(config.download_rustc_commit, None); |
| 254 | + }); |
| 255 | +} |
258 | 256 |
|
259 |
| - builder.run_step_descriptions(&Builder::get_step_descriptions(config.cmd.kind()), &[]); |
| 257 | +#[test] |
| 258 | +fn ci_rustc_if_unchanged_invalidate_on_library_changes_in_ci() { |
| 259 | + git_test(|ctx| { |
| 260 | + prepare_rustc_checkout(ctx); |
| 261 | + ctx.create_upstream_merge(&["compiler/bar"]); |
| 262 | + // This change should invalidate download-ci-rustc |
| 263 | + ctx.create_nonupstream_merge(&["library/foo"]); |
| 264 | + |
| 265 | + let config = parse_config_download_rustc_at(ctx.get_path(), "if-unchanged", true); |
| 266 | + assert_eq!(config.download_rustc_commit, None); |
| 267 | + }); |
| 268 | +} |
260 | 269 |
|
261 |
| - // Make sure "if-unchanged" logic doesn't try to use CI rustc while there are changes |
262 |
| - // in compiler and/or library. |
263 |
| - if config.download_rustc_commit.is_some() { |
264 |
| - let mut paths = vec!["compiler"]; |
| 270 | +#[test] |
| 271 | +fn ci_rustc_if_unchanged_do_not_invalidate_on_library_changes_outside_ci() { |
| 272 | + git_test(|ctx| { |
| 273 | + prepare_rustc_checkout(ctx); |
| 274 | + let sha = ctx.create_upstream_merge(&["compiler/bar"]); |
| 275 | + // This change should not invalidate download-ci-rustc |
| 276 | + ctx.create_nonupstream_merge(&["library/foo"]); |
| 277 | + |
| 278 | + let config = parse_config_download_rustc_at(ctx.get_path(), "if-unchanged", false); |
| 279 | + assert_eq!(config.download_rustc_commit, Some(sha)); |
| 280 | + }); |
| 281 | +} |
265 | 282 |
|
266 |
| - // Handle library tree the same way as in `Config::download_ci_rustc_commit`. |
267 |
| - if builder.config.is_running_on_ci { |
268 |
| - paths.push("library"); |
269 |
| - } |
| 283 | +#[test] |
| 284 | +fn ci_rustc_if_unchanged_do_not_invalidate_on_tool_changes() { |
| 285 | + git_test(|ctx| { |
| 286 | + prepare_rustc_checkout(ctx); |
| 287 | + let sha = ctx.create_upstream_merge(&["compiler/bar"]); |
| 288 | + // This change should not invalidate download-ci-rustc |
| 289 | + ctx.create_nonupstream_merge(&["src/tools/foo"]); |
| 290 | + |
| 291 | + let config = parse_config_download_rustc_at(ctx.get_path(), "if-unchanged", true); |
| 292 | + assert_eq!(config.download_rustc_commit, Some(sha)); |
| 293 | + }); |
| 294 | +} |
270 | 295 |
|
271 |
| - let has_changes = config.has_changes_from_upstream(&paths); |
| 296 | +/// Prepares the given directory so that it looks like a rustc checkout. |
| 297 | +/// Also configures `GitCtx` to use the correct merge bot e-mail for upstream merge commits. |
| 298 | +fn prepare_rustc_checkout(ctx: &mut GitCtx) { |
| 299 | + ctx.merge_bot_email = |
| 300 | + format!("Merge bot <{}>", parse_stage0_file().config.git_merge_commit_email); |
| 301 | + ctx.write("src/ci/channel", "nightly"); |
| 302 | + ctx.commit(); |
| 303 | +} |
272 | 304 |
|
273 |
| - assert!( |
274 |
| - !has_changes, |
275 |
| - "CI-rustc can't be used with 'if-unchanged' while there are changes in compiler and/or library." |
276 |
| - ); |
277 |
| - } |
| 305 | +/// Parses a Config directory from `path`, with the given value of `download_rustc`. |
| 306 | +fn parse_config_download_rustc_at(path: &Path, download_rustc: &str, ci: bool) -> Config { |
| 307 | + Config::parse_inner( |
| 308 | + Flags::parse(&[ |
| 309 | + "build".to_owned(), |
| 310 | + "--dry-run".to_owned(), |
| 311 | + "--ci".to_owned(), |
| 312 | + if ci { "true" } else { "false" }.to_owned(), |
| 313 | + format!("--set=rust.download-rustc='{download_rustc}'"), |
| 314 | + "--src".to_owned(), |
| 315 | + path.to_str().unwrap().to_owned(), |
| 316 | + ]), |
| 317 | + |&_| Ok(Default::default()), |
| 318 | + ) |
278 | 319 | }
|
279 | 320 |
|
280 | 321 | mod defaults {
|
|
0 commit comments