From 5b8786692221c053f2c29c3ad5c125dafc2a2ecb Mon Sep 17 00:00:00 2001 From: Michal Date: Sat, 23 Jul 2022 00:59:20 +0100 Subject: [PATCH] Improved workspace/repository checks --- examples/workspace/mlc.toml | 32 ++++++++------------------------ src/main.rs | 27 ++++++++++++++++++++------- src/repository/repo.rs | 4 +++- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/examples/workspace/mlc.toml b/examples/workspace/mlc.toml index 9a56512..77b0e6a 100644 --- a/examples/workspace/mlc.toml +++ b/examples/workspace/mlc.toml @@ -1,15 +1,15 @@ [base] -mode = "repository" +mode = "workspace" smart_pull = true [mode.repository] -name = "test" -build_on_update = true +name = "" +build_on_update = false [mode.repository.signing] -enabled = true +enabled = false key = "" -on_gen = true +on_gen = false [mode.workspace] @@ -18,26 +18,10 @@ name = [ "1::amethyst", "1::jade!", "2::notop-git", - "3::slippy-rb" + "3::appendage", ] urls = [ "https://github.com/crystal-linux/%repo%", "https://aur.archlinux.org/%repo%", - "https://github.com/jnats/%repo%" -] - -# In this example, Malachite will create a repository called "test", with 4 packages -# These packages will be expanded based on the index number they have (index_number::package) -# To demonstrate, the ones in this config will expand to the following: -# -# https://github.com/crystal-linux/ame -# https://github.com/crystal-linux/jade -# https://aur.archlinux.org/notop-git -# https://github.com/jnats/slippy-rb -# -# The "name" option specifies the name of the pacman repository. -# The "sign" option specifies whether the built packages should be signed, which is recommended for all pacman repositories. -# When in repository mode, malachite only pulls the PKGBUILD file from the git repository (all we need to build the packages from src) -# -# Additionally, packages are built in the order of priority, so packages with a higher priority (denoted by "!"s appended to the name) will be built first. -# In this case, jade has a higher priority than amethyst, so it will be built first. \ No newline at end of file + "https://github.com/not-my-segfault/%repo%" +] \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 5583bea..bce418e 100755 --- a/src/main.rs +++ b/src/main.rs @@ -23,15 +23,19 @@ fn main() { } let args: Args = Args::parse(); - let exclude = &args.exclude; let verbose = args.verbose; + log!(verbose, "Args: {:?}", args); + log!(verbose, "Exclude: {:?}", exclude); + log!(verbose, "Verbose: You guess. :)"); + + let config = read_cfg(verbose); + log!(verbose, "Config: {:?}", config); if Path::exists("../.git".as_ref()) { + log!(verbose, "Detected parent git repository"); info!("Parent directory is a git directory, pulling latest mlc.toml. It is advised you run mlc pull/update in all malachite directories"); - let config = read_cfg(verbose); - let dir = env::current_dir().unwrap(); env::set_current_dir("../").unwrap(); log!(verbose, "Current dir: {:?}", env::current_dir().unwrap()); @@ -72,21 +76,30 @@ fn main() { log!(verbose, "Current dir: {:?}", env::current_dir().unwrap()); } + let repository = config.base.mode == "repository"; + log!(verbose, "Repository Mode: {:?}", repository); + 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), + } => { + if !repository { + crash!( + AppExitCode::BuildInWorkspace, + "Cannot build packages in workspace mode" + ) + } + 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.base.mode != "repository" { + if !repository { crash!( AppExitCode::BuildInWorkspace, "Cannot build packages in workspace mode" ) } - info!("Generating repository: {}", config.mode.repository.name); repository::generate(verbose); } Operation::Config => operations::config(verbose), diff --git a/src/repository/repo.rs b/src/repository/repo.rs index 9b74303..fe4177c 100644 --- a/src/repository/repo.rs +++ b/src/repository/repo.rs @@ -2,7 +2,7 @@ use std::path::Path; use std::process::Command; use std::{env, fs}; -use crate::{crash, internal::AppExitCode, log, workspace::read_cfg}; +use crate::{crash, info, internal::AppExitCode, log, workspace::read_cfg}; pub fn generate(verbose: bool) { // Read config struct from mlc.toml @@ -13,6 +13,8 @@ pub fn generate(verbose: bool) { let name = config.mode.repository.name; log!(verbose, "Name: {}", name); + info!("Generating repository: {}", name); + // If repository exists, delete it if Path::exists(name.as_ref()) { log!(verbose, "Deleting {}", name);