]> git.lizzy.rs Git - rust.git/blob - src/bootstrap/bin/main.rs
Add `x.py setup`
[rust.git] / src / bootstrap / bin / main.rs
1 //! rustbuild, the Rust build system
2 //!
3 //! This is the entry point for the build system used to compile the `rustc`
4 //! compiler. Lots of documentation can be found in the `README.md` file in the
5 //! parent directory, and otherwise documentation can be found throughout the `build`
6 //! directory in each respective module.
7
8 use std::env;
9
10 use bootstrap::{Build, Config, Subcommand};
11
12 fn main() {
13     let args = env::args().skip(1).collect::<Vec<_>>();
14     let config = Config::parse(&args);
15
16     let changelog_suggestion = check_version(&config);
17
18     // NOTE: Since `./configure` generates a `config.toml`, distro maintainers will see the
19     // changelog warning, not the `x.py setup` message.
20     let suggest_setup = !config.config.exists() && !matches!(config.cmd, Subcommand::Setup { .. });
21     if suggest_setup {
22         println!("warning: you have not made a `config.toml`");
23         println!("help: consider running `x.py setup` or copying `config.toml.example`");
24     } else if let Some(suggestion) = &changelog_suggestion {
25         println!("{}", suggestion);
26     }
27
28     Build::new(config).build();
29
30     if suggest_setup {
31         println!("warning: you have not made a `config.toml`");
32         println!("help: consider running `x.py setup` or copying `config.toml.example`");
33     } else if let Some(suggestion) = &changelog_suggestion {
34         println!("{}", suggestion);
35     }
36
37     if suggest_setup || changelog_suggestion.is_some() {
38         println!("note: this message was printed twice to make it more likely to be seen");
39     }
40 }
41
42 fn check_version(config: &Config) -> Option<String> {
43     const VERSION: usize = 1;
44
45     let mut msg = String::new();
46
47     let suggestion = if let Some(seen) = config.changelog_seen {
48         if seen != VERSION {
49             msg.push_str("warning: there have been changes to x.py since you last updated.\n");
50             format!("update `config.toml` to use `changelog-seen = {}` instead", VERSION)
51         } else {
52             return None;
53         }
54     } else {
55         msg.push_str("warning: x.py has made several changes recently you may want to look at\n");
56         format!("add `changelog-seen = {}` to `config.toml`", VERSION)
57     };
58
59     msg.push_str("help: consider looking at the changes in `src/bootstrap/CHANGELOG.md`\n");
60     msg.push_str("note: to silence this warning, ");
61     msg.push_str(&suggestion);
62
63     Some(msg)
64 }