From ea395b0d293a30b317623b904097dcc4e948a68e Mon Sep 17 00:00:00 2001 From: thirteenowls Date: Tue, 14 May 2024 19:39:10 +0200 Subject: [PATCH] Fix `zig.image` precedence Currently, `image` always takes precedence over `zig.image`. This change makes it so `image` doesn't get used when zig is enabled, even if `zig.image` is unset (and vice versa). This is a breaking change. --- .changes/1494.json | 5 +++++ src/docker/shared.rs | 16 ++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 .changes/1494.json diff --git a/.changes/1494.json b/.changes/1494.json new file mode 100644 index 000000000..6f24c706f --- /dev/null +++ b/.changes/1494.json @@ -0,0 +1,5 @@ +{ + "description": "Fix `zig.image` precedence", + "type": "fixed", + "breaking": true +} diff --git a/src/docker/shared.rs b/src/docker/shared.rs index 4a1c56f89..7996e1fc0 100644 --- a/src/docker/shared.rs +++ b/src/docker/shared.rs @@ -1246,10 +1246,12 @@ fn get_user_image( target: &Target, uses_zig: bool, ) -> Result, GetImageError> { - let mut image = config.image(target).map_err(GetImageError::Other)?; - if image.is_none() && uses_zig { - image = config.zig_image(target).map_err(GetImageError::Other)?; + let mut image = if uses_zig { + config.zig_image(target) + } else { + config.image(target) } + .map_err(GetImageError::Other)?; if let Some(image) = &mut image { let target_name = get_target_name(target, uses_zig); @@ -1632,18 +1634,16 @@ mod tests { test(map.clone(), &default_ver, &default_ver)?; map.insert("CROSS_TARGET_X86_64_UNKNOWN_LINUX_GNU_IMAGE", "-centos"); - let centos_tag = format!("{default_ver}-centos"); - test(map.clone(), ¢os_tag, ¢os_tag)?; + test(map.clone(), &format!("{default_ver}-centos"), &default_ver)?; map.insert("CROSS_TARGET_X86_64_UNKNOWN_LINUX_GNU_IMAGE", ":edge"); - test(map.clone(), ":edge", ":edge")?; + test(map.clone(), ":edge", &default_ver)?; - // `image` always takes precedence over `zig.image`, even when `uses_zig` is `true` map.insert( "CROSS_TARGET_X86_64_UNKNOWN_LINUX_GNU_ZIG_IMAGE", "@sha256:foobar", ); - test(map.clone(), ":edge", ":edge")?; + test(map.clone(), ":edge", "@sha256:foobar")?; map.remove("CROSS_TARGET_X86_64_UNKNOWN_LINUX_GNU_IMAGE"); test(map.clone(), &default_ver, "@sha256:foobar")?;