]> git.lizzy.rs Git - rust.git/blob - src/bootstrap/run.rs
Merge commit 'b52fb5234cd7c11ecfae51897a6f7fa52e8777fc' into clippyup
[rust.git] / src / bootstrap / run.rs
1 use crate::builder::{Builder, RunConfig, ShouldRun, Step};
2 use crate::dist::distdir;
3 use crate::tool::Tool;
4 use crate::util::output;
5 use std::process::Command;
6
7 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
8 pub struct ExpandYamlAnchors;
9
10 impl Step for ExpandYamlAnchors {
11     type Output = ();
12
13     /// Runs the `expand-yaml_anchors` tool.
14     ///
15     /// This tool in `src/tools` reads the CI configuration files written in YAML and expands the
16     /// anchors in them, since GitHub Actions doesn't support them.
17     fn run(self, builder: &Builder<'_>) {
18         builder.info("Expanding YAML anchors in the GitHub Actions configuration");
19         try_run(
20             builder,
21             &mut builder.tool_cmd(Tool::ExpandYamlAnchors).arg("generate").arg(&builder.src),
22         );
23     }
24
25     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
26         run.path("src/tools/expand-yaml-anchors")
27     }
28
29     fn make_run(run: RunConfig<'_>) {
30         run.builder.ensure(ExpandYamlAnchors);
31     }
32 }
33
34 fn try_run(builder: &Builder<'_>, cmd: &mut Command) -> bool {
35     if !builder.fail_fast {
36         if !builder.try_run(cmd) {
37             let mut failures = builder.delayed_failures.borrow_mut();
38             failures.push(format!("{:?}", cmd));
39             return false;
40         }
41     } else {
42         builder.run(cmd);
43     }
44     true
45 }
46
47 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
48 pub struct BuildManifest;
49
50 impl Step for BuildManifest {
51     type Output = ();
52     const ONLY_HOSTS: bool = true;
53
54     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
55         run.path("src/tools/build-manifest")
56     }
57
58     fn make_run(run: RunConfig<'_>) {
59         run.builder.ensure(BuildManifest);
60     }
61
62     fn run(self, builder: &Builder<'_>) {
63         // This gets called by `promote-release`
64         // (https://github.com/rust-lang/promote-release).
65         let mut cmd = builder.tool_cmd(Tool::BuildManifest);
66         let sign = builder.config.dist_sign_folder.as_ref().unwrap_or_else(|| {
67             panic!("\n\nfailed to specify `dist.sign-folder` in `config.toml`\n\n")
68         });
69         let addr = builder.config.dist_upload_addr.as_ref().unwrap_or_else(|| {
70             panic!("\n\nfailed to specify `dist.upload-addr` in `config.toml`\n\n")
71         });
72
73         let today = output(Command::new("date").arg("+%Y-%m-%d"));
74
75         cmd.arg(sign);
76         cmd.arg(distdir(builder));
77         cmd.arg(today.trim());
78         cmd.arg(addr);
79         cmd.arg(&builder.config.channel);
80
81         builder.create_dir(&distdir(builder));
82         builder.run(&mut cmd);
83     }
84 }
85
86 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
87 pub struct BumpStage0;
88
89 impl Step for BumpStage0 {
90     type Output = ();
91     const ONLY_HOSTS: bool = true;
92
93     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
94         run.path("src/tools/bump-stage0")
95     }
96
97     fn make_run(run: RunConfig<'_>) {
98         run.builder.ensure(BumpStage0);
99     }
100
101     fn run(self, builder: &Builder<'_>) -> Self::Output {
102         let mut cmd = builder.tool_cmd(Tool::BumpStage0);
103         builder.run(&mut cmd);
104     }
105 }
106
107 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
108 pub struct ReplaceVersionPlaceholder;
109
110 impl Step for ReplaceVersionPlaceholder {
111     type Output = ();
112     const ONLY_HOSTS: bool = true;
113
114     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
115         run.path("src/tools/replace-version-placeholder")
116     }
117
118     fn make_run(run: RunConfig<'_>) {
119         run.builder.ensure(ReplaceVersionPlaceholder);
120     }
121
122     fn run(self, builder: &Builder<'_>) -> Self::Output {
123         let mut cmd = builder.tool_cmd(Tool::ReplaceVersionPlaceholder);
124         cmd.arg(&builder.src);
125         builder.run(&mut cmd);
126     }
127 }