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
for x in config.repositories.repos {
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_struct = if split.len() > 2 {
SplitRepo {
@ -114,5 +114,6 @@ pub fn parse_cfg(verbose: bool) -> Config {
repositories: expanded_repos,
};
log!(verbose, "Config: {:?}", conf);
conf
}

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

@ -1,13 +1,16 @@
use crate::internal::structs::{ErroredPackage, Repo};
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) {
// Read config struct from mlc.toml
let config = internal::parse_cfg(verbose);
let config = crate::internal::parse_cfg(verbose);
log!(verbose, "Config: {:?}", config);
// Check if any packages were passed, if not, imply all
let all = packages.is_empty();
log!(verbose, "All: {:?}", all);
// Parse whether to sign on build or not
let sign = if config.mode.repository.as_ref().unwrap().signing.enabled
&& 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) {
// Otherwise, build
log!(verbose, "Building {}", pkg);
let code = repository::build(pkg, sign, verbose);
log!(
verbose,
@ -54,6 +58,7 @@ pub fn build(packages: &[String], exclude: Vec<String>, no_regen: bool, verbose:
pkg,
code
);
if code != 0 {
let error = ErroredPackage {
name: pkg.to_string(),
@ -81,6 +86,7 @@ pub fn build(packages: &[String], exclude: Vec<String>, no_regen: bool, verbose:
log!(verbose, "Sorted: {:?}", repos);
for pkg in repos {
log!(verbose, "Building {}", pkg.name);
let code = repository::build(&pkg.name, sign, verbose);
log!(
verbose,
@ -88,6 +94,7 @@ pub fn build(packages: &[String], exclude: Vec<String>, no_regen: bool, verbose:
pkg.name,
code
);
if code != 0 {
let error = ErroredPackage {
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 != "./.git" && *x != ".\\.git");
// Enter each directory and check git status
let mut unclean_dirs = vec![];
// Enter each directory and check git status
for dir in &dirs {
let root_dir = std::env::current_dir().unwrap();
log!(verbose, "Entering directory: {}", dir);
std::env::set_current_dir(dir).unwrap();
let status = std::process::Command::new("git")
.arg("status")
.output()
.unwrap();
let output = std::string::String::from_utf8(status.stdout).unwrap();
log!(verbose, "Git status: {}", output);
if output.contains("Your branch is up to date with")
&& !output.contains("Untracked files")
&& !output.contains("Changes not staged for commit")
@ -35,6 +38,7 @@ pub fn clean(verbose: bool, force: bool) {
} else {
unclean_dirs.push(dir);
}
std::env::set_current_dir(&root_dir).unwrap();
log!(verbose, "Current directory: {}", root_dir.display());
}

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

@ -94,9 +94,11 @@ pub fn git_status(verbose: bool, repo: &str, colorblind: bool) -> String {
pub fn info(verbose: bool) {
log!(verbose, "Showing Info");
// Parse config from mlc.toml
let config = crate::internal::parse_cfg(verbose);
log!(verbose, "Config: {:?}", config);
// Check for git_info
let git_info = if config.mode.workspace.is_some() {
config.mode.workspace.as_ref().unwrap().git_info
} else {
@ -104,6 +106,7 @@ pub fn info(verbose: bool) {
};
log!(verbose, "Git info: {}", git_info);
// Check for colorblind mode
let colorblind = if config.mode.workspace.is_some() {
config.mode.workspace.as_ref().unwrap().colorblind
} else {
@ -116,11 +119,14 @@ pub fn info(verbose: bool) {
let mut repos = vec![];
let mut repos_git = vec![];
// Start the spinner
let sp = Spinner::new(
Spinners::Line,
format!("{}", "Parsing Git Info...".bold()),
Color::Green,
);
// Iterate over all repositories
for repo in repos_unparsed {
// Get name with branch, '/' serving as the delimiter
let name = if repo.branch.is_some() {
@ -200,7 +206,7 @@ pub fn info(verbose: bool) {
internal_name
);
// Get terminal width
// Get terminal width for table formatting
let width = match crossterm::terminal::size() {
Ok((w, _)) => w,
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" }
let mut packages: Vec<PackageFile> = vec![];
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();
// Get file name to string
let file = file.to_str().unwrap();
// Match file name against regex
for cap in re.captures_iter(file) {
// Collect regex captures
let name = cap[1].to_string();
let mut ver = cap[2].to_string();
let mut ext = cap[3].to_string();
// Strip leading - from ver and ext
ver.remove(0).to_string();
ext.remove(0).to_string();
let package = PackageFile { name, ver, ext };
log!(verbose, "Package: {:?}", package);
packages.push(package);
@ -65,6 +71,7 @@ pub fn prune(verbose: bool) {
log!(verbose, "Sorting Package: {:?}", package);
let name = &package.name;
let mut found = false;
// Check if name is already present in packages_by_name
for p in &mut packages_by_name {
if &p[0].name == name {
log!(verbose, "Found {}", name);
@ -72,6 +79,7 @@ pub fn prune(verbose: bool) {
p.push(package);
}
}
// If not, create a new vector and push to it
if !found {
log!(verbose, "Creating {}", name);
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));
}
// 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![];
for p in &packages_by_name {
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![];
// Pull
// Pull logic
log!(verbose, "Pulling");
if params.smart_pull {
// Just update the remote
// Update the remote
log!(verbose, "Smart pull");
Command::new("git")
.args(&["remote", "update"])
@ -80,10 +80,12 @@ fn do_the_pulling(repos: Vec<String>, verbose: bool, params: &PullParams) {
env::current_dir().unwrap()
);
// Rebuild packages if necessary
if !packages_to_rebuild.is_empty() && params.build_on_update {
info!("Rebuilding packages: {}", &packages_to_rebuild.join(", "));
log!(verbose, "Rebuilding packages: {:?}", &packages_to_rebuild);
// Push to build
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
let config = crate::parse_cfg(verbose);
log!(verbose, "Config: {:?}", config);
// If no packages are specified, imply all
let all = packages.is_empty();
log!(verbose, "All: {}", all);
// Read smart_pull from config
let smart_pull = config.base.smart_pull;
log!(verbose, "Smart pull: {}", smart_pull);
// Read build_on_update from config
let build_on_update = if config.mode.repository.is_some() {
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 {
log!(verbose, "Building {}", pkg);
log!(verbose, "Signing: {}", sign);
// Set root dir to return after build
let dir = env::current_dir().unwrap();
log!(verbose, "Root dir: {:?}", dir);

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

Loading…
Cancel
Save