From e1686f26b7dded4d6c067a2e67c7547021b375c3 Mon Sep 17 00:00:00 2001 From: ecpullen Date: Tue, 14 Nov 2023 19:50:21 +0000 Subject: [PATCH] twoliter: Remove `Release.toml` from build --- Cargo.lock | 1 + tests/projects/project1/Release.toml | 1 - tests/projects/project1/variants/Cargo.lock | 8 ------ twoliter/Cargo.toml | 31 +++++++++++++++------ twoliter/embedded/Makefile.toml | 4 ++- twoliter/src/cmd/build.rs | 4 +++ twoliter/src/common.rs | 16 +++++++---- twoliter/src/docker/container.rs | 3 +- twoliter/src/main.rs | 1 + twoliter/src/test/mod.rs | 1 + 10 files changed, 45 insertions(+), 25 deletions(-) delete mode 100644 tests/projects/project1/Release.toml diff --git a/Cargo.lock b/Cargo.lock index 5f61caf57..5dc25077c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3552,6 +3552,7 @@ dependencies = [ "pubsys", "pubsys-setup", "serde", + "serde_json", "sha2", "tar", "tempfile", diff --git a/tests/projects/project1/Release.toml b/tests/projects/project1/Release.toml deleted file mode 100644 index 5820a7290..000000000 --- a/tests/projects/project1/Release.toml +++ /dev/null @@ -1 +0,0 @@ -version = "0.0.1" diff --git a/tests/projects/project1/variants/Cargo.lock b/tests/projects/project1/variants/Cargo.lock index 9291e5672..54165822b 100644 --- a/tests/projects/project1/variants/Cargo.lock +++ b/tests/projects/project1/variants/Cargo.lock @@ -2,14 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "aws-test-1" -version = "0.1.0" -dependencies = [ - "hello-agent", - "hello-go", -] - [[package]] name = "hello-agent" version = "0.1.0" diff --git a/twoliter/Cargo.toml b/twoliter/Cargo.toml index ff1e85cd3..e1f86645f 100644 --- a/twoliter/Cargo.toml +++ b/twoliter/Cargo.toml @@ -17,21 +17,36 @@ env_logger = "0.10" flate2 = "1" hex = "0.4" log = "0.4" -non-empty-string = { version = "0.2", features = [ "serde" ] } +non-empty-string = { version = "0.2", features = ["serde"] } serde = { version = "1", features = ["derive"] } +serde_json = "1" sha2 = "0.10" tar = "0.4" tempfile = "3" -tokio = { version = "1", default-features = false, features = ["fs", "macros", "process", "rt-multi-thread"] } +tokio = { version = "1", default-features = false, features = [ + "fs", + "macros", + "process", + "rt-multi-thread", +] } toml = "0.8" -uuid = { version = "1", features = [ "v4" ] } +uuid = { version = "1", features = ["v4"] } # Binary dependencies. These are binaries that we want to embed in the Twoliter binary. -buildsys = { version = "0.1.0", artifact = [ "bin:buildsys", "bin:bottlerocket-variant" ], path = "../tools/buildsys" } -pubsys = { version = "0.1.0", artifact = [ "bin:pubsys" ], path = "../tools/pubsys" } -pubsys-setup = { version = "0.1.0", artifact = [ "bin:pubsys-setup" ], path = "../tools/pubsys-setup" } -testsys = { version = "0.1.0", artifact = [ "bin:testsys" ], path = "../tools/testsys" } -tuftool = { version = "0.10", artifact = [ "bin:tuftool" ] } +buildsys = { version = "0.1.0", artifact = [ + "bin:buildsys", + "bin:bottlerocket-variant", +], path = "../tools/buildsys" } +pubsys = { version = "0.1.0", artifact = [ + "bin:pubsys", +], path = "../tools/pubsys" } +pubsys-setup = { version = "0.1.0", artifact = [ + "bin:pubsys-setup", +], path = "../tools/pubsys-setup" } +testsys = { version = "0.1.0", artifact = [ + "bin:testsys", +], path = "../tools/testsys" } +tuftool = { version = "0.10", artifact = ["bin:tuftool"] } [build-dependencies] bytes = "1" diff --git a/twoliter/embedded/Makefile.toml b/twoliter/embedded/Makefile.toml index 87b2c554a..d71d9d49f 100644 --- a/twoliter/embedded/Makefile.toml +++ b/twoliter/embedded/Makefile.toml @@ -22,7 +22,7 @@ BUILDSYS_VERSION_BUILD = { script = ["git describe --always --dirty --exclude '* # later in this section. You have to edit the path here in Makefile.toml to # use a different Release.toml. BUILDSYS_RELEASE_CONFIG_PATH = "${BUILDSYS_ROOT_DIR}/Release.toml" -BUILDSYS_VERSION_IMAGE = { script = ["awk -F '[ =\"]+' '$1 == \"version\" {print $2}' ${BUILDSYS_RELEASE_CONFIG_PATH}"] } + # This can be overridden with -e to build a different variant from the variants/ directory BUILDSYS_VARIANT = { script = ['echo "${BUILDSYS_VARIANT:-aws-k8s-1.24}"'] } # Product name used for file and directory naming @@ -137,6 +137,8 @@ TESTSYS_LOG_LEVEL = "info" # Certain variables are defined here to allow us to override a component value # on the command line. +BUILDSYS_VERSION_IMAGE = { script = ["awk -F '[ =\"]+' '$1 == \"version\" {print $2}' ${BUILDSYS_RELEASE_CONFIG_PATH}"], condition = { env_not_set = ["BUILDSYS_VERSION_IMAGE"]}} + # Depends on ${BUILDSYS_JOBS}. CARGO_MAKE_CARGO_LIMIT_JOBS = "--jobs ${BUILDSYS_JOBS}" CARGO_MAKE_CARGO_ARGS = "--offline --locked" diff --git a/twoliter/src/cmd/build.rs b/twoliter/src/cmd/build.rs index d8d7ad25b..d720b9285 100644 --- a/twoliter/src/cmd/build.rs +++ b/twoliter/src/cmd/build.rs @@ -2,6 +2,7 @@ use crate::cargo_make::CargoMake; use crate::docker::DockerContainer; use crate::project; use crate::tools::{install_tools, tools_tempdir}; +use crate::variant::variant_version; use anyhow::{Context, Result}; use clap::Parser; use log::{debug, trace}; @@ -47,6 +48,8 @@ impl BuildVariant { let makefile_path = tempdir.path().join("Makefile.toml"); let packages_dir = TempDir::new().context("Unable to create a tempdir for Twoliter's packages")?; + let variant_version = + variant_version(&project.project_dir().join("variants"), &self.variant).await?; let sdk_container = DockerContainer::new( format!("sdk-{}", token), @@ -106,6 +109,7 @@ impl BuildVariant { "BUILDSYS_SBKEYS_DIR", (*sbkeys_dir).as_ref().join("sbkeys").display().to_string(), ) + .env("BUILDSYS_VERSION_IMAGE", variant_version) .makefile(makefile_path) .project_dir(project.project_dir()) .exec("build") diff --git a/twoliter/src/common.rs b/twoliter/src/common.rs index 9378614ee..32bfb9a9a 100644 --- a/twoliter/src/common.rs +++ b/twoliter/src/common.rs @@ -9,15 +9,16 @@ pub(crate) async fn exec_log(cmd: &mut Command) -> Result<()> { log::max_level(), LevelFilter::Off | LevelFilter::Error | LevelFilter::Warn ); - exec(cmd, quiet).await + exec(cmd, quiet).await?; + Ok(()) } /// Run a `tokio::process::Command` and return a `Result` letting us know whether or not it worked. /// `quiet` determines whether or not the command output will be piped to `stdout/stderr`. When -/// `quiet=true`, no output will be shown. -pub(crate) async fn exec(cmd: &mut Command, quiet: bool) -> Result<()> { +/// `quiet=true`, no output will be shown and will be returned instead. +pub(crate) async fn exec(cmd: &mut Command, quiet: bool) -> Result { debug!("Running: {:?}", cmd); - if quiet { + Ok(if quiet { // For quiet levels of logging we capture stdout and stderr let output = cmd .output() @@ -30,6 +31,8 @@ pub(crate) async fn exec(cmd: &mut Command, quiet: bool) -> Result<()> { String::from_utf8_lossy(&output.stdout), String::from_utf8_lossy(&output.stderr) ); + + String::from_utf8(output.stdout).context("Unable to convert command output to `String`")? } else { // For less quiet log levels we stream to stdout and stderr. let status = cmd @@ -42,6 +45,7 @@ pub(crate) async fn exec(cmd: &mut Command, quiet: bool) -> Result<()> { "Command was unsuccessful, exit code {}", status.code().unwrap_or(1), ); - } - Ok(()) + + "".to_string() + }) } diff --git a/twoliter/src/docker/container.rs b/twoliter/src/docker/container.rs index 60a2244f5..ea3516d71 100644 --- a/twoliter/src/docker/container.rs +++ b/twoliter/src/docker/container.rs @@ -54,7 +54,8 @@ impl DockerContainer { let mut args = vec!["cp".to_string()]; args.push(format!("{}:{}", self.name, src.display())); args.push(dest.display().to_string()); - exec(Command::new("docker").args(args), true).await + exec(Command::new("docker").args(args), true).await?; + Ok(()) } } diff --git a/twoliter/src/main.rs b/twoliter/src/main.rs index 9a3ea4be6..37d544bbc 100644 --- a/twoliter/src/main.rs +++ b/twoliter/src/main.rs @@ -8,6 +8,7 @@ mod common; mod docker; mod project; mod tools; +mod variant; /// Test code that should only be compiled when running tests. #[cfg(test)] diff --git a/twoliter/src/test/mod.rs b/twoliter/src/test/mod.rs index bead937ef..b49ad0970 100644 --- a/twoliter/src/test/mod.rs +++ b/twoliter/src/test/mod.rs @@ -5,6 +5,7 @@ be compiled for `cfg(test)`, which is accomplished at its declaration in `main.r !*/ mod cargo_make; +mod variant_version; use std::path::PathBuf; /// Return the canonical path to the directory where we store test data.