added ability to shorten repo urls

main
michal 3 years ago
parent e5010ab082
commit c86a2c23e6

@ -10,8 +10,15 @@ license-file = "LICENSE.md"
name = "mlc"
path = "src/main.rs"
[profile.release]
incremental = true
debug = false
lto = "fat"
codegen-units = 1
[dependencies]
mimalloc = { version = "0.1.27", default-features = false }
clap = { version = "2.34.0", default-features = false }
toml = "0.5.8"
serde = "1.0.134"
serde_derive = "1.0.134"
toml = { version = "0.5.8", default-features = false }
serde = { version = "1.0.134", default-features = false }
serde_derive = { version = "1.0.134", default-features = false }

@ -6,3 +6,17 @@ pub struct Config {
pub name: Option<String>,
pub repo: Vec<String>,
}
#[derive(Debug, Deserialize)]
pub struct UnexpandedConfig {
pub mode: String,
pub name: Option<String>,
pub repo: Vec<String>,
pub urls: Vec<String>,
}
#[derive(Debug)]
pub struct SplitRepo {
pub indx: usize,
pub name: String
}

@ -8,11 +8,22 @@ use crate::repository::create_config;
use crate::workspace::read_cfg;
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
mod internal;
mod repository;
mod workspace;
fn main() {
extern "C" {
fn geteuid() -> u32;
}
if unsafe { geteuid() } == 0 {
crash("Running malachite as root is disallowed as it can lead to system breakage. Instead, malachite will prompt you when it needs superuser permissions".to_string(), 1);
}
fn build_app() -> App<'static, 'static> {
let app = App::new("Malachite")
.version(env!("CARGO_PKG_VERSION"))
@ -25,32 +36,29 @@ fn main() {
.set(ArgSettings::Global)
.help("Sets the level of verbosity"),
)
.arg(
// TODO implement --exclude
Arg::with_name("exclude")
.short("e")
.long("exclude")
.multiple(true)
.set(ArgSettings::Global)
.help("Excludes packages from given operation"),
)
.arg(
// TODO implement --all
Arg::with_name("all")
.long("all")
.set(ArgSettings::Global)
.help("Operates on every possible package"),
)
.subcommand(
SubCommand::with_name("build")
.about("Builds the given packages")
.arg(
Arg::with_name("package(s)")
.help("The packages to operate on")
.required(true)
.multiple(true)
.index(1),
),
)
.arg(
Arg::with_name("all")
.long("all")
.help("Builds all packages in mlc.toml (except if -x is specified)")
.conflicts_with("package(s)")
)
.arg(
Arg::with_name("exclude")
.short("x")
.long("exclude")
.multiple(true)
.takes_value(true)
.help("Excludes packages from given operation")
)
)
.subcommand(
SubCommand::with_name("repo-gen").about("Generates repository from built packages"),
@ -87,6 +95,7 @@ fn main() {
let matches = build_app().get_matches();
if let true = matches.is_present("init") {
let config = workspace::read_cfg();
if config.mode == "workspace" {
@ -110,6 +119,7 @@ fn main() {
.unwrap();
info(format!("Entering working directory: {}", r));
let cdir = env::current_dir().unwrap();
let dir = format!(
"{}/{}",
env::current_dir().unwrap().display(),
@ -132,6 +142,9 @@ fn main() {
.unwrap()
.wait()
.unwrap();
info(format!("Exiting work directory: {}", r));
env::set_current_dir(cdir).unwrap();
}
} else {
crash("Invalid mode in mlc.toml".to_string(), 1);
@ -140,18 +153,26 @@ fn main() {
if let true = matches.is_present("build") {
let config = workspace::read_cfg();
let mut packages: Vec<String> = matches
.subcommand_matches("build")
.unwrap()
.values_of_lossy("package(s)")
.unwrap_or(vec![]);
let exclude: Vec<String> = matches
.subcommand_matches("build")
.unwrap()
.values_of_lossy("exclude")
.unwrap_or(vec![]);
for pkg in &exclude {
packages.retain(|x| &*x != pkg);
}
if config.mode != "repository" {
crash("Cannot build packages in workspace mode".to_string(), 2);
}
let packages: Vec<String> = matches
.subcommand()
.1
.unwrap()
.values_of("package(s)")
.unwrap()
.into_iter()
.map(|s| s.to_string())
.collect();
let mut repos: Vec<String> = vec![];
for r in config.repo {
let split = r.split('/').collect::<Vec<&str>>();
@ -159,6 +180,12 @@ fn main() {
repos.push(a.parse().unwrap());
}
if matches.subcommand_matches("build").unwrap().is_present("exclude") {
for ex in exclude {
repos.retain(|x| *x != ex);
}
}
for pkg in packages {
if !repos.contains(&pkg) {
crash(format!("Package {} not found in repos in mlc.toml", pkg), 3);
@ -166,6 +193,12 @@ fn main() {
repository::build(pkg);
}
}
if matches.subcommand_matches("build").unwrap().is_present("all") {
for pkg in repos {
repository::build(pkg);
}
}
}
if let true = matches.is_present("pull") {

@ -6,7 +6,8 @@ use crate::crash;
const DEFAULT_CONFIG: &str = r#"mode = "" # either "repository" or "workspace"
name = "" # only required when in repository mode, decides what to call the repository and relevant files
repo = [""] # an array of git repos to clone from"#;
repo = [""] # an array of git repos to clone from, formatted url_index::repo_name, e.g. if you had urls = [ "https://example.com/%repo%" ], 1::package would expand to https://example.com/package
urls = [""] # an array of urls to clone from, in the format https://example.com/%repo% (the %repo% is NOT optional)"#;
pub fn create_config() {
if env::current_dir().unwrap().read_dir().unwrap().next().is_some() {

@ -2,7 +2,7 @@ use crate::crash;
use std::fs;
use std::path::Path;
use crate::internal::structs::Config;
use crate::internal::structs::{Config, SplitRepo, UnexpandedConfig};
pub fn read_cfg() -> Config {
if !Path::exists("mlc.toml".as_ref()) {
@ -10,7 +10,34 @@ pub fn read_cfg() -> Config {
}
let file = fs::read_to_string("mlc.toml").unwrap();
let config: Config = toml::from_str(&file).unwrap();
let config: UnexpandedConfig = toml::from_str(&file).unwrap();
config
}
let mut trimmed_urls: Vec<String> = vec![];
let mut expanded_repos: Vec<String> = vec![];
for url in config.urls {
let a = url.split("%repo%").collect::<Vec<&str>>()[0];
let mut b = vec![a.to_string()];
trimmed_urls.append(&mut b);
}
let config_repos = config.repo;
for x in config_repos {
let split: Vec<&str> = x.split("::").collect();
let sr_struct = SplitRepo {
indx: (&split[0]).parse().unwrap(),
name: (&split[1]).parse().unwrap()
};
let index = sr_struct.indx;
let expanded = format!("{}{}", trimmed_urls[index-1], sr_struct.name);
println!("{}", expanded);
expanded_repos.push(expanded);
}
Config {
mode: config.mode,
name: config.name,
repo: expanded_repos
}
}
Loading…
Cancel
Save