Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tools/buildsys/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
18 changes: 10 additions & 8 deletions twoliter/src/cargo_make.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -53,7 +53,9 @@ impl CargoMake {
/// definition in `Twoliter.toml`.
pub(crate) fn new(project: &Project) -> Result<Self> {
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
Expand Down Expand Up @@ -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`.
Expand All @@ -208,11 +211,8 @@ fn is_build_system_env(key: impl AsRef<str>) -> 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(())
}
Expand Down Expand Up @@ -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());
}
6 changes: 6 additions & 0 deletions twoliter/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
Expand Down