mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-22 17:36:19 +04:00
produce error when grammar build fails (#6795)
* produce error when grammar build fails * print which grammar build failed
This commit is contained in:
parent
83c307a66a
commit
f5d38cee17
@ -1,4 +1,4 @@
|
|||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, bail, Context, Result};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
@ -98,15 +98,12 @@ pub fn fetch_grammars() -> Result<()> {
|
|||||||
let mut git_up_to_date = 0;
|
let mut git_up_to_date = 0;
|
||||||
let mut non_git = Vec::new();
|
let mut non_git = Vec::new();
|
||||||
|
|
||||||
for res in results {
|
for (grammar_id, res) in results {
|
||||||
match res {
|
match res {
|
||||||
Ok(FetchStatus::GitUpToDate) => git_up_to_date += 1,
|
Ok(FetchStatus::GitUpToDate) => git_up_to_date += 1,
|
||||||
Ok(FetchStatus::GitUpdated {
|
Ok(FetchStatus::GitUpdated { revision }) => git_updated.push((grammar_id, revision)),
|
||||||
grammar_id,
|
Ok(FetchStatus::NonGit) => non_git.push(grammar_id),
|
||||||
revision,
|
Err(e) => errors.push((grammar_id, e)),
|
||||||
}) => git_updated.push((grammar_id, revision)),
|
|
||||||
Ok(FetchStatus::NonGit { grammar_id }) => non_git.push(grammar_id),
|
|
||||||
Err(e) => errors.push(e),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,10 +135,10 @@ pub fn fetch_grammars() -> Result<()> {
|
|||||||
|
|
||||||
if !errors.is_empty() {
|
if !errors.is_empty() {
|
||||||
let len = errors.len();
|
let len = errors.len();
|
||||||
println!("{} grammars failed to fetch", len);
|
for (i, (grammar, error)) in errors.into_iter().enumerate() {
|
||||||
for (i, error) in errors.into_iter().enumerate() {
|
println!("Failure {}/{len}: {grammar} {error}", i + 1);
|
||||||
println!("\tFailure {}/{}: {}", i + 1, len, error);
|
|
||||||
}
|
}
|
||||||
|
bail!("{len} grammars failed to fetch");
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -158,11 +155,11 @@ pub fn build_grammars(target: Option<String>) -> Result<()> {
|
|||||||
let mut already_built = 0;
|
let mut already_built = 0;
|
||||||
let mut built = Vec::new();
|
let mut built = Vec::new();
|
||||||
|
|
||||||
for res in results {
|
for (grammar_id, res) in results {
|
||||||
match res {
|
match res {
|
||||||
Ok(BuildStatus::AlreadyBuilt) => already_built += 1,
|
Ok(BuildStatus::AlreadyBuilt) => already_built += 1,
|
||||||
Ok(BuildStatus::Built { grammar_id }) => built.push(grammar_id),
|
Ok(BuildStatus::Built) => built.push(grammar_id),
|
||||||
Err(e) => errors.push(e),
|
Err(e) => errors.push((grammar_id, e)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,10 +176,10 @@ pub fn build_grammars(target: Option<String>) -> Result<()> {
|
|||||||
|
|
||||||
if !errors.is_empty() {
|
if !errors.is_empty() {
|
||||||
let len = errors.len();
|
let len = errors.len();
|
||||||
println!("{} grammars failed to build", len);
|
for (i, (grammar_id, error)) in errors.into_iter().enumerate() {
|
||||||
for (i, error) in errors.into_iter().enumerate() {
|
println!("Failure {}/{len}: {grammar_id} {error}", i + 1);
|
||||||
println!("\tFailure {}/{}: {}", i, len, error);
|
|
||||||
}
|
}
|
||||||
|
bail!("{len} grammars failed to build");
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -214,7 +211,7 @@ fn get_grammar_configs() -> Result<Vec<GrammarConfiguration>> {
|
|||||||
Ok(grammars)
|
Ok(grammars)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_parallel<F, Res>(grammars: Vec<GrammarConfiguration>, job: F) -> Vec<Result<Res>>
|
fn run_parallel<F, Res>(grammars: Vec<GrammarConfiguration>, job: F) -> Vec<(String, Result<Res>)>
|
||||||
where
|
where
|
||||||
F: Fn(GrammarConfiguration) -> Result<Res> + Send + 'static + Clone,
|
F: Fn(GrammarConfiguration) -> Result<Res> + Send + 'static + Clone,
|
||||||
Res: Send + 'static,
|
Res: Send + 'static,
|
||||||
@ -229,7 +226,7 @@ fn run_parallel<F, Res>(grammars: Vec<GrammarConfiguration>, job: F) -> Vec<Resu
|
|||||||
pool.execute(move || {
|
pool.execute(move || {
|
||||||
// Ignore any SendErrors, if any job in another thread has encountered an
|
// Ignore any SendErrors, if any job in another thread has encountered an
|
||||||
// error the Receiver will be closed causing this send to fail.
|
// error the Receiver will be closed causing this send to fail.
|
||||||
let _ = tx.send(job(grammar));
|
let _ = tx.send((grammar.grammar_id.clone(), job(grammar)));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,13 +237,8 @@ fn run_parallel<F, Res>(grammars: Vec<GrammarConfiguration>, job: F) -> Vec<Resu
|
|||||||
|
|
||||||
enum FetchStatus {
|
enum FetchStatus {
|
||||||
GitUpToDate,
|
GitUpToDate,
|
||||||
GitUpdated {
|
GitUpdated { revision: String },
|
||||||
grammar_id: String,
|
NonGit,
|
||||||
revision: String,
|
|
||||||
},
|
|
||||||
NonGit {
|
|
||||||
grammar_id: String,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fetch_grammar(grammar: GrammarConfiguration) -> Result<FetchStatus> {
|
fn fetch_grammar(grammar: GrammarConfiguration) -> Result<FetchStatus> {
|
||||||
@ -287,17 +279,12 @@ fn fetch_grammar(grammar: GrammarConfiguration) -> Result<FetchStatus> {
|
|||||||
)?;
|
)?;
|
||||||
git(&grammar_dir, ["checkout", &revision])?;
|
git(&grammar_dir, ["checkout", &revision])?;
|
||||||
|
|
||||||
Ok(FetchStatus::GitUpdated {
|
Ok(FetchStatus::GitUpdated { revision })
|
||||||
grammar_id: grammar.grammar_id,
|
|
||||||
revision,
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
Ok(FetchStatus::GitUpToDate)
|
Ok(FetchStatus::GitUpToDate)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Ok(FetchStatus::NonGit {
|
Ok(FetchStatus::NonGit)
|
||||||
grammar_id: grammar.grammar_id,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,7 +334,7 @@ fn git<I, S>(repository_dir: &Path, args: I) -> Result<String>
|
|||||||
|
|
||||||
enum BuildStatus {
|
enum BuildStatus {
|
||||||
AlreadyBuilt,
|
AlreadyBuilt,
|
||||||
Built { grammar_id: String },
|
Built,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_grammar(grammar: GrammarConfiguration, target: Option<&str>) -> Result<BuildStatus> {
|
fn build_grammar(grammar: GrammarConfiguration, target: Option<&str>) -> Result<BuildStatus> {
|
||||||
@ -533,9 +520,7 @@ fn build_tree_sitter_library(
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(BuildStatus::Built {
|
Ok(BuildStatus::Built)
|
||||||
grammar_id: grammar.grammar_id,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn needs_recompile(
|
fn needs_recompile(
|
||||||
|
Loading…
Reference in New Issue
Block a user