You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
malachite/src/main.rs

77 lines
2.4 KiB
Rust

2 years ago
use clap::Parser;
use std::env;
use std::path::Path;
3 years ago
use std::process::Command;
use crate::args::{Args, Operation};
use crate::internal::AppExitCode;
use crate::repository::create_config;
3 years ago
use crate::workspace::read_cfg;
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
mod args;
3 years ago
mod internal;
3 years ago
mod operations;
3 years ago
mod repository;
mod workspace;
3 years ago
fn main() {
if unsafe { libc::geteuid() } == 0 {
crash!(AppExitCode::RunAsRoot, "Running malachite as root is disallowed as it can lead to system breakage. Instead, malachite will prompt you when it needs superuser permissions");
}
let args: Args = Args::parse();
3 years ago
if Path::exists("mlc.toml".as_ref()) && Path::exists(".git".as_ref()) {
2 years ago
info!(
"In a git repository, pulling latest mlc.toml. It is advised you run mlc pull/update"
);
Command::new("git")
.arg("pull")
.spawn()
.unwrap()
.wait()
.unwrap();
}
let exclude = &args.exclude;
let verbose = args.verbose;
if Path::exists("../.git".as_ref()) {
info!("Parent directory is a git directory, pulling latest mlc.toml. It is advised you run mlc pull/update in all malachite directories");
let dir = env::current_dir().unwrap();
env::set_current_dir("../").unwrap();
Command::new("git")
.arg("pull")
.spawn()
.unwrap()
.wait()
.unwrap();
env::set_current_dir(dir).unwrap();
}
match args.subcommand.unwrap_or(Operation::Clone) {
Operation::Clone => operations::clone(verbose),
Operation::Build {
packages, no_regen, ..
} => operations::build(packages, exclude.to_vec(), no_regen, verbose),
Operation::Pull { packages, .. } => operations::pull(packages, exclude.to_vec(), verbose),
Operation::RepoGen => {
let config = read_cfg(verbose);
if config.mode != "repository" {
2 years ago
crash!(
AppExitCode::BuildInWorkspace,
"Cannot build packages in workspace mode"
)
}
info!("Generating repository: {}", config.name.unwrap());
repository::generate(verbose);
3 years ago
}
Operation::Config => operations::config(verbose),
Operation::Prune => operations::prune(verbose),
Operation::Clean => operations::clean(verbose),
}
3 years ago
}