build_helper/
stage0_parser.rs1use 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 channel_manifest_hash: String,
14 pub git_commit_hash: String,
15 pub date: String,
16 pub version: String,
17}
18
19#[derive(Default, Clone)]
20pub struct Stage0Config {
21 pub dist_server: String,
22 pub artifacts_server: String,
23 pub artifacts_with_llvm_assertions_server: String,
24 pub git_merge_commit_email: String,
25 pub nightly_branch: String,
26}
27
28pub fn parse_stage0_file() -> Stage0 {
29 let stage0_content = include_str!("../../stage0");
30
31 let mut stage0 = Stage0::default();
32 for line in stage0_content.lines() {
33 let line = line.trim();
34
35 if line.is_empty() {
36 continue;
37 }
38
39 if line.starts_with('#') {
41 continue;
42 }
43
44 let (key, value) = line.split_once('=').unwrap();
45
46 match key {
47 "dist_server" => stage0.config.dist_server = value.to_owned(),
48 "artifacts_server" => stage0.config.artifacts_server = value.to_owned(),
49 "artifacts_with_llvm_assertions_server" => {
50 stage0.config.artifacts_with_llvm_assertions_server = value.to_owned()
51 }
52 "git_merge_commit_email" => stage0.config.git_merge_commit_email = value.to_owned(),
53 "nightly_branch" => stage0.config.nightly_branch = value.to_owned(),
54
55 "compiler_channel_manifest_hash" => {
56 stage0.compiler.channel_manifest_hash = value.to_owned()
57 }
58 "compiler_git_commit_hash" => stage0.compiler.git_commit_hash = value.to_owned(),
59 "compiler_date" => stage0.compiler.date = value.to_owned(),
60 "compiler_version" => stage0.compiler.version = value.to_owned(),
61
62 "rustfmt_channel_manifest_hash" => {
63 stage0.rustfmt.get_or_insert(VersionMetadata::default()).channel_manifest_hash =
64 value.to_owned();
65 }
66 "rustfmt_git_commit_hash" => {
67 stage0.rustfmt.get_or_insert(VersionMetadata::default()).git_commit_hash =
68 value.to_owned();
69 }
70 "rustfmt_date" => {
71 stage0.rustfmt.get_or_insert(VersionMetadata::default()).date = value.to_owned();
72 }
73 "rustfmt_version" => {
74 stage0.rustfmt.get_or_insert(VersionMetadata::default()).version = value.to_owned();
75 }
76
77 dist if dist.starts_with("dist") => {
78 stage0.checksums_sha256.insert(key.to_owned(), value.to_owned());
79 }
80
81 unsupported => {
82 println!("'{unsupported}' field is not supported.");
83 }
84 }
85 }
86
87 stage0
88}