Made things vaguely non-linux-centric for potential msys2 support

main
Michal 2 years ago
parent cdf5e68a09
commit 58a0de3f89

@ -20,7 +20,6 @@ lto = "fat"
codegen-units = 1 codegen-units = 1
[dependencies] [dependencies]
mimalloc = { version = "0.1.29" }
clap = { version = "3.2.8", features = ["derive", "suggestions"] } clap = { version = "3.2.8", features = ["derive", "suggestions"] }
toml = { version = "0.5.9", default-features = false } toml = { version = "0.5.9", default-features = false }
serde = { version = "1.0.139", default-features = false } serde = { version = "1.0.139", default-features = false }
@ -31,3 +30,6 @@ tabled = { version = "0.8.0", default-features = false, features = ["derive", "c
crossterm = { version = "0.24.0", default-features = false } crossterm = { version = "0.24.0", default-features = false }
regex = { version = "1.6.0", default-features = false, features = ["std"] } regex = { version = "1.6.0", default-features = false, features = ["std"] }
spinoff = { version = "0.4.0", default-features = false } spinoff = { version = "0.4.0", default-features = false }
[target.'cfg(target_os = "linux")'.dependencies]
mimalloc = { version = "0.1.29" }

@ -1,4 +1,5 @@
pub enum AppExitCode { pub enum AppExitCode {
#[cfg(target_os = "linux")]
RunAsRoot = 1, RunAsRoot = 1,
BuildInWorkspace = 2, BuildInWorkspace = 2,
PkgNotFound = 3, PkgNotFound = 3,

@ -7,6 +7,7 @@ use crate::args::{Args, Operation};
use crate::internal::parse_cfg; use crate::internal::parse_cfg;
use crate::internal::AppExitCode; use crate::internal::AppExitCode;
#[cfg(target_os = "linux")]
#[global_allocator] #[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

@ -3,15 +3,15 @@ use crate::{crash, info, internal::AppExitCode, log};
pub fn clean(verbose: bool, force: bool) { pub fn clean(verbose: bool, force: bool) {
info!("Resetting mlc repo, deleting all directories"); info!("Resetting mlc repo, deleting all directories");
// Get a vec of all files/dirs in the current directory // Get a vec of all files/dirs in the current directory
let dir_paths = std::fs::read_dir("./").unwrap(); let dir_paths = std::fs::read_dir(".").unwrap();
log!(verbose, "Paths: {:?}", dir_paths); log!(verbose, "Paths: {:?}", dir_paths);
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 // Remove mlc.toml and .git from output
dirs.retain(|x| *x != "./mlc.toml"); dirs.retain(|x| *x != "./mlc.toml" && *x != ".\\mlc.toml");
dirs.retain(|x| *x != "./.git"); dirs.retain(|x| *x != "./.git" && *x != ".\\.git");
// Enter each directory and check git status // Enter each directory and check git status
@ -44,7 +44,7 @@ pub fn clean(verbose: bool, force: bool) {
AppExitCode::NotClean, AppExitCode::NotClean,
"The following directories are not clean: \n {}\n\ "The following directories are not clean: \n {}\n\
If you are sure no important changes are staged, run `mlc clean` with the `--force` flag to delete them.", If you are sure no important changes are staged, run `mlc clean` with the `--force` flag to delete them.",
unclean_dirs.iter().map(|x| (*x).to_string().replace("./", "")).collect::<Vec<String>>().join(", ") unclean_dirs.iter().map(|x| (*x).to_string().replace("./", "").replace(".\\", "")).collect::<Vec<String>>().join(", ")
); );
} }
@ -56,7 +56,7 @@ pub fn clean(verbose: bool, force: bool) {
"Reset complete, dirs removed: \n \ "Reset complete, dirs removed: \n \
{}", {}",
dirs.iter() dirs.iter()
.map(|x| x.replace("./", "")) .map(|x| x.replace("./", "").replace(".\\", ""))
.collect::<Vec<String>>() .collect::<Vec<String>>()
.join("\n ") .join("\n ")
); );

@ -11,14 +11,14 @@ pub fn clone(verbose: bool) {
log!(verbose, "Repos: {:?}", repos); log!(verbose, "Repos: {:?}", repos);
// Get a vector of all files/dirs in the current directory, excluding config file // Get a vector of all files/dirs in the current directory, excluding config file
let dir_paths = std::fs::read_dir("./").unwrap(); let dir_paths = std::fs::read_dir(".").unwrap();
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>>();
dirs.retain(|x| *x != "./mlc.toml"); dirs.retain(|x| *x != "./mlc.toml" && *x != ".\\mlc.toml");
dirs.retain(|x| *x != "./out"); dirs.retain(|x| *x != "./out" && *x != ".\\out");
if config.mode.repository.is_some() { if config.mode.repository.is_some() {
dirs.retain(|x| *x != format!("./{}", config.mode.repository.as_ref().unwrap().name)); dirs.retain(|x| *x != format!("./{}", config.mode.repository.as_ref().unwrap().name) && *x != format!(".\\{}", config.mode.repository.as_ref().unwrap().name));
} }
log!(verbose, "Paths with mlc.toml excluded: {:?}", dirs); log!(verbose, "Paths with mlc.toml excluded: {:?}", dirs);
@ -26,7 +26,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)) { if !dirs.contains(&format!("./{}", name)) || !dirs.contains(&format!(".\\{}", name)) {
repo_diff.push(repo); repo_diff.push(repo);
} }
} }

@ -28,9 +28,9 @@ pub fn prune(verbose: bool) {
env::set_current_dir("out").unwrap(); env::set_current_dir("out").unwrap();
log!(verbose, "Current dir: {:?}", env::current_dir().unwrap()); log!(verbose, "Current dir: {:?}", env::current_dir().unwrap());
// Read all files from ./ into a Vec<PathBuf>, except for .sig files // Read all files from . into a Vec<PathBuf>, except for .sig files
let mut files: Vec<PathBuf> = vec![]; let mut files: Vec<PathBuf> = vec![];
for entry in fs::read_dir("./").unwrap() { for entry in fs::read_dir(".").unwrap() {
let entry = entry.unwrap(); let entry = entry.unwrap();
let path = entry.path(); let path = entry.path();
if path.extension().unwrap() != "sig" { if path.extension().unwrap() != "sig" {
@ -120,7 +120,7 @@ pub fn prune(verbose: bool) {
for p in &mut packages_to_delete { for p in &mut packages_to_delete {
println!( println!(
"{}", "{}",
format!(" {}-{}", p.name.replace("./", ""), p.ver).bold() format!(" {}-{}", p.name.replace("./", "").replace(".\\", ""), p.ver).bold()
); );
} }
} }

@ -43,7 +43,7 @@ pub fn generate(verbose: bool) {
&& config.mode.repository.as_ref().unwrap().signing.on_gen && config.mode.repository.as_ref().unwrap().signing.on_gen
{ {
// 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 {
let file = file.unwrap(); let file = file.unwrap();
let path = file.path(); let path = file.path();

Loading…
Cancel
Save