Massive malachite internal rework
parent
a68d201bba
commit
06e906d2ef
@ -1,60 +1,72 @@
|
|||||||
|
use crate::internal::structs::ErroredPackage;
|
||||||
use crate::internal::AppExitCode;
|
use crate::internal::AppExitCode;
|
||||||
use crate::repository::generate;
|
|
||||||
use crate::{crash, info, repository, workspace};
|
use crate::{crash, info, repository, workspace};
|
||||||
|
|
||||||
pub fn build(packages: Vec<String>, exclude: Vec<String>, no_regen: bool) {
|
pub fn build(packages: Vec<String>, exclude: Vec<String>, no_regen: bool) {
|
||||||
let all = packages.is_empty();
|
// Read config struct from mlc.toml
|
||||||
|
|
||||||
let config = workspace::read_cfg();
|
let config = workspace::read_cfg();
|
||||||
|
let all = packages.is_empty();
|
||||||
|
|
||||||
let mut repos: Vec<String> = vec![];
|
// Get list of repos and subtract exclude
|
||||||
for r in config.repo {
|
let mut repos: Vec<String> = config.repo.iter().map(|x| x.name.clone()).collect();
|
||||||
let split = r.split('/').collect::<Vec<&str>>();
|
if !exclude.is_empty() {
|
||||||
let a = split.last().unwrap();
|
|
||||||
repos.push(a.parse().unwrap());
|
|
||||||
}
|
|
||||||
|
|
||||||
if exclude.is_empty() {
|
|
||||||
for ex in exclude {
|
for ex in exclude {
|
||||||
repos.retain(|x| *x != ex);
|
repos.retain(|x| *x != ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut errored: Vec<String> = vec![];
|
// If packages is not empty and all isn't specified, build specifed packages
|
||||||
|
let mut errored: Vec<ErroredPackage> = vec![];
|
||||||
for pkg in packages {
|
if !packages.is_empty() && !all {
|
||||||
if !repos.contains(&pkg) {
|
for pkg in &packages {
|
||||||
crash!(
|
if !repos.contains(pkg) {
|
||||||
AppExitCode::PkgNotFound,
|
crash!(
|
||||||
"Package {} not found in repos in mlc.toml",
|
AppExitCode::PkgNotFound,
|
||||||
pkg
|
"Package repo {} not found in in mlc.toml",
|
||||||
);
|
pkg
|
||||||
} else {
|
);
|
||||||
let code = repository::build(&pkg);
|
} else {
|
||||||
if code != 0 {
|
let code = repository::build(pkg, config.sign);
|
||||||
errored.push(pkg);
|
if code != 0 {
|
||||||
|
let error = ErroredPackage { name: pkg.to_string(), code };
|
||||||
|
errored.push(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If all is specified, attempt to build a package from all repos
|
||||||
if all {
|
if all {
|
||||||
for pkg in repos {
|
for pkg in repos {
|
||||||
let code = repository::build(&pkg);
|
let code = repository::build(&pkg, config.sign);
|
||||||
if code != 0 {
|
if code != 0 {
|
||||||
errored.push(pkg);
|
let error = ErroredPackage { name: pkg, code };
|
||||||
|
errored.push(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
generate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If all is not specified, but packages is empty, crash
|
||||||
|
if !all && packages.is_empty() {
|
||||||
|
crash!(AppExitCode::NoPkgs, "No packages specified");
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no_regen is passed, do not generate a repository
|
||||||
if !no_regen {
|
if !no_regen {
|
||||||
repository::generate();
|
repository::generate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Map errored packages to a string for display
|
||||||
|
let error_strings: Vec<String> = errored
|
||||||
|
.iter()
|
||||||
|
.map(|x| format!("{}: Returned {}", x.name, x.code))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
// If errored is not empty, let the user know which packages failed
|
||||||
if !errored.is_empty() {
|
if !errored.is_empty() {
|
||||||
info!(
|
info!(
|
||||||
"The following packages build jobs returned a non-zero exit code: {}",
|
"The following packages build jobs returned a non-zero exit code: {}",
|
||||||
errored.join(" ")
|
error_strings.join("\n")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,49 @@
|
|||||||
|
use crate::{info, workspace};
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
pub fn clone() {
|
||||||
|
// Read config struct from mlc.toml
|
||||||
|
let config = workspace::read_cfg();
|
||||||
|
let repos = &config.repo;
|
||||||
|
|
||||||
|
// Get a vector of all files/dirs in the current directory, excluding config file
|
||||||
|
let dir_paths = std::fs::read_dir("./").unwrap();
|
||||||
|
let mut dirs = dir_paths
|
||||||
|
.map(|x| x.unwrap().path().display().to_string())
|
||||||
|
.collect::<Vec<String>>();
|
||||||
|
dirs.retain(|x| *x != "./mlc.toml");
|
||||||
|
|
||||||
|
// Creates a vector of the difference between cloned repos and repos defined in config
|
||||||
|
let mut repo_diff = vec![];
|
||||||
|
for repo in repos {
|
||||||
|
let name = &repo.name;
|
||||||
|
if !dirs.contains(name) {
|
||||||
|
repo_diff.push(repo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Diff logic
|
||||||
|
if repo_diff.is_empty() {
|
||||||
|
// No diff, do nothing
|
||||||
|
info!("All repos are already cloned");
|
||||||
|
} else {
|
||||||
|
// This is just for pretty display purposes
|
||||||
|
let display = repo_diff
|
||||||
|
.iter()
|
||||||
|
.map(|x| x.name.to_string())
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
.join(" ");
|
||||||
|
info!("New/missing repos to clone: {}", display);
|
||||||
|
|
||||||
|
// Clone all diff repos
|
||||||
|
for r in repo_diff {
|
||||||
|
info!("Cloning ({} mode): {}", config.mode, r.name);
|
||||||
|
Command::new("git")
|
||||||
|
.args(&["clone", &r.url, &r.name])
|
||||||
|
.spawn()
|
||||||
|
.unwrap()
|
||||||
|
.wait()
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,58 +0,0 @@
|
|||||||
use std::process::Command;
|
|
||||||
|
|
||||||
use crate::internal::AppExitCode;
|
|
||||||
use crate::{crash, info, workspace};
|
|
||||||
|
|
||||||
pub fn init() {
|
|
||||||
let config = workspace::read_cfg();
|
|
||||||
if config.mode == "workspace" || config.mode == "repository" {
|
|
||||||
let dirs_raw = Command::new("ls").arg("-1").output().unwrap().stdout;
|
|
||||||
let dirs_string = String::from_utf8_lossy(&dirs_raw);
|
|
||||||
let mut dirs = dirs_string.lines().collect::<Vec<&str>>();
|
|
||||||
|
|
||||||
dirs.retain(|x| *x != "mlc.toml");
|
|
||||||
dirs.sort_unstable();
|
|
||||||
|
|
||||||
let repos = &config.repo;
|
|
||||||
let mut repos = repos
|
|
||||||
.iter()
|
|
||||||
.map(|x| x.split('/').last().unwrap())
|
|
||||||
.collect::<Vec<&str>>();
|
|
||||||
|
|
||||||
repos.sort_unstable();
|
|
||||||
|
|
||||||
let mut diff = repos.clone();
|
|
||||||
diff.retain(|x| !dirs.contains(x));
|
|
||||||
|
|
||||||
let mut diff_matches = vec![];
|
|
||||||
|
|
||||||
for &x in &diff {
|
|
||||||
for y in config.repo.iter() {
|
|
||||||
if x == y.split('/').last().unwrap() {
|
|
||||||
diff_matches.push(y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if diff.is_empty() {
|
|
||||||
info!("All repos are already cloned");
|
|
||||||
} else {
|
|
||||||
info!("New/missing repos to clone: {}", diff.join(", "));
|
|
||||||
for r in diff_matches {
|
|
||||||
info!(
|
|
||||||
"Cloning ({} mode): {}",
|
|
||||||
config.mode,
|
|
||||||
r.split('/').last().unwrap()
|
|
||||||
);
|
|
||||||
Command::new("git")
|
|
||||||
.args(&["clone", r])
|
|
||||||
.spawn()
|
|
||||||
.unwrap()
|
|
||||||
.wait()
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
crash!(AppExitCode::InvalidMode, "Invalid mode in mlc.toml");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +1,9 @@
|
|||||||
pub use build::*;
|
pub use build::*;
|
||||||
|
pub use clone::*;
|
||||||
pub use config::*;
|
pub use config::*;
|
||||||
pub use init::*;
|
|
||||||
pub use prune::*;
|
|
||||||
pub use pull::*;
|
pub use pull::*;
|
||||||
|
|
||||||
mod build;
|
mod build;
|
||||||
|
mod clone;
|
||||||
mod config;
|
mod config;
|
||||||
mod init;
|
|
||||||
mod prune;
|
|
||||||
mod pull;
|
mod pull;
|
||||||
|
@ -1,56 +0,0 @@
|
|||||||
use std::fs;
|
|
||||||
use std::process::Command;
|
|
||||||
|
|
||||||
use crate::{info, read_cfg};
|
|
||||||
|
|
||||||
pub fn prune() {
|
|
||||||
let config = read_cfg();
|
|
||||||
let mut packages = vec![];
|
|
||||||
for untrimmed_repo in &config.repo {
|
|
||||||
pub fn trim_repo(a: String) -> String {
|
|
||||||
(a.split('/')
|
|
||||||
.map(|s| s.to_string())
|
|
||||||
.collect::<Vec<String>>()
|
|
||||||
.last()
|
|
||||||
.unwrap())
|
|
||||||
.to_string()
|
|
||||||
}
|
|
||||||
packages.push(trim_repo(untrimmed_repo.to_string()));
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut packages_to_del = vec![];
|
|
||||||
|
|
||||||
for pkg in packages {
|
|
||||||
let dups = Command::new("bash")
|
|
||||||
.args(&[
|
|
||||||
"-c",
|
|
||||||
&format!(
|
|
||||||
"ls out/{}*.tar.* -w 1 | grep .sig | sed 's/.sig//g' | sort -r",
|
|
||||||
pkg
|
|
||||||
),
|
|
||||||
])
|
|
||||||
.output()
|
|
||||||
.unwrap()
|
|
||||||
.stdout
|
|
||||||
.to_ascii_lowercase();
|
|
||||||
|
|
||||||
let duplicates = String::from_utf8_lossy(&dups);
|
|
||||||
let duplicates_lines = duplicates.lines().collect::<Vec<&str>>();
|
|
||||||
let variable_hell = duplicates_lines.iter().skip(1).collect::<Vec<&&str>>();
|
|
||||||
|
|
||||||
if !variable_hell.is_empty() {
|
|
||||||
for var in variable_hell {
|
|
||||||
packages_to_del.push(var.to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !packages_to_del.is_empty() {
|
|
||||||
info!("Pruning duplicates: {}", packages_to_del.join(", "));
|
|
||||||
}
|
|
||||||
|
|
||||||
for pkg in packages_to_del {
|
|
||||||
fs::remove_file(&pkg).unwrap();
|
|
||||||
fs::remove_file(format!("{}.sig", &pkg)).unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,40 +1,57 @@
|
|||||||
|
use crate::{internal::AppExitCode, crash};
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
use crate::info;
|
use crate::info;
|
||||||
|
|
||||||
fn do_the_pulling(packages: Vec<String>) {
|
fn do_the_pulling(repos: Vec<String>) {
|
||||||
for dir in packages {
|
for repo in repos {
|
||||||
let current_dir = env::current_dir().unwrap();
|
// Set root dir to return after each git pull
|
||||||
info!("Entering working directory: {}", dir);
|
let root_dir = env::current_dir().unwrap();
|
||||||
env::set_current_dir(dir).unwrap();
|
info!("Entering working directory: {}", &repo);
|
||||||
|
env::set_current_dir(repo).unwrap();
|
||||||
Command::new("git")
|
Command::new("git")
|
||||||
.arg("pull")
|
.arg("pull")
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.wait()
|
.wait()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
env::set_current_dir(current_dir).unwrap();
|
|
||||||
|
// Return to root dir
|
||||||
|
env::set_current_dir(root_dir).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pull(packages: Vec<String>, exclude: Vec<String>) {
|
pub fn pull(packages: Vec<String>, exclude: Vec<String>) {
|
||||||
|
// If no packages are specified, imply all
|
||||||
let all = packages.is_empty();
|
let all = packages.is_empty();
|
||||||
if all {
|
|
||||||
let stdout = Command::new("ls").arg("-1").output().unwrap().stdout;
|
|
||||||
let dirs_string = String::from_utf8_lossy(&stdout);
|
|
||||||
|
|
||||||
let mut dirs = dirs_string.lines().collect::<Vec<&str>>();
|
// Read repos from config file
|
||||||
|
let repos = crate::workspace::read_cfg()
|
||||||
|
.repo
|
||||||
|
.iter()
|
||||||
|
.map(|x| x.name.clone())
|
||||||
|
.collect::<Vec<String>>();
|
||||||
|
|
||||||
dirs.retain(|x| *x != "mlc.toml");
|
// Set repos_applicable for next function
|
||||||
for x in exclude {
|
let mut repos_applicable = if all {
|
||||||
dirs.retain(|y| *y != x);
|
repos
|
||||||
}
|
} else {
|
||||||
|
packages
|
||||||
|
};
|
||||||
|
|
||||||
let dirs_mapped = dirs.iter().map(|x| x.to_string()).collect();
|
// Subtract exclude from repos_applicable
|
||||||
|
if !exclude.is_empty() {
|
||||||
|
for ex in exclude {
|
||||||
|
repos_applicable.retain(|x| *x != ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
do_the_pulling(dirs_mapped);
|
// If all is not specified and packages is empty, crash
|
||||||
} else {
|
if repos_applicable.is_empty() {
|
||||||
do_the_pulling(packages);
|
crash!(AppExitCode::NoPkgs, "No packages specified");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pull!
|
||||||
|
do_the_pulling(repos_applicable);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue