Trigger and report on more events in the compilation pipeline.
This commit is contained in:
parent
749d8ecb10
commit
0eb3cf221b
|
@ -50,9 +50,34 @@ pub struct Terminal;
|
|||
impl telemetry::EventListener for Terminal {
|
||||
fn handle_event(&self, event: telemetry::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 => {
|
||||
println!("\n{}\n", "Running tests...".bold().underline().purple());
|
||||
println!("{}\n", "...Running tests".bold().purple());
|
||||
}
|
||||
telemetry::Event::FinishedTests { tests } => {
|
||||
let (max_mem, max_cpu) = tests.iter().fold(
|
||||
|
|
|
@ -105,12 +105,23 @@ where
|
|||
uplc_dump: bool,
|
||||
run_tests: bool,
|
||||
) -> 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()?;
|
||||
|
||||
let parsed_modules = self.parse_sources()?;
|
||||
|
||||
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 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
|
||||
// model the options differently to make it obvious at the type-level.
|
||||
if uplc_gen {
|
||||
self.event_listener.handle_event(Event::GeneratingUPLC {
|
||||
output_path: self.output_path(),
|
||||
});
|
||||
let programs = self.code_gen(validators, &checked_modules)?;
|
||||
self.write_build_outputs(programs, uplc_dump)?;
|
||||
}
|
||||
|
@ -533,11 +547,13 @@ where
|
|||
.handle_event(Event::FinishedTests { tests: results });
|
||||
}
|
||||
|
||||
fn write_build_outputs(&self, programs: Vec<Script>, uplc_dump: bool) -> Result<(), Error> {
|
||||
let assets = self.root.join("assets");
|
||||
fn output_path(&self) -> PathBuf {
|
||||
self.root.join("assets")
|
||||
}
|
||||
|
||||
fn write_build_outputs(&self, programs: Vec<Script>, uplc_dump: bool) -> Result<(), Error> {
|
||||
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)?;
|
||||
|
||||
|
|
|
@ -1,15 +1,26 @@
|
|||
use uplc::machine::cost_model::ExBudget;
|
||||
|
||||
use crate::script::Script;
|
||||
use std::path::PathBuf;
|
||||
use uplc::machine::cost_model::ExBudget;
|
||||
|
||||
pub trait EventListener: std::fmt::Debug {
|
||||
fn handle_event(&self, event: Event);
|
||||
}
|
||||
|
||||
pub enum Event {
|
||||
CompilingPackage { name: String },
|
||||
StartingCompilation {
|
||||
name: String,
|
||||
version: String,
|
||||
root: PathBuf,
|
||||
},
|
||||
ParsingProjectFiles,
|
||||
TypeChecking,
|
||||
GeneratingUPLC {
|
||||
output_path: PathBuf,
|
||||
},
|
||||
RunningTests,
|
||||
FinishedTests { tests: Vec<TestInfo> },
|
||||
FinishedTests {
|
||||
tests: Vec<TestInfo>,
|
||||
},
|
||||
}
|
||||
|
||||
pub struct TestInfo {
|
||||
|
|
Loading…
Reference in New Issue