Skip to content

Commit

Permalink
twoilter: add build clean command
Browse files Browse the repository at this point in the history
Make the `make clean` target accessible through Twoliter's actual
interface instead of `twoliter make`.
  • Loading branch information
webern committed Apr 3, 2024
1 parent 11afef0 commit 9e5efc7
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 2 deletions.
1 change: 0 additions & 1 deletion tests/projects/local-kit/Release.toml

This file was deleted.

1 change: 1 addition & 0 deletions tests/projects/local-kit/Twoliter.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
schema-version = 1
release-version = "1.0.0"

[sdk]
registry = "twoliter.alpha"
Expand Down
5 changes: 4 additions & 1 deletion twoliter/src/cmd/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use super::build_clean::BuildClean;
use crate::cargo_make::CargoMake;
use crate::common::fs;
use crate::docker::DockerContainer;
Expand All @@ -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,
}
}
}
Expand Down
92 changes: 92 additions & 0 deletions twoliter/src/cmd/build_clean.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
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<PathBuf>,
// /// The architecture to build for.
// #[clap(long = "arch", default_value = "x86_64")]
// arch: String,
//
// /// The kit to build.
// name: String,
//
// /// The URL to the lookaside cache where sources are stored to avoid pulling them from upstream.
// /// Defaults to https://cache.bottlerocket.aws
// lookaside_cache: Option<String>,
// /// If sources are not found in the lookaside cache, this flag will cause buildsys to pull them
// /// from the upstream URL found in a package's `Cargo.toml`.
// #[clap(long = "upstream-source-fallback")]
// upstream_source_fallback: bool,
}

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())
// .env("BUILDSYS_ARCH", &self.arch)
// .env("BUILDSYS_VARIANT", &self.variant)
// .env("BUILDSYS_SBKEYS_DIR", sbkeys_dir.display().to_string())
// .env("BUILDSYS_VERSION_IMAGE", project.release_version())
// .env("GO_MODULES", project.find_go_modules().await?.join(" "))
// .env("TLPRIVATE_KIT_NAME", &self.name)
// .env(
// "BUILDSYS_UPSTREAM_SOURCE_FALLBACK",
// self.upstream_source_fallback.to_string(),
// )
// .envs(optional_envs.into_iter())
.makefile(makefile_path)
.project_dir(project.project_dir())
.exec("clean")
.await?;

Ok(())

// let mut envs = Vec::new();

// if let Some(lookaside_cache) = &self.lookaside_cache {
// optional_envs.push(("BUILDSYS_LOOKASIDE_CACHE", lookaside_cache))
// }
//
// // Hold the result of the cargo make call so we can clean up the project directory first.
// let res = CargoMake::new(&project, &self.arch)?
// .env("TWOLITER_TOOLS_DIR", toolsdir.display().to_string())
// .env("BUILDSYS_ARCH", &self.arch)
// .env("BUILDSYS_VARIANT", &self.variant)
// .env("BUILDSYS_SBKEYS_DIR", sbkeys_dir.display().to_string())
// .env("BUILDSYS_VERSION_IMAGE", project.release_version())
// .env("GO_MODULES", project.find_go_modules().await?.join(" "))
// .env(
// "BUILDSYS_UPSTREAM_SOURCE_FALLBACK",
// self.upstream_source_fallback.to_string(),
// )
// .envs(optional_envs.into_iter())
// .makefile(makefile_path)
// .project_dir(project.project_dir())
// .exec("build")
// .await;
//
// // Clean up all of the files we created
// for file_name in created_files {
// let added = Path::new(&file_name);
// if added.is_file() {
// fs::remove_file(added).await?;
// } else if added.is_dir() {
// fs::remove_dir_all(added).await?;
// }
// }
//
// res
}
}
1 change: 1 addition & 0 deletions twoliter/src/cmd/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod build;
mod build_clean;
mod debug;
mod make;

Expand Down

0 comments on commit 9e5efc7

Please sign in to comment.