Trigger and report on more events in the compilation pipeline.

This commit is contained in:
KtorZ 2022-12-09 15:04:02 +01:00
parent 749d8ecb10
commit 0eb3cf221b
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
3 changed files with 61 additions and 9 deletions

View File

@ -50,9 +50,34 @@ pub struct Terminal;
impl telemetry::EventListener for Terminal { impl telemetry::EventListener for Terminal {
fn handle_event(&self, event: telemetry::Event) { fn handle_event(&self, event: telemetry::Event) {
match event { match event {
telemetry::Event::CompilingPackage { .. } => todo!(), telemetry::Event::StartingCompilation {
name,
version,
root,
} => {
println!(
"{} {} {} ({})",
"Compiling".bold().purple(),
name.bold(),
version,
root.to_str().unwrap_or("").bright_blue()
);
}
telemetry::Event::ParsingProjectFiles => {
println!("{}", "...Parsing project files".bold().purple());
}
telemetry::Event::TypeChecking => {
println!("{}", "...Type-checking project".bold().purple());
}
telemetry::Event::GeneratingUPLC { output_path } => {
println!(
"{} in {}",
"...Generating Untyped Plutus Core".bold().purple(),
output_path.to_str().unwrap_or("").bright_blue()
);
}
telemetry::Event::RunningTests => { telemetry::Event::RunningTests => {
println!("\n{}\n", "Running tests...".bold().underline().purple()); println!("{}\n", "...Running tests".bold().purple());
} }
telemetry::Event::FinishedTests { tests } => { telemetry::Event::FinishedTests { tests } => {
let (max_mem, max_cpu) = tests.iter().fold( let (max_mem, max_cpu) = tests.iter().fold(

View File

@ -105,12 +105,23 @@ where
uplc_dump: bool, uplc_dump: bool,
run_tests: bool, run_tests: bool,
) -> Result<(), Error> { ) -> Result<(), Error> {
self.event_listener
.handle_event(Event::StartingCompilation {
root: self.root.clone(),
name: self.config.name.clone(),
version: self.config.version.clone(),
});
self.event_listener.handle_event(Event::ParsingProjectFiles);
self.read_source_files()?; self.read_source_files()?;
let parsed_modules = self.parse_sources()?; let parsed_modules = self.parse_sources()?;
let processing_sequence = parsed_modules.sequence()?; let processing_sequence = parsed_modules.sequence()?;
self.event_listener.handle_event(Event::TypeChecking);
let mut checked_modules = self.type_check(parsed_modules, processing_sequence)?; let mut checked_modules = self.type_check(parsed_modules, processing_sequence)?;
let validators = self.validate_validators(&mut checked_modules)?; let validators = self.validate_validators(&mut checked_modules)?;
@ -118,6 +129,9 @@ where
// TODO: In principle, uplc_gen and run_tests can't be true together. We probably want to // TODO: In principle, uplc_gen and run_tests can't be true together. We probably want to
// model the options differently to make it obvious at the type-level. // model the options differently to make it obvious at the type-level.
if uplc_gen { if uplc_gen {
self.event_listener.handle_event(Event::GeneratingUPLC {
output_path: self.output_path(),
});
let programs = self.code_gen(validators, &checked_modules)?; let programs = self.code_gen(validators, &checked_modules)?;
self.write_build_outputs(programs, uplc_dump)?; self.write_build_outputs(programs, uplc_dump)?;
} }
@ -533,11 +547,13 @@ where
.handle_event(Event::FinishedTests { tests: results }); .handle_event(Event::FinishedTests { tests: results });
} }
fn write_build_outputs(&self, programs: Vec<Script>, uplc_dump: bool) -> Result<(), Error> { fn output_path(&self) -> PathBuf {
let assets = self.root.join("assets"); self.root.join("assets")
}
fn write_build_outputs(&self, programs: Vec<Script>, uplc_dump: bool) -> Result<(), Error> {
for script in programs { for script in programs {
let script_output_dir = assets.join(script.module).join(script.name); let script_output_dir = self.output_path().join(script.module).join(script.name);
fs::create_dir_all(&script_output_dir)?; fs::create_dir_all(&script_output_dir)?;

View File

@ -1,15 +1,26 @@
use uplc::machine::cost_model::ExBudget;
use crate::script::Script; use crate::script::Script;
use std::path::PathBuf;
use uplc::machine::cost_model::ExBudget;
pub trait EventListener: std::fmt::Debug { pub trait EventListener: std::fmt::Debug {
fn handle_event(&self, event: Event); fn handle_event(&self, event: Event);
} }
pub enum Event { pub enum Event {
CompilingPackage { name: String }, StartingCompilation {
name: String,
version: String,
root: PathBuf,
},
ParsingProjectFiles,
TypeChecking,
GeneratingUPLC {
output_path: PathBuf,
},
RunningTests, RunningTests,
FinishedTests { tests: Vec<TestInfo> }, FinishedTests {
tests: Vec<TestInfo>,
},
} }
pub struct TestInfo { pub struct TestInfo {