From 09d8e5a1146adfef7588b1db833e4fe7eb709b4f Mon Sep 17 00:00:00 2001 From: Matthew James Briggs Date: Wed, 3 Apr 2024 14:24:39 -0700 Subject: [PATCH] twoilter: add build clean command Make the `make clean` target accessible through Twoliter's actual interface instead of `twoliter make`. --- tests/projects/local-kit/Release.toml | 1 - tests/projects/local-kit/Twoliter.toml | 1 + twoliter/src/cmd/build.rs | 5 ++++- twoliter/src/cmd/build_clean.rs | 31 ++++++++++++++++++++++++++ twoliter/src/cmd/mod.rs | 1 + 5 files changed, 37 insertions(+), 2 deletions(-) delete mode 100644 tests/projects/local-kit/Release.toml create mode 100644 twoliter/src/cmd/build_clean.rs diff --git a/tests/projects/local-kit/Release.toml b/tests/projects/local-kit/Release.toml deleted file mode 100644 index 5820a7290..000000000 --- a/tests/projects/local-kit/Release.toml +++ /dev/null @@ -1 +0,0 @@ -version = "0.0.1" diff --git a/tests/projects/local-kit/Twoliter.toml b/tests/projects/local-kit/Twoliter.toml index 81ecec86f..9095088d0 100644 --- a/tests/projects/local-kit/Twoliter.toml +++ b/tests/projects/local-kit/Twoliter.toml @@ -1,4 +1,5 @@ schema-version = 1 +release-version = "1.0.0" [sdk] registry = "twoliter.alpha" diff --git a/twoliter/src/cmd/build.rs b/twoliter/src/cmd/build.rs index 2f101a6e2..3fb6a15d2 100644 --- a/twoliter/src/cmd/build.rs +++ b/twoliter/src/cmd/build.rs @@ -1,3 +1,4 @@ +use super::build_clean::BuildClean; use crate::cargo_make::CargoMake; use crate::common::fs; use crate::docker::DockerContainer; @@ -11,13 +12,15 @@ use tempfile::TempDir; #[derive(Debug, Parser)] pub(crate) enum BuildCommand { + Clean(BuildClean), Variant(BuildVariant), } impl BuildCommand { pub(crate) async fn run(self) -> Result<()> { match self { - BuildCommand::Variant(build_variant) => build_variant.run().await, + BuildCommand::Clean(command) => command.run().await, + BuildCommand::Variant(command) => command.run().await, } } } diff --git a/twoliter/src/cmd/build_clean.rs b/twoliter/src/cmd/build_clean.rs new file mode 100644 index 000000000..2d7e6948b --- /dev/null +++ b/twoliter/src/cmd/build_clean.rs @@ -0,0 +1,31 @@ +use crate::cargo_make::CargoMake; +use crate::project; +use crate::tools; +use anyhow::Result; +use clap::Parser; +use std::path::PathBuf; + +#[derive(Debug, Parser)] +pub(crate) struct BuildClean { + /// Path to Twoliter.toml. Will search for Twoliter.toml when absent. + #[clap(long = "project-path")] + project_path: Option, +} + +impl BuildClean { + pub(super) async fn run(&self) -> Result<()> { + let project = project::load_or_find_project(self.project_path.clone()).await?; + let toolsdir = project.project_dir().join("build/tools"); + tools::install_tools(&toolsdir).await?; + let makefile_path = toolsdir.join("Makefile.toml"); + + CargoMake::new(&project)? + .env("TWOLITER_TOOLS_DIR", toolsdir.display().to_string()) + .makefile(makefile_path) + .project_dir(project.project_dir()) + .exec("clean") + .await?; + + Ok(()) + } +} diff --git a/twoliter/src/cmd/mod.rs b/twoliter/src/cmd/mod.rs index 7ce56f93c..ccc0c1512 100644 --- a/twoliter/src/cmd/mod.rs +++ b/twoliter/src/cmd/mod.rs @@ -1,4 +1,5 @@ mod build; +mod build_clean; mod debug; mod make;