]> git.lizzy.rs Git - rust.git/blob - src/bootstrap/bin/main.rs
e730a2557e0bf38fd1f7a961b059c25c34c85a9b
[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, VERSION};
11
12 fn main() {
13     let args = env::args().skip(1).collect::<Vec<_>>();
14     let config = Config::parse(&args);
15
16     // check_version warnings are not printed during setup
17     let changelog_suggestion =
18         if matches!(config.cmd, Subcommand::Setup { .. }) { None } else { check_version(&config) };
19
20     // NOTE: Since `./configure` generates a `config.toml`, distro maintainers will see the
21     // changelog warning, not the `x.py setup` message.
22     let suggest_setup = !config.config.exists() && !matches!(config.cmd, Subcommand::Setup { .. });
23     if suggest_setup {
24         println!("warning: you have not made a `config.toml`");
25         println!(
26             "help: consider running `./x.py setup` or copying `config.toml.example` by running \
27             `cp config.toml.example config.toml`"
28         );
29     } else if let Some(suggestion) = &changelog_suggestion {
30         println!("{}", suggestion);
31     }
32
33     Build::new(config).build();
34
35     if suggest_setup {
36         println!("warning: you have not made a `config.toml`");
37         println!(
38             "help: consider running `./x.py setup` or copying `config.toml.example` by running \
39             `cp config.toml.example config.toml`"
40         );
41     } else if let Some(suggestion) = &changelog_suggestion {
42         println!("{}", suggestion);
43     }
44
45     if suggest_setup || changelog_suggestion.is_some() {
46         println!("note: this message was printed twice to make it more likely to be seen");
47     }
48 }
49
50 fn check_version(config: &Config) -> Option<String> {
51     let mut msg = String::new();
52
53     let suggestion = if let Some(seen) = config.changelog_seen {
54         if seen != VERSION {
55             msg.push_str("warning: there have been changes to x.py since you last updated.\n");
56             format!("update `config.toml` to use `changelog-seen = {}` instead", VERSION)
57         } else {
58             return None;
59         }
60     } else {
61         msg.push_str("warning: x.py has made several changes recently you may want to look at\n");
62         format!("add `changelog-seen = {}` at the top of `config.toml`", VERSION)
63     };
64
65     msg.push_str("help: consider looking at the changes in `src/bootstrap/CHANGELOG.md`\n");
66     msg.push_str("note: to silence this warning, ");
67     msg.push_str(&suggestion);
68
69     Some(msg)
70 }