Skip to content

Commit

Permalink
Fix zig.image precedence (#1494)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Emilgardis authored May 14, 2024
2 parents 78357ea + ea395b0 commit 7d75864
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changes/1494.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"description": "Fix `zig.image` precedence",
"type": "fixed",
"breaking": true
}
16 changes: 8 additions & 8 deletions src/docker/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1246,10 +1246,12 @@ fn get_user_image(
target: &Target,
uses_zig: bool,
) -> Result<Option<PossibleImage>, 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);
Expand Down Expand Up @@ -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(), &centos_tag, &centos_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")?;
Expand Down

0 comments on commit 7d75864

Please sign in to comment.