1
1
//! This module contains shared utilities for bootstrap tests.
2
2
3
+ use std::path::{Path, PathBuf};
4
+ use std::thread;
5
+
6
+ use tempfile::TempDir;
7
+
3
8
use crate::core::builder::Builder;
4
9
use crate::core::config::DryRun;
5
- use crate::{Build, Config, Flags};
10
+ use crate::{Build, Config, Flags, t };
6
11
7
12
pub mod git;
8
13
14
+ /// Holds temporary state of a bootstrap test.
15
+ /// Right now it is only used to redirect the build directory of the bootstrap
16
+ /// invocation, in the future it would be great if we could actually execute
17
+ /// the whole test with this directory set as the workdir.
18
+ pub struct TestCtx {
19
+ directory: TempDir,
20
+ }
21
+
22
+ impl TestCtx {
23
+ pub fn new() -> Self {
24
+ let directory = TempDir::new().expect("cannot create temporary directory");
25
+ eprintln!("Running test in {}", directory.path().display());
26
+ Self { directory }
27
+ }
28
+
29
+ /// Starts a new invocation of bootstrap that executes `kind` as its top level command
30
+ /// (i.e. `x <kind>`). Returns a builder that configures the created config through CLI flags.
31
+ pub fn config(&self, kind: &str) -> ConfigBuilder {
32
+ ConfigBuilder::from_args(&[kind], self.directory.path().to_owned())
33
+ }
34
+ }
35
+
9
36
/// Used to configure an invocation of bootstrap.
10
37
/// Currently runs in the rustc checkout, long-term it should be switched
11
38
/// to run in a (cache-primed) temporary directory instead.
12
39
pub struct ConfigBuilder {
13
40
args: Vec<String>,
41
+ directory: PathBuf,
14
42
}
15
43
16
44
impl ConfigBuilder {
17
- pub fn from_args(args: &[&str]) -> Self {
18
- Self::new(args)
19
- }
20
-
21
- pub fn build() -> Self {
22
- Self::new(&["build"])
45
+ fn from_args(args: &[&str], directory: PathBuf) -> Self {
46
+ Self { args: args.iter().copied().map(String::from).collect(), directory }
23
47
}
24
48
25
49
pub fn path(mut self, path: &str) -> Self {
@@ -33,14 +57,18 @@ impl ConfigBuilder {
33
57
self
34
58
}
35
59
36
- fn new(args: &[&str]) -> Self {
37
- Self { args: args.iter().copied().map(String::from).collect() }
38
- }
39
-
40
60
pub fn create_config(mut self) -> Config {
41
- let mut config = Config::parse(Flags::parse(&self.args));
42
61
// Run in dry-check, otherwise the test would be too slow
43
- config.set_dry_run(DryRun::SelfCheck);
44
- config
62
+ self.args.push("--dry-run".to_string());
63
+
64
+ // Ignore submodules
65
+ self.args.push("--set".to_string());
66
+ self.args.push("build.submodules=false".to_string());
67
+
68
+ // Do not mess with the local rustc checkout build directory
69
+ self.args.push("--build-dir".to_string());
70
+ self.args.push(self.directory.join("build").display().to_string());
71
+
72
+ Config::parse(Flags::parse(&self.args))
45
73
}
46
74
}
0 commit comments