]> git.lizzy.rs Git - rust.git/blob - src/bootstrap/run.rs
Rollup merge of #103945 - H4x5:remove-iter-empty-hack, r=compiler-errors
[rust.git] / src / bootstrap / run.rs
1 use std::path::PathBuf;
2 use std::process::Command;
3
4 use crate::builder::{Builder, RunConfig, ShouldRun, Step};
5 use crate::config::TargetSelection;
6 use crate::dist::distdir;
7 use crate::test;
8 use crate::tool::{self, SourceType, Tool};
9 use crate::util::output;
10 use crate::Mode;
11
12 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
13 pub struct ExpandYamlAnchors;
14
15 impl Step for ExpandYamlAnchors {
16     type Output = ();
17
18     /// Runs the `expand-yaml_anchors` tool.
19     ///
20     /// This tool in `src/tools` reads the CI configuration files written in YAML and expands the
21     /// anchors in them, since GitHub Actions doesn't support them.
22     fn run(self, builder: &Builder<'_>) {
23         builder.info("Expanding YAML anchors in the GitHub Actions configuration");
24         try_run(
25             builder,
26             &mut builder.tool_cmd(Tool::ExpandYamlAnchors).arg("generate").arg(&builder.src),
27         );
28     }
29
30     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
31         run.path("src/tools/expand-yaml-anchors")
32     }
33
34     fn make_run(run: RunConfig<'_>) {
35         run.builder.ensure(ExpandYamlAnchors);
36     }
37 }
38
39 fn try_run(builder: &Builder<'_>, cmd: &mut Command) -> bool {
40     if !builder.fail_fast {
41         if !builder.try_run(cmd) {
42             let mut failures = builder.delayed_failures.borrow_mut();
43             failures.push(format!("{:?}", cmd));
44             return false;
45         }
46     } else {
47         builder.run(cmd);
48     }
49     true
50 }
51
52 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
53 pub struct BuildManifest;
54
55 impl Step for BuildManifest {
56     type Output = ();
57     const ONLY_HOSTS: bool = true;
58
59     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
60         run.path("src/tools/build-manifest")
61     }
62
63     fn make_run(run: RunConfig<'_>) {
64         run.builder.ensure(BuildManifest);
65     }
66
67     fn run(self, builder: &Builder<'_>) {
68         // This gets called by `promote-release`
69         // (https://github.com/rust-lang/promote-release).
70         let mut cmd = builder.tool_cmd(Tool::BuildManifest);
71         let sign = builder.config.dist_sign_folder.as_ref().unwrap_or_else(|| {
72             panic!("\n\nfailed to specify `dist.sign-folder` in `config.toml`\n\n")
73         });
74         let addr = builder.config.dist_upload_addr.as_ref().unwrap_or_else(|| {
75             panic!("\n\nfailed to specify `dist.upload-addr` in `config.toml`\n\n")
76         });
77
78         let today = output(Command::new("date").arg("+%Y-%m-%d"));
79
80         cmd.arg(sign);
81         cmd.arg(distdir(builder));
82         cmd.arg(today.trim());
83         cmd.arg(addr);
84         cmd.arg(&builder.config.channel);
85
86         builder.create_dir(&distdir(builder));
87         builder.run(&mut cmd);
88     }
89 }
90
91 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
92 pub struct BumpStage0;
93
94 impl Step for BumpStage0 {
95     type Output = ();
96     const ONLY_HOSTS: bool = true;
97
98     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
99         run.path("src/tools/bump-stage0")
100     }
101
102     fn make_run(run: RunConfig<'_>) {
103         run.builder.ensure(BumpStage0);
104     }
105
106     fn run(self, builder: &Builder<'_>) -> Self::Output {
107         let mut cmd = builder.tool_cmd(Tool::BumpStage0);
108         builder.run(&mut cmd);
109     }
110 }
111
112 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
113 pub struct ReplaceVersionPlaceholder;
114
115 impl Step for ReplaceVersionPlaceholder {
116     type Output = ();
117     const ONLY_HOSTS: bool = true;
118
119     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
120         run.path("src/tools/replace-version-placeholder")
121     }
122
123     fn make_run(run: RunConfig<'_>) {
124         run.builder.ensure(ReplaceVersionPlaceholder);
125     }
126
127     fn run(self, builder: &Builder<'_>) -> Self::Output {
128         let mut cmd = builder.tool_cmd(Tool::ReplaceVersionPlaceholder);
129         cmd.arg(&builder.src);
130         builder.run(&mut cmd);
131     }
132 }
133
134 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
135 pub struct Miri {
136     stage: u32,
137     host: TargetSelection,
138     target: TargetSelection,
139 }
140
141 impl Step for Miri {
142     type Output = ();
143     const ONLY_HOSTS: bool = false;
144
145     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
146         run.path("src/tools/miri")
147     }
148
149     fn make_run(run: RunConfig<'_>) {
150         run.builder.ensure(Miri {
151             stage: run.builder.top_stage,
152             host: run.build_triple(),
153             target: run.target,
154         });
155     }
156
157     fn run(self, builder: &Builder<'_>) {
158         let stage = self.stage;
159         let host = self.host;
160         let target = self.target;
161         let compiler = builder.compiler(stage, host);
162
163         let miri = builder
164             .ensure(tool::Miri { compiler, target: self.host, extra_features: Vec::new() })
165             .expect("in-tree tool");
166         let miri_sysroot = test::Miri::build_miri_sysroot(builder, compiler, &miri, target);
167
168         // # Run miri.
169         // Running it via `cargo run` as that figures out the right dylib path.
170         // add_rustc_lib_path does not add the path that contains librustc_driver-<...>.so.
171         let mut miri = tool::prepare_tool_cargo(
172             builder,
173             compiler,
174             Mode::ToolRustc,
175             host,
176             "run",
177             "src/tools/miri",
178             SourceType::InTree,
179             &[],
180         );
181         miri.add_rustc_lib_path(builder, compiler);
182         // Forward arguments.
183         miri.arg("--").arg("--target").arg(target.rustc_target_arg());
184         miri.args(builder.config.cmd.args());
185
186         // miri tests need to know about the stage sysroot
187         miri.env("MIRI_SYSROOT", &miri_sysroot);
188
189         let mut miri = Command::from(miri);
190         builder.run(&mut miri);
191     }
192 }
193
194 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
195 pub struct CollectLicenseMetadata;
196
197 impl Step for CollectLicenseMetadata {
198     type Output = PathBuf;
199     const ONLY_HOSTS: bool = true;
200
201     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
202         run.path("src/tools/collect-license-metadata")
203     }
204
205     fn make_run(run: RunConfig<'_>) {
206         run.builder.ensure(CollectLicenseMetadata);
207     }
208
209     fn run(self, builder: &Builder<'_>) -> Self::Output {
210         let Some(reuse) = &builder.config.reuse else {
211             panic!("REUSE is required to collect the license metadata");
212         };
213
214         // Temporary location, it will be moved to src/etc once it's accurate.
215         let dest = builder.out.join("license-metadata.json");
216
217         let mut cmd = builder.tool_cmd(Tool::CollectLicenseMetadata);
218         cmd.env("REUSE_EXE", reuse);
219         cmd.env("DEST", &dest);
220         builder.run(&mut cmd);
221
222         dest
223     }
224 }
225
226 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
227 pub struct GenerateCopyright;
228
229 impl Step for GenerateCopyright {
230     type Output = PathBuf;
231     const ONLY_HOSTS: bool = true;
232
233     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
234         run.path("src/tools/generate-copyright")
235     }
236
237     fn make_run(run: RunConfig<'_>) {
238         run.builder.ensure(GenerateCopyright);
239     }
240
241     fn run(self, builder: &Builder<'_>) -> Self::Output {
242         let license_metadata = builder.ensure(CollectLicenseMetadata);
243
244         // Temporary location, it will be moved to the proper one once it's accurate.
245         let dest = builder.out.join("COPYRIGHT.md");
246
247         let mut cmd = builder.tool_cmd(Tool::GenerateCopyright);
248         cmd.env("LICENSE_METADATA", &license_metadata);
249         cmd.env("DEST", &dest);
250         builder.run(&mut cmd);
251
252         dest
253     }
254 }