Read through code, ensured it actually makes sense lol

main
Michal 2 years ago
parent 0b0e35a5af
commit abed0b12fb
No known key found for this signature in database
GPG Key ID: A6A1A4DCB22279B9

@ -41,7 +41,7 @@ pub fn parse_cfg(verbose: bool) -> Config {
// Parsing repos from the config file // Parsing repos from the config file
for x in config.repositories.repos { for x in config.repositories.repos {
log!(verbose, "Parsing repo: {:?}", x); log!(verbose, "Parsing repo: {:?}", x);
// Splits the repo name and index inta a SplitRepo struct // Splits the repo name and index into a SplitRepo struct
let split: Vec<&str> = x.split(':').collect(); let split: Vec<&str> = x.split(':').collect();
let split_struct = if split.len() > 2 { let split_struct = if split.len() > 2 {
SplitRepo { SplitRepo {
@ -114,5 +114,6 @@ pub fn parse_cfg(verbose: bool) -> Config {
repositories: expanded_repos, repositories: expanded_repos,
}; };
log!(verbose, "Config: {:?}", conf); log!(verbose, "Config: {:?}", conf);
conf conf
} }

@ -43,7 +43,6 @@ fn main() {
log!(verbose, "Exclude: {:?}", exclude); log!(verbose, "Exclude: {:?}", exclude);
log!(verbose, "Verbose: You guess. :)"); log!(verbose, "Verbose: You guess. :)");
// Arg matching // Arg matching
match args.subcommand.unwrap_or(Operation::Clone) { match args.subcommand.unwrap_or(Operation::Clone) {
Operation::Clone => operations::clone(verbose), Operation::Clone => operations::clone(verbose),

@ -1,13 +1,16 @@
use crate::internal::structs::{ErroredPackage, Repo}; use crate::internal::structs::{ErroredPackage, Repo};
use crate::internal::AppExitCode; use crate::internal::AppExitCode;
use crate::{crash, info, internal, log, repository}; use crate::{crash, info, log, repository};
pub fn build(packages: &[String], exclude: Vec<String>, no_regen: bool, verbose: bool) { pub fn build(packages: &[String], exclude: Vec<String>, no_regen: bool, verbose: bool) {
// Read config struct from mlc.toml // Read config struct from mlc.toml
let config = internal::parse_cfg(verbose); let config = crate::internal::parse_cfg(verbose);
log!(verbose, "Config: {:?}", config); log!(verbose, "Config: {:?}", config);
// Check if any packages were passed, if not, imply all
let all = packages.is_empty(); let all = packages.is_empty();
log!(verbose, "All: {:?}", all); log!(verbose, "All: {:?}", all);
// Parse whether to sign on build or not
let sign = if config.mode.repository.as_ref().unwrap().signing.enabled let sign = if config.mode.repository.as_ref().unwrap().signing.enabled
&& config.mode.repository.as_ref().unwrap().signing.on_gen && config.mode.repository.as_ref().unwrap().signing.on_gen
{ {
@ -47,6 +50,7 @@ pub fn build(packages: &[String], exclude: Vec<String>, no_regen: bool, verbose:
if repos.iter().map(|x| x.name.clone()).any(|x| x == *pkg) { if repos.iter().map(|x| x.name.clone()).any(|x| x == *pkg) {
// Otherwise, build // Otherwise, build
log!(verbose, "Building {}", pkg); log!(verbose, "Building {}", pkg);
let code = repository::build(pkg, sign, verbose); let code = repository::build(pkg, sign, verbose);
log!( log!(
verbose, verbose,
@ -54,6 +58,7 @@ pub fn build(packages: &[String], exclude: Vec<String>, no_regen: bool, verbose:
pkg, pkg,
code code
); );
if code != 0 { if code != 0 {
let error = ErroredPackage { let error = ErroredPackage {
name: pkg.to_string(), name: pkg.to_string(),
@ -81,6 +86,7 @@ pub fn build(packages: &[String], exclude: Vec<String>, no_regen: bool, verbose:
log!(verbose, "Sorted: {:?}", repos); log!(verbose, "Sorted: {:?}", repos);
for pkg in repos { for pkg in repos {
log!(verbose, "Building {}", pkg.name); log!(verbose, "Building {}", pkg.name);
let code = repository::build(&pkg.name, sign, verbose); let code = repository::build(&pkg.name, sign, verbose);
log!( log!(
verbose, verbose,
@ -88,6 +94,7 @@ pub fn build(packages: &[String], exclude: Vec<String>, no_regen: bool, verbose:
pkg.name, pkg.name,
code code
); );
if code != 0 { if code != 0 {
let error = ErroredPackage { let error = ErroredPackage {
name: pkg.name, name: pkg.name,

@ -13,20 +13,23 @@ pub fn clean(verbose: bool, force: bool) {
dirs.retain(|x| *x != "./mlc.toml" && *x != ".\\mlc.toml"); dirs.retain(|x| *x != "./mlc.toml" && *x != ".\\mlc.toml");
dirs.retain(|x| *x != "./.git" && *x != ".\\.git"); dirs.retain(|x| *x != "./.git" && *x != ".\\.git");
// Enter each directory and check git status
let mut unclean_dirs = vec![]; let mut unclean_dirs = vec![];
// Enter each directory and check git status
for dir in &dirs { for dir in &dirs {
let root_dir = std::env::current_dir().unwrap(); let root_dir = std::env::current_dir().unwrap();
log!(verbose, "Entering directory: {}", dir); log!(verbose, "Entering directory: {}", dir);
std::env::set_current_dir(dir).unwrap(); std::env::set_current_dir(dir).unwrap();
let status = std::process::Command::new("git") let status = std::process::Command::new("git")
.arg("status") .arg("status")
.output() .output()
.unwrap(); .unwrap();
let output = std::string::String::from_utf8(status.stdout).unwrap(); let output = std::string::String::from_utf8(status.stdout).unwrap();
log!(verbose, "Git status: {}", output); log!(verbose, "Git status: {}", output);
if output.contains("Your branch is up to date with") if output.contains("Your branch is up to date with")
&& !output.contains("Untracked files") && !output.contains("Untracked files")
&& !output.contains("Changes not staged for commit") && !output.contains("Changes not staged for commit")
@ -35,6 +38,7 @@ pub fn clean(verbose: bool, force: bool) {
} else { } else {
unclean_dirs.push(dir); unclean_dirs.push(dir);
} }
std::env::set_current_dir(&root_dir).unwrap(); std::env::set_current_dir(&root_dir).unwrap();
log!(verbose, "Current directory: {}", root_dir.display()); log!(verbose, "Current directory: {}", root_dir.display());
} }

@ -7,6 +7,7 @@ pub fn clone(verbose: bool) {
// Read config struct from mlc.toml // Read config struct from mlc.toml
let config = crate::internal::parse_cfg(verbose); let config = crate::internal::parse_cfg(verbose);
log!(verbose, "Config: {:?}", config); log!(verbose, "Config: {:?}", config);
// Parse repositories from config
let repos = &config.repositories; let repos = &config.repositories;
log!(verbose, "Repos: {:?}", repos); log!(verbose, "Repos: {:?}", repos);
@ -15,13 +16,18 @@ pub fn clone(verbose: bool) {
let mut dirs = dir_paths let mut dirs = dir_paths
.map(|x| x.unwrap().path().display().to_string()) .map(|x| x.unwrap().path().display().to_string())
.collect::<Vec<String>>(); .collect::<Vec<String>>();
// Remove mlc.toml and .git from output
dirs.retain(|x| *x != "./mlc.toml" && *x != ".\\mlc.toml"); dirs.retain(|x| *x != "./mlc.toml" && *x != ".\\mlc.toml");
dirs.retain(|x| *x != "./out" && *x != ".\\out"); dirs.retain(|x| *x != "./.git" && *x != ".\\.git");
// If mode is repository, also exclude repository mode directories
if config.mode.repository.is_some() { if config.mode.repository.is_some() {
dirs.retain(|x| { dirs.retain(|x| {
*x != format!("./{}", config.mode.repository.as_ref().unwrap().name) *x != format!("./{}", config.mode.repository.as_ref().unwrap().name)
&& *x != format!(".\\{}", config.mode.repository.as_ref().unwrap().name) && *x != format!(".\\{}", config.mode.repository.as_ref().unwrap().name)
}); });
dirs.retain(|x| *x != "./out" && *x != ".\\out");
} }
log!(verbose, "Paths with mlc.toml excluded: {:?}", dirs); log!(verbose, "Paths with mlc.toml excluded: {:?}", dirs);
@ -29,6 +35,7 @@ pub fn clone(verbose: bool) {
let mut repo_diff = vec![]; let mut repo_diff = vec![];
for repo in repos { for repo in repos {
let name = &repo.name; let name = &repo.name;
if !dirs.contains(&format!("./{}", name)) && !dirs.contains(&format!(".\\{}", name)) { if !dirs.contains(&format!("./{}", name)) && !dirs.contains(&format!(".\\{}", name)) {
repo_diff.push(repo); repo_diff.push(repo);
} }
@ -53,6 +60,7 @@ pub fn clone(verbose: bool) {
for r in repo_diff { for r in repo_diff {
log!(verbose, "Depth: {:?}", r.extra); log!(verbose, "Depth: {:?}", r.extra);
log!(verbose, "Cloning {}", r.name); log!(verbose, "Cloning {}", r.name);
if r.extra.is_some() && config.base.mode == "workspace" { if r.extra.is_some() && config.base.mode == "workspace" {
info!( info!(
"Cloning ({} mode): {} at depth: {}", "Cloning ({} mode): {} at depth: {}",

@ -94,9 +94,11 @@ pub fn git_status(verbose: bool, repo: &str, colorblind: bool) -> String {
pub fn info(verbose: bool) { pub fn info(verbose: bool) {
log!(verbose, "Showing Info"); log!(verbose, "Showing Info");
// Parse config from mlc.toml
let config = crate::internal::parse_cfg(verbose); let config = crate::internal::parse_cfg(verbose);
log!(verbose, "Config: {:?}", config); log!(verbose, "Config: {:?}", config);
// Check for git_info
let git_info = if config.mode.workspace.is_some() { let git_info = if config.mode.workspace.is_some() {
config.mode.workspace.as_ref().unwrap().git_info config.mode.workspace.as_ref().unwrap().git_info
} else { } else {
@ -104,6 +106,7 @@ pub fn info(verbose: bool) {
}; };
log!(verbose, "Git info: {}", git_info); log!(verbose, "Git info: {}", git_info);
// Check for colorblind mode
let colorblind = if config.mode.workspace.is_some() { let colorblind = if config.mode.workspace.is_some() {
config.mode.workspace.as_ref().unwrap().colorblind config.mode.workspace.as_ref().unwrap().colorblind
} else { } else {
@ -116,11 +119,14 @@ pub fn info(verbose: bool) {
let mut repos = vec![]; let mut repos = vec![];
let mut repos_git = vec![]; let mut repos_git = vec![];
// Start the spinner
let sp = Spinner::new( let sp = Spinner::new(
Spinners::Line, Spinners::Line,
format!("{}", "Parsing Git Info...".bold()), format!("{}", "Parsing Git Info...".bold()),
Color::Green, Color::Green,
); );
// Iterate over all repositories
for repo in repos_unparsed { for repo in repos_unparsed {
// Get name with branch, '/' serving as the delimiter // Get name with branch, '/' serving as the delimiter
let name = if repo.branch.is_some() { let name = if repo.branch.is_some() {
@ -200,7 +206,7 @@ pub fn info(verbose: bool) {
internal_name internal_name
); );
// Get terminal width // Get terminal width for table formatting
let width = match crossterm::terminal::size() { let width = match crossterm::terminal::size() {
Ok((w, _)) => w, Ok((w, _)) => w,
Err(_) => 80, Err(_) => 80,

@ -42,17 +42,23 @@ pub fn prune(verbose: bool) {
// Split files into Vec<PackageFile>, turning package-name-1.0.0-1-x86_64.tar.gz into PackageFile { name: "package-name", ver: "1.0.0-1", ext: "x86_64.tar.gz" } // Split files into Vec<PackageFile>, turning package-name-1.0.0-1-x86_64.tar.gz into PackageFile { name: "package-name", ver: "1.0.0-1", ext: "x86_64.tar.gz" }
let mut packages: Vec<PackageFile> = vec![]; let mut packages: Vec<PackageFile> = vec![];
for file in files { for file in files {
// Regex fuckery. Please don't mess with this. // Regex, splits package-name-1.0.0-1-x86_64.tar.gz into 3 groups: package-name, -1.0.0-1, -x86_64.tar.gz
let re = regex::Regex::new(r"^(.+)(-.+-.+)(-.+\..+\..+\.+..+)$").unwrap(); let re = regex::Regex::new(r"^(.+)(-.+-.+)(-.+\..+\..+\.+..+)$").unwrap();
// Get file name to string
let file = file.to_str().unwrap(); let file = file.to_str().unwrap();
// Match file name against regex
for cap in re.captures_iter(file) { for cap in re.captures_iter(file) {
// Collect regex captures // Collect regex captures
let name = cap[1].to_string(); let name = cap[1].to_string();
let mut ver = cap[2].to_string(); let mut ver = cap[2].to_string();
let mut ext = cap[3].to_string(); let mut ext = cap[3].to_string();
// Strip leading - from ver and ext // Strip leading - from ver and ext
ver.remove(0).to_string(); ver.remove(0).to_string();
ext.remove(0).to_string(); ext.remove(0).to_string();
let package = PackageFile { name, ver, ext }; let package = PackageFile { name, ver, ext };
log!(verbose, "Package: {:?}", package); log!(verbose, "Package: {:?}", package);
packages.push(package); packages.push(package);
@ -65,6 +71,7 @@ pub fn prune(verbose: bool) {
log!(verbose, "Sorting Package: {:?}", package); log!(verbose, "Sorting Package: {:?}", package);
let name = &package.name; let name = &package.name;
let mut found = false; let mut found = false;
// Check if name is already present in packages_by_name
for p in &mut packages_by_name { for p in &mut packages_by_name {
if &p[0].name == name { if &p[0].name == name {
log!(verbose, "Found {}", name); log!(verbose, "Found {}", name);
@ -72,6 +79,7 @@ pub fn prune(verbose: bool) {
p.push(package); p.push(package);
} }
} }
// If not, create a new vector and push to it
if !found { if !found {
log!(verbose, "Creating {}", name); log!(verbose, "Creating {}", name);
packages_by_name.push(vec![package]); packages_by_name.push(vec![package]);
@ -84,7 +92,7 @@ pub fn prune(verbose: bool) {
p.sort_by(|a, b| b.ver.cmp(&a.ver)); p.sort_by(|a, b| b.ver.cmp(&a.ver));
} }
// Pushes all but the 4 most recent versions of each package into a new Vector of PackageFiles // Pushes all but the 3 most recent versions of each package into a new Vector of PackageFiles
let mut packages_to_delete: Vec<PackageFile> = vec![]; let mut packages_to_delete: Vec<PackageFile> = vec![];
for p in &packages_by_name { for p in &packages_by_name {
let mut to_delete = vec![]; let mut to_delete = vec![];

@ -23,10 +23,10 @@ fn do_the_pulling(repos: Vec<String>, verbose: bool, params: &PullParams) {
let mut packages_to_rebuild: Vec<String> = vec![]; let mut packages_to_rebuild: Vec<String> = vec![];
// Pull // Pull logic
log!(verbose, "Pulling"); log!(verbose, "Pulling");
if params.smart_pull { if params.smart_pull {
// Just update the remote // Update the remote
log!(verbose, "Smart pull"); log!(verbose, "Smart pull");
Command::new("git") Command::new("git")
.args(&["remote", "update"]) .args(&["remote", "update"])
@ -80,10 +80,12 @@ fn do_the_pulling(repos: Vec<String>, verbose: bool, params: &PullParams) {
env::current_dir().unwrap() env::current_dir().unwrap()
); );
// Rebuild packages if necessary
if !packages_to_rebuild.is_empty() && params.build_on_update { if !packages_to_rebuild.is_empty() && params.build_on_update {
info!("Rebuilding packages: {}", &packages_to_rebuild.join(", ")); info!("Rebuilding packages: {}", &packages_to_rebuild.join(", "));
log!(verbose, "Rebuilding packages: {:?}", &packages_to_rebuild); log!(verbose, "Rebuilding packages: {:?}", &packages_to_rebuild);
// Push to build
crate::operations::build(&packages_to_rebuild, vec![], params.no_regen, verbose); crate::operations::build(&packages_to_rebuild, vec![], params.no_regen, verbose);
} }
} }
@ -93,12 +95,15 @@ pub fn pull(packages: Vec<String>, exclude: &[String], verbose: bool, no_regen:
// Read config file // Read config file
let config = crate::parse_cfg(verbose); let config = crate::parse_cfg(verbose);
log!(verbose, "Config: {:?}", config); log!(verbose, "Config: {:?}", config);
// If no packages are specified, imply all // If no packages are specified, imply all
let all = packages.is_empty(); let all = packages.is_empty();
log!(verbose, "All: {}", all); log!(verbose, "All: {}", all);
// Read smart_pull from config // Read smart_pull from config
let smart_pull = config.base.smart_pull; let smart_pull = config.base.smart_pull;
log!(verbose, "Smart pull: {}", smart_pull); log!(verbose, "Smart pull: {}", smart_pull);
// Read build_on_update from config // Read build_on_update from config
let build_on_update = if config.mode.repository.is_some() { let build_on_update = if config.mode.repository.is_some() {
config.mode.repository.unwrap().build_on_update config.mode.repository.unwrap().build_on_update

@ -8,6 +8,7 @@ use crate::{crash, log};
pub fn build(pkg: &str, sign: bool, verbose: bool) -> i32 { pub fn build(pkg: &str, sign: bool, verbose: bool) -> i32 {
log!(verbose, "Building {}", pkg); log!(verbose, "Building {}", pkg);
log!(verbose, "Signing: {}", sign); log!(verbose, "Signing: {}", sign);
// Set root dir to return after build // Set root dir to return after build
let dir = env::current_dir().unwrap(); let dir = env::current_dir().unwrap();
log!(verbose, "Root dir: {:?}", dir); log!(verbose, "Root dir: {:?}", dir);

@ -45,8 +45,10 @@ pub fn generate(verbose: bool) {
// Get a list of all .tar.* files in repository // Get a list of all .tar.* files in repository
let files = fs::read_dir(".").unwrap(); let files = fs::read_dir(".").unwrap();
for file in files { for file in files {
// Get file name
let file = file.unwrap(); let file = file.unwrap();
let path = file.path(); let path = file.path();
// If extension is either .zst or .xz, sign it
if path.extension().unwrap() == "zst" || path.extension().unwrap() == "xz" { if path.extension().unwrap() == "zst" || path.extension().unwrap() == "xz" {
log!(verbose, "Signing {}", path.display()); log!(verbose, "Signing {}", path.display());
Command::new("bash") Command::new("bash")

Loading…
Cancel
Save