-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
5 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,13 +16,9 @@ | |
// | ||
// For inquiries, you can contact us via e-mail at [email protected]. | ||
|
||
use std::path::{Path, PathBuf}; | ||
use std::process::Command; | ||
use std::path::PathBuf; | ||
|
||
use anyhow::Context; | ||
use moonutil::common::IGNORE_DIRS; | ||
use moonutil::module::ModuleDB; | ||
use walkdir::WalkDir; | ||
|
||
use moonutil::common::{MoonbuildOpt, MooncOpt}; | ||
|
||
|
@@ -34,45 +30,6 @@ use std::rc::Rc; | |
use crate::gen::cmd_builder::CommandBuilder; | ||
use crate::gen::n2_errors::{N2Error, N2ErrorKind}; | ||
|
||
pub fn format_package(dir: &Path) -> anyhow::Result<i32> { | ||
let mut errors = vec![]; | ||
let result = walk_dir(dir, &mut errors); | ||
if result.is_ok() { | ||
if errors.is_empty() { | ||
return Ok(0); | ||
} else { | ||
for (p, e) in errors { | ||
eprintln!("Error while formatting {}:\n{}", p.display(), e); | ||
} | ||
return Ok(1); | ||
} | ||
} | ||
anyhow::bail!(result.err().unwrap()) | ||
} | ||
|
||
fn walk_dir(dir: &Path, errors: &mut Vec<(PathBuf, String)>) -> anyhow::Result<()> { | ||
let walker = WalkDir::new(dir).into_iter(); | ||
for entry in walker.filter_entry(|e| !IGNORE_DIRS.contains(&e.file_name().to_str().unwrap())) { | ||
let entry = entry.context("failed to read entry")?; | ||
if entry.file_type().is_dir() { | ||
continue; | ||
} | ||
|
||
let p = entry.path(); | ||
|
||
if let Some(ext) = p.extension() { | ||
if ext == "mbt" { | ||
let out = Command::new("moonfmt").arg("-w").arg(p).output()?; | ||
if !out.status.success() { | ||
let stderr = String::from_utf8_lossy(&out.stderr).to_string(); | ||
errors.push((p.to_path_buf(), stderr)); | ||
} | ||
} | ||
} | ||
} | ||
Ok(()) | ||
} | ||
|
||
pub fn load_moon_proj( | ||
m: &ModuleDB, | ||
moonc_opt: &MooncOpt, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters