From f8970ecb9e24b47ba6dadfe83b54ff6f5a7f506c Mon Sep 17 00:00:00 2001 From: KtorZ Date: Fri, 27 Jan 2023 10:47:08 +0100 Subject: [PATCH] Move UPLC dump into separate function + log event. ``` Compiling aiken-lang/stdlib 43d8e740ffdf5febc59e51b7f0d5f8506115340c (examples/hello_world/build/packages/aiken-lang-stdlib) Compiling aiken-lang/hello_world 1.0.0 (examples/hello_world) Generating project's blueprint (examples/hello_world/plutus.json) Exporting UPLC (examples/hello_world/artifacts) ``` --- crates/aiken-project/src/lib.rs | 23 +++++++++++++++-------- crates/aiken-project/src/telemetry.rs | 3 +++ crates/aiken/src/cmd/new.rs | 2 +- crates/aiken/src/lib.rs | 12 ++++++++++-- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/crates/aiken-project/src/lib.rs b/crates/aiken-project/src/lib.rs index e2f4c8a1..01c85c04 100644 --- a/crates/aiken-project/src/lib.rs +++ b/crates/aiken-project/src/lib.rs @@ -184,6 +184,20 @@ where self.compile(options) } + pub fn dump_uplc(&self, blueprint: &Blueprint) -> Result<(), Error> { + let dir = self.root.join("artifacts"); + self.event_listener + .handle_event(Event::DumpingUPLC { path: dir.clone() }); + fs::create_dir_all(&dir)?; + for validator in &blueprint.validators { + // TODO: Also include validator name. + let path = dir.clone().join(format!("{}.uplc", validator.purpose)); + fs::write(&path, validator.program.to_pretty()) + .map_err(|error| Error::FileIo { error, path })?; + } + Ok(()) + } + pub fn compile(&mut self, options: Options) -> Result<(), Error> { self.compile_deps()?; @@ -222,14 +236,7 @@ where } if uplc_dump { - let dir = self.root.join("artifacts"); - fs::create_dir_all(&dir)?; - for validator in &blueprint.validators { - // TODO: Also include validator name. - let path = dir.clone().join(format!("{}.uplc", validator.purpose)); - fs::write(&path, validator.program.to_pretty()) - .map_err(|error| Error::FileIo { error, path })?; - } + self.dump_uplc(&blueprint)?; } let json = serde_json::to_string_pretty(&blueprint).unwrap(); diff --git a/crates/aiken-project/src/telemetry.rs b/crates/aiken-project/src/telemetry.rs index fd72b0f9..3143ea3f 100644 --- a/crates/aiken-project/src/telemetry.rs +++ b/crates/aiken-project/src/telemetry.rs @@ -22,6 +22,9 @@ pub enum Event { GeneratingBlueprint { path: PathBuf, }, + DumpingUPLC { + path: PathBuf, + }, GeneratingUPLCFor { name: String, path: PathBuf, diff --git a/crates/aiken/src/cmd/new.rs b/crates/aiken/src/cmd/new.rs index f407cc6f..5d28fdfd 100644 --- a/crates/aiken/src/cmd/new.rs +++ b/crates/aiken/src/cmd/new.rs @@ -165,7 +165,7 @@ fn gitignore(root: &Path) -> miette::Result<()> { indoc! { r#" # Aiken compilation artifacts - assets/ + artifacts/ # Aiken's project working directory build/ # Aiken's default documentation export diff --git a/crates/aiken/src/lib.rs b/crates/aiken/src/lib.rs index fac313ba..4ea7dcff 100644 --- a/crates/aiken/src/lib.rs +++ b/crates/aiken/src/lib.rs @@ -94,11 +94,19 @@ impl telemetry::EventListener for Terminal { telemetry::Event::WaitingForBuildDirLock => { println!("{}", "Waiting for build directory lock ...".bold().purple()); } + telemetry::Event::DumpingUPLC { path } => { + println!( + "{} {} ({})", + " Exporting".bold().purple(), + "UPLC".bold(), + path.display().bright_blue() + ); + } telemetry::Event::GeneratingBlueprint { path } => { println!( "{} {} ({})", " Generating".bold().purple(), - "contract blueprint".bold(), + "project's blueprint".bold(), path.display().bright_blue() ); } @@ -112,7 +120,7 @@ impl telemetry::EventListener for Terminal { telemetry::Event::GeneratingUPLCFor { name, path } => { println!( "{} {}.{{{}}}", - " Generating Untyped Plutus Core for".bold().purple(), + " Generating UPLC for".bold().purple(), path.to_str().unwrap_or("").blue(), name.bright_blue(), );