diff --git a/go.mod b/go.mod index df8baede6bc0..6ae8abff93f5 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/docker/buildx -go 1.23.0 +go 1.22.0 require ( github.com/Masterminds/semver/v3 v3.2.1 diff --git a/util/buildflags/attests_cty.go b/util/buildflags/attests_cty.go index e2592ac54f54..2b60b167f870 100644 --- a/util/buildflags/attests_cty.go +++ b/util/buildflags/attests_cty.go @@ -22,16 +22,19 @@ func (e *Attests) FromCtyValue(in cty.Value, p cty.Path) error { return p.NewErrorf("%s", convert.MismatchMessage(got, want)) } -func (e *Attests) fromCtyValue(in cty.Value, p cty.Path) error { +func (e *Attests) fromCtyValue(in cty.Value, p cty.Path) (retErr error) { *e = make([]*Attest, 0, in.LengthInt()) - for value := range eachElement(in) { + + yield := func(value cty.Value) bool { entry := &Attest{} - if err := entry.FromCtyValue(value, p); err != nil { - return err + if retErr = entry.FromCtyValue(value, p); retErr != nil { + return false } *e = append(*e, entry) + return true } - return nil + eachElement(in)(yield) + return retErr } func (e Attests) ToCtyValue() cty.Value { diff --git a/util/buildflags/cache_cty.go b/util/buildflags/cache_cty.go index 0a818f978886..7186b025ca30 100644 --- a/util/buildflags/cache_cty.go +++ b/util/buildflags/cache_cty.go @@ -21,26 +21,30 @@ func (o *CacheOptions) FromCtyValue(in cty.Value, p cty.Path) error { return p.NewErrorf("%s", convert.MismatchMessage(got, want)) } -func (o *CacheOptions) fromCtyValue(in cty.Value, p cty.Path) error { +func (o *CacheOptions) fromCtyValue(in cty.Value, p cty.Path) (retErr error) { *o = make([]*CacheOptionsEntry, 0, in.LengthInt()) - for value := range eachElement(in) { + + yield := func(value cty.Value) bool { // Special handling for a string type to handle ref only format. if value.Type() == cty.String { - entries, err := ParseCacheEntry([]string{value.AsString()}) - if err != nil { - return err + var entries CacheOptions + entries, retErr = ParseCacheEntry([]string{value.AsString()}) + if retErr != nil { + return false } *o = append(*o, entries...) - continue + return true } entry := &CacheOptionsEntry{} - if err := entry.FromCtyValue(value, p); err != nil { - return err + if retErr = entry.FromCtyValue(value, p); retErr != nil { + return false } *o = append(*o, entry) + return true } - return nil + eachElement(in)(yield) + return retErr } func (o CacheOptions) ToCtyValue() cty.Value { diff --git a/util/buildflags/export_cty.go b/util/buildflags/export_cty.go index 88743d8ddc34..3df3eb298a32 100644 --- a/util/buildflags/export_cty.go +++ b/util/buildflags/export_cty.go @@ -21,16 +21,19 @@ func (e *Exports) FromCtyValue(in cty.Value, p cty.Path) error { return p.NewErrorf("%s", convert.MismatchMessage(got, want)) } -func (e *Exports) fromCtyValue(in cty.Value, p cty.Path) error { +func (e *Exports) fromCtyValue(in cty.Value, p cty.Path) (retErr error) { *e = make([]*ExportEntry, 0, in.LengthInt()) - for value := range eachElement(in) { + + yield := func(value cty.Value) bool { entry := &ExportEntry{} - if err := entry.FromCtyValue(value, p); err != nil { - return err + if retErr = entry.FromCtyValue(value, p); retErr != nil { + return false } *e = append(*e, entry) + return true } - return nil + eachElement(in)(yield) + return retErr } func (e Exports) ToCtyValue() cty.Value { diff --git a/util/buildflags/secrets_cty.go b/util/buildflags/secrets_cty.go index 7e9ba28d2077..aaadfc39a8e9 100644 --- a/util/buildflags/secrets_cty.go +++ b/util/buildflags/secrets_cty.go @@ -28,16 +28,19 @@ func (s *Secrets) FromCtyValue(in cty.Value, p cty.Path) error { return p.NewErrorf("%s", convert.MismatchMessage(got, want)) } -func (s *Secrets) fromCtyValue(in cty.Value, p cty.Path) error { +func (s *Secrets) fromCtyValue(in cty.Value, p cty.Path) (retErr error) { *s = make([]*Secret, 0, in.LengthInt()) - for value := range eachElement(in) { + + yield := func(value cty.Value) bool { entry := &Secret{} - if err := entry.FromCtyValue(value, p); err != nil { - return err + if retErr = entry.FromCtyValue(value, p); retErr != nil { + return false } *s = append(*s, entry) + return true } - return nil + eachElement(in)(yield) + return retErr } func (s Secrets) ToCtyValue() cty.Value { diff --git a/util/buildflags/ssh_cty.go b/util/buildflags/ssh_cty.go index 694a74212655..ef580729881f 100644 --- a/util/buildflags/ssh_cty.go +++ b/util/buildflags/ssh_cty.go @@ -28,16 +28,19 @@ func (s *SSHKeys) FromCtyValue(in cty.Value, p cty.Path) error { return p.NewErrorf("%s", convert.MismatchMessage(got, want)) } -func (s *SSHKeys) fromCtyValue(in cty.Value, p cty.Path) error { +func (s *SSHKeys) fromCtyValue(in cty.Value, p cty.Path) (retErr error) { *s = make([]*SSH, 0, in.LengthInt()) - for value := range eachElement(in) { + + yield := func(value cty.Value) bool { entry := &SSH{} - if err := entry.FromCtyValue(value, p); err != nil { - return err + if retErr = entry.FromCtyValue(value, p); retErr != nil { + return false } *s = append(*s, entry) + return true } - return nil + eachElement(in)(yield) + return retErr } func (s SSHKeys) ToCtyValue() cty.Value { diff --git a/util/buildflags/utils.go b/util/buildflags/utils.go index 6535bb10cccf..c7aeffd5c060 100644 --- a/util/buildflags/utils.go +++ b/util/buildflags/utils.go @@ -1,8 +1,6 @@ package buildflags import ( - "iter" - "github.com/zclconf/go-cty/cty" "github.com/zclconf/go-cty/cty/gocty" ) @@ -57,7 +55,12 @@ func isEmptyOrUnknown(v cty.Value) bool { return !v.IsKnown() || (v.Type() == cty.String && v.AsString() == "") } -func eachElement(in cty.Value) iter.Seq[cty.Value] { +// Seq is a temporary definition of iter.Seq until we are able to migrate +// to using go1.23 as our minimum version. This can be removed when go1.24 +// is released and usages can be changed to use rangefunc. +type Seq[V any] func(yield func(V) bool) + +func eachElement(in cty.Value) Seq[cty.Value] { return func(yield func(v cty.Value) bool) { for elem := in.ElementIterator(); elem.Next(); { _, value := elem.Element()