-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Required input in the form of environment variables was sprinkled throughout the code. Here we aggregate the inputs into a CLI interface using Clap, while still allowing all to specified via environment variables.
- Loading branch information
Showing
4 changed files
with
189 additions
and
61 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/*! | ||
These structs provide the CLI interface for buildsys which is called from Cargo.toml and accepts all | ||
of its input arguments from environment variables. | ||
!*/ | ||
|
||
use clap::{Parser, Subcommand}; | ||
use std::path::PathBuf; | ||
|
||
/// A tool for building Bottlerocket images and artifacts. | ||
#[derive(Debug, Parser)] | ||
pub(crate) struct Buildsys { | ||
#[command(subcommand)] | ||
pub(crate) command: Command, | ||
} | ||
|
||
#[derive(Subcommand, Debug)] | ||
pub(crate) enum Command { | ||
BuildPackage(BuildPackageArgs), | ||
BuildVariant(BuildVariantArgs), | ||
} | ||
|
||
/// Arguments common to all subcommands. | ||
#[derive(Debug, Parser)] | ||
pub(crate) struct Common { | ||
#[arg(long, env = "BUILDSYS_ARCH")] | ||
pub(crate) arch: String, | ||
|
||
#[arg(long, env = "BUILDSYS_OUTPUT_DIR")] | ||
pub(crate) output_dir: PathBuf, | ||
|
||
#[arg(long, env = "BUILDSYS_ROOT_DIR")] | ||
pub(crate) root_dir: PathBuf, | ||
|
||
#[arg(long, env = "BUILDSYS_STATE_DIR")] | ||
pub(crate) state_dir: PathBuf, | ||
|
||
#[arg(long, env = "BUILDSYS_TIMESTAMP")] | ||
pub(crate) timestamp: String, | ||
|
||
#[arg(long, env = "CARGO_MANIFEST_DIR")] | ||
pub(crate) cargo_manifest_dir: PathBuf, | ||
} | ||
|
||
impl Common { | ||
pub(crate) fn rerun_for_envs() { | ||
[ | ||
"BUILDSYS_ARCH", | ||
"BUILDSYS_OUTPUT_DIR", | ||
"BUILDSYS_ROOT_DIR", | ||
"BUILDSYS_STATE_DIR", | ||
"BUILDSYS_TIMESTAMP", | ||
"BUILDSYS_VERSION_FULL", | ||
"CARGO_MANIFEST_DIR", | ||
] | ||
.iter() | ||
.for_each(|&var| rerun_for_env(var)); | ||
} | ||
} | ||
|
||
/// Build RPMs from a spec file and sources. | ||
#[derive(Debug, Parser)] | ||
pub(crate) struct BuildPackageArgs { | ||
#[arg(long, env = "BUILDSYS_PACKAGES_DIR")] | ||
pub(crate) packages_dir: PathBuf, | ||
|
||
#[arg(long, env = "BUILDSYS_VARIANT")] | ||
pub(crate) variant: String, | ||
|
||
#[arg(long, env = "BUILDSYS_SOURCES_DIR")] | ||
pub(crate) sources_dir: PathBuf, | ||
|
||
#[arg(long, env = "CARGO_PKG_NAME")] | ||
pub(crate) cargo_package_name: String, | ||
|
||
#[command(flatten)] | ||
pub(crate) common: Common, | ||
} | ||
|
||
impl BuildPackageArgs { | ||
pub(crate) fn rerun_for_envs() { | ||
Common::rerun_for_envs(); | ||
[ | ||
"BUILDSYS_PACKAGES_DIR", | ||
"BUILDSYS_SOURCES_DIR", | ||
"BUILDSYS_VARIANT", | ||
"CARGO_PKG_NAME", | ||
] | ||
.iter() | ||
.for_each(|&var| rerun_for_env(var)); | ||
} | ||
} | ||
|
||
/// Build filesystem and disk images from RPMs. | ||
#[derive(Debug, Parser)] | ||
pub(crate) struct BuildVariantArgs { | ||
#[arg(long, env = "BUILDSYS_NAME")] | ||
pub(crate) name: String, | ||
|
||
#[arg(long, env = "BUILDSYS_PRETTY_NAME")] | ||
pub(crate) pretty_name: String, | ||
|
||
#[arg(long, env = "BUILDSYS_VARIANT")] | ||
pub(crate) variant: String, | ||
|
||
#[arg(long, env = "BUILDSYS_VERSION_BUILD")] | ||
pub(crate) version_build: String, | ||
|
||
#[arg(long, env = "BUILDSYS_VERSION_FULL")] | ||
pub(crate) version_full: String, | ||
|
||
#[arg(long, env = "BUILDSYS_VERSION_IMAGE")] | ||
pub(crate) version_image: String, | ||
|
||
#[command(flatten)] | ||
pub(crate) common: Common, | ||
} | ||
|
||
impl BuildVariantArgs { | ||
pub(crate) fn rerun_for_envs() { | ||
Common::rerun_for_envs(); | ||
[ | ||
"BUILDSYS_NAME", | ||
"BUILDSYS_PRETTY_NAME", | ||
"BUILDSYS_VARIANT", | ||
"BUILDSYS_VERSION_BUILD", | ||
"BUILDSYS_VERSION_FULL", | ||
"BUILDSYS_VERSION_IMAGE", | ||
] | ||
.iter() | ||
.for_each(|&var| rerun_for_env(var)); | ||
} | ||
} | ||
|
||
fn rerun_for_env(var: &str) { | ||
println!("cargo:rerun-if-env-changed={}", var); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters