From 0576ae168a91f64a66eb2311e83163cf5ee81ca3 Mon Sep 17 00:00:00 2001 From: YetAnotherMinion Date: Sun, 10 Oct 2021 19:44:29 +0100 Subject: [PATCH] refactor: use starmelon for derive macros infra/homer/examples was the start of my work on macros for Elm. I have greatly refined these ideas in starmelon. Delete the multi step build process and replace it with a single call to starmelon. --- always-rebuild.do | 2 ++ release.do | 4 ++++ src/main.rs | 19 +++++++++++++++---- starmelon-binary.do | 7 +++++++ 4 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 always-rebuild.do create mode 100644 release.do create mode 100644 starmelon-binary.do diff --git a/always-rebuild.do b/always-rebuild.do new file mode 100644 index 0000000..06fcfe0 --- /dev/null +++ b/always-rebuild.do @@ -0,0 +1,2 @@ +redo-always +redo-ifchange release diff --git a/release.do b/release.do new file mode 100644 index 0000000..8ce97db --- /dev/null +++ b/release.do @@ -0,0 +1,4 @@ +redo-ifchange Cargo.toml +find src/ -type f | xargs redo-ifchange + +cargo build --release diff --git a/src/main.rs b/src/main.rs index cdb9fd2..072b70e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -446,10 +446,21 @@ globalThis.runOnInput = function(data) { // now. Another way to do this would be with an Arc. This will panic if the // mailbox is currently borrowed match mailbox.replace(None) { - Some(Ok(output)) => { - io::stdout() - .write_all(&output) - .map_err(|io_err| CompilerError::WriteOutputFailed(io_err, "stdout".into()))?; + Some(Ok(buffer)) => { + match output { + None => { + io::stdout() + .write_all(&buffer) + .map_err(|io_err| CompilerError::WriteOutputFailed(io_err, "stdout".into()))?; + }, + Some(filename) => { + let mut f = fs::File::create(&filename) + .map_err(|io_err| CompilerError::WriteOutputFailed(io_err, filename))?; + + f.write_all(&buffer) + .map_err(|io_err| CompilerError::WriteOutputFailed(io_err, "stdout".into()))?; + } + } } Some(Err(problem)) => { println!("had a problem {}", problem); diff --git a/starmelon-binary.do b/starmelon-binary.do new file mode 100644 index 0000000..43a6053 --- /dev/null +++ b/starmelon-binary.do @@ -0,0 +1,7 @@ +if test -f ../../target/debug/gen-css-selectors; then + redo-ifchange always-rebuild + ls -al ../../../target/release/starmelon | redo-stamp +else; + cargo build --release + ls -al ../../../target/release/starmelon | redo-stamp +fi