rust/compiler/rustc_codegen_gcc/build_system/src/main.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

103 lines
2.6 KiB
Rust
Raw Normal View History

2023-08-18 14:06:20 +00:00
use std::{env, process};
mod build;
2023-12-20 13:58:43 +00:00
mod clean;
2024-02-26 17:12:12 +00:00
mod clone_gcc;
2023-09-26 14:09:51 +00:00
mod config;
2024-05-02 13:20:40 +00:00
mod fmt;
mod info;
2023-08-18 14:06:20 +00:00
mod prepare;
mod rust_tools;
2023-08-18 14:06:20 +00:00
mod rustc_info;
mod test;
2023-08-18 14:06:20 +00:00
mod utils;
const BUILD_DIR: &str = "build";
2023-08-18 14:06:20 +00:00
macro_rules! arg_error {
($($err:tt)*) => {{
eprintln!($($err)*);
2023-09-25 15:12:40 +00:00
eprintln!();
2023-08-18 14:06:20 +00:00
usage();
std::process::exit(1);
}};
}
fn usage() {
2023-09-26 14:09:51 +00:00
println!(
"\
rustc_codegen_gcc build system
Usage: build_system [command] [options]
Options:
--help : Displays this help message.
Commands:
cargo : Executes a cargo command.
rustc : Compiles the program using the GCC compiler.
clean : Cleans the build directory, removing all compiled files and artifacts.
prepare : Prepares the environment for building, including fetching dependencies and setting up configurations.
build : Compiles the project.
test : Runs tests for the project.
info : Displays information about the build environment and project configuration.
2024-05-02 13:20:40 +00:00
clone-gcc : Clones the GCC compiler from a specified source.
fmt : Runs rustfmt"
2023-09-26 14:09:51 +00:00
);
2023-08-18 14:06:20 +00:00
}
pub enum Command {
2023-12-21 22:46:41 +00:00
Cargo,
2023-12-20 13:58:43 +00:00
Clean,
2024-02-26 17:12:12 +00:00
CloneGcc,
2023-08-18 14:06:20 +00:00
Prepare,
Build,
2024-04-05 15:32:19 +00:00
Rustc,
Test,
Info,
2024-05-02 13:20:40 +00:00
Fmt,
2023-08-18 14:06:20 +00:00
}
fn main() {
if env::var("RUST_BACKTRACE").is_err() {
env::set_var("RUST_BACKTRACE", "1");
}
let command = match env::args().nth(1).as_deref() {
2023-12-21 22:46:41 +00:00
Some("cargo") => Command::Cargo,
2024-04-05 15:32:19 +00:00
Some("rustc") => Command::Rustc,
2023-12-20 13:58:43 +00:00
Some("clean") => Command::Clean,
2023-08-18 14:06:20 +00:00
Some("prepare") => Command::Prepare,
Some("build") => Command::Build,
Some("test") => Command::Test,
Some("info") => Command::Info,
2024-02-26 17:12:12 +00:00
Some("clone-gcc") => Command::CloneGcc,
2024-05-02 13:20:40 +00:00
Some("fmt") => Command::Fmt,
2023-09-25 15:12:40 +00:00
Some("--help") => {
usage();
process::exit(0);
}
2023-08-18 14:06:20 +00:00
Some(flag) if flag.starts_with('-') => arg_error!("Expected command found flag {}", flag),
Some(command) => arg_error!("Unknown command {}", command),
None => {
usage();
process::exit(0);
}
};
if let Err(e) = match command {
Command::Cargo => rust_tools::run_cargo(),
2024-04-05 15:32:19 +00:00
Command::Rustc => rust_tools::run_rustc(),
2023-12-20 13:58:43 +00:00
Command::Clean => clean::run(),
2023-08-18 14:06:20 +00:00
Command::Prepare => prepare::run(),
Command::Build => build::run(),
Command::Test => test::run(),
Command::Info => info::run(),
2024-02-26 17:12:12 +00:00
Command::CloneGcc => clone_gcc::run(),
2024-05-02 13:20:40 +00:00
Command::Fmt => fmt::run(),
2023-08-18 14:06:20 +00:00
} {
eprintln!("Command failed to run: {e}");
2023-08-18 14:06:20 +00:00
process::exit(1);
}
}