diff --git a/tools/buildsys/src/args.rs b/tools/buildsys/src/args.rs index c1eb63776..fcf4c4937 100644 --- a/tools/buildsys/src/args.rs +++ b/tools/buildsys/src/args.rs @@ -15,8 +15,9 @@ use url::Url; /// variable changes. The build type is represented with bit flags so that we can easily list /// multiple build types for a single variable. See `[BuildType]` and `[rerun_for_envs]` below to /// see how this list is used. -const REBUILD_VARS: [(&str, u8); 12] = [ +const REBUILD_VARS: [(&str, u8); 13] = [ ("BUILDSYS_ARCH", PACKAGE | VARIANT), + ("BUILDSYS_EPOCH", PACKAGE | VARIANT), ("BUILDSYS_NAME", VARIANT), ("BUILDSYS_OUTPUT_DIR", VARIANT), ("BUILDSYS_PACKAGES_DIR", PACKAGE), diff --git a/twoliter/src/cargo_make.rs b/twoliter/src/cargo_make.rs index 63115e9ad..5a266ceef 100644 --- a/twoliter/src/cargo_make.rs +++ b/twoliter/src/cargo_make.rs @@ -1,4 +1,4 @@ -use crate::common::exec_log; +use crate::common::{exec_log, BUILDSYS_EPOCH}; use crate::docker::ImageUri; use crate::project::Project; use anyhow::{bail, Result}; @@ -53,7 +53,9 @@ impl CargoMake { /// definition in `Twoliter.toml`. pub(crate) fn new(project: &Project) -> Result { let sdk = require_sdk(project)?; - Ok(Self::default().env("TLPRIVATE_SDK_IMAGE", sdk)) + Ok(Self::default() + .env("TLPRIVATE_SDK_IMAGE", sdk) + .env("BUILDSYS_EPOCH", BUILDSYS_EPOCH.to_string())) } /// Specify the path to the `Makefile.toml` for the `cargo make` command @@ -189,10 +191,11 @@ const ENV_VARS: [&str; 23] = [ "no_proxy", ]; -const DISALLOWED_SDK_VARS: [&str; 3] = [ +const DISALLOWED_ENV_VARS: [&str; 4] = [ "BUILDSYS_SDK_NAME", "BUILDSYS_SDK_VERSION", "BUILDSYS_REGISTRY", + "BUILDSYS_EPOCH", ]; /// Returns `true` if `key` is an environment variable that needs to be passed to `cargo make`. @@ -208,11 +211,8 @@ fn is_build_system_env(key: impl AsRef) -> bool { } fn check_for_disallowed_var(key: &str) -> Result<()> { - if DISALLOWED_SDK_VARS.contains(&key) { - bail!( - "The environment variable '{}' can no longer be used. Specify the SDK in Twoliter.toml", - key - ) + if DISALLOWED_ENV_VARS.contains(&key) { + bail!("The environment variable '{}' can not be used.", key) } Ok(()) } @@ -242,4 +242,6 @@ fn test_is_build_system_env() { fn test_check_for_disallowed_var() { assert!(check_for_disallowed_var("BUILDSYS_REGISTRY").is_err()); assert!(check_for_disallowed_var("BUILDSYS_PRETTY_NAME").is_ok()); + assert!(check_for_disallowed_var("BUILDSYS_EPOCH").is_err()); + assert!(check_for_disallowed_var("BUILDSYS_FOO").is_ok()); } diff --git a/twoliter/src/common.rs b/twoliter/src/common.rs index 24c45ec33..2175868cb 100644 --- a/twoliter/src/common.rs +++ b/twoliter/src/common.rs @@ -2,6 +2,12 @@ use anyhow::{ensure, Context, Result}; use log::{self, debug, LevelFilter}; use tokio::process::Command; +/// This is passed as an environment variable to Buildsys. Buildsys tells Cargo to watch this +/// environment variable for changes. So if we have a breaking change to the way Buildsys and/or +/// Twoliter function, we can increment this so that we know users will rebuild after updating +/// Twoliter. +pub(crate) const BUILDSYS_EPOCH: u32 = 1; + /// Run a `tokio::process::Command` and return a `Result` letting us know whether or not it worked. /// Pipes stdout/stderr when logging `LevelFilter` is more verbose than `Warn`. pub(crate) async fn exec_log(cmd: &mut Command) -> Result<()> {