build_helper/
stage0_parser.rs

1use std::collections::BTreeMap;
2
3#[derive(Default, Clone)]
4pub struct Stage0 {
5    pub compiler: VersionMetadata,
6    pub rustfmt: Option<VersionMetadata>,
7    pub config: Stage0Config,
8    pub checksums_sha256: BTreeMap<String, String>,
9}
10
11#[derive(Default, Clone)]
12pub struct VersionMetadata {
13    pub date: String,
14    pub version: String,
15}
16
17#[derive(Default, Clone)]
18pub struct Stage0Config {
19    pub dist_server: String,
20    pub artifacts_server: String,
21    pub artifacts_with_llvm_assertions_server: String,
22    pub git_merge_commit_email: String,
23    pub nightly_branch: String,
24}
25
26pub fn parse_stage0_file() -> Stage0 {
27    let stage0_content = include_str!("../../stage0");
28
29    let mut stage0 = Stage0::default();
30    for line in stage0_content.lines() {
31        let line = line.trim();
32
33        if line.is_empty() {
34            continue;
35        }
36
37        // Ignore comments
38        if line.starts_with('#') {
39            continue;
40        }
41
42        let (key, value) = line.split_once('=').unwrap();
43
44        match key {
45            "dist_server" => stage0.config.dist_server = value.to_owned(),
46            "artifacts_server" => stage0.config.artifacts_server = value.to_owned(),
47            "artifacts_with_llvm_assertions_server" => {
48                stage0.config.artifacts_with_llvm_assertions_server = value.to_owned()
49            }
50            "git_merge_commit_email" => stage0.config.git_merge_commit_email = value.to_owned(),
51            "nightly_branch" => stage0.config.nightly_branch = value.to_owned(),
52
53            "compiler_date" => stage0.compiler.date = value.to_owned(),
54            "compiler_version" => stage0.compiler.version = value.to_owned(),
55
56            "rustfmt_date" => {
57                stage0.rustfmt.get_or_insert(VersionMetadata::default()).date = value.to_owned();
58            }
59            "rustfmt_version" => {
60                stage0.rustfmt.get_or_insert(VersionMetadata::default()).version = value.to_owned();
61            }
62
63            dist if dist.starts_with("dist") => {
64                stage0.checksums_sha256.insert(key.to_owned(), value.to_owned());
65            }
66
67            unsupported => {
68                println!("'{unsupported}' field is not supported.");
69            }
70        }
71    }
72
73    stage0
74}