extractHeadlingArgsFromNode creates headling args using a new temporary builder. However, if the current builder's BuiltinArgDefaults differ from the host's defaults (such as when passing --platform to buildah, which overrides TARGET* args after calling NewBuilder()), the resulting headling args contain the wrong values.
The function should instead copy the current builder's BuiltinArgDefaults into the temporary builder before trying to construct the headling args. The following patch should fix this:
--- a/builder.go
+++ b/builder.go
@@ -6,6 +6,7 @@ import (
"fmt"
"io"
"log"
+ "maps"
"os"
"path/filepath"
"runtime"
@@ -418,6 +419,7 @@ func (b *Builder) extractHeadingArgsFromNode(node *parser.Node) error {
// Use a separate builder to evaluate the heading args
tempBuilder := NewBuilder(b.UserArgs)
+ maps.Copy(tempBuilder.BuiltinArgDefaults, b.BuiltinArgDefaults)
// Built-in ARGs are declared implicitly in the heading and should be resolvable in its scope
for k, v := range tempBuilder.BuiltinArgDefaults {
The test cases in podman-container-tools/buildah#6964 pass after making this change.
extractHeadlingArgsFromNodecreates headling args using a new temporary builder. However, if the current builder'sBuiltinArgDefaultsdiffer from the host's defaults (such as when passing--platformto buildah, which overridesTARGET*args after callingNewBuilder()), the resulting headling args contain the wrong values.The function should instead copy the current builder's
BuiltinArgDefaultsinto the temporary builder before trying to construct the headling args. The following patch should fix this:The test cases in podman-container-tools/buildah#6964 pass after making this change.