mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 00:47:48 +08:00
Merge pull request #3116 from crazy-max/v0.23-picks-0.23.0
[v0.23] cherry-picks for v0.23.0
This commit is contained in:
commit
28c90eadc4
@ -42,7 +42,7 @@ type variableValidation struct {
|
|||||||
type functionDef struct {
|
type functionDef struct {
|
||||||
Name string `json:"-" hcl:"name,label"`
|
Name string `json:"-" hcl:"name,label"`
|
||||||
Params *hcl.Attribute `json:"params,omitempty" hcl:"params"`
|
Params *hcl.Attribute `json:"params,omitempty" hcl:"params"`
|
||||||
Variadic *hcl.Attribute `json:"variadic_param,omitempty" hcl:"variadic_params"`
|
Variadic *hcl.Attribute `json:"variadic_params,omitempty" hcl:"variadic_params"`
|
||||||
Result *hcl.Attribute `json:"result,omitempty" hcl:"result"`
|
Result *hcl.Attribute `json:"result,omitempty" hcl:"result"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
go.mod
2
go.mod
@ -29,7 +29,7 @@ require (
|
|||||||
github.com/hashicorp/hcl/v2 v2.23.0
|
github.com/hashicorp/hcl/v2 v2.23.0
|
||||||
github.com/in-toto/in-toto-golang v0.5.0
|
github.com/in-toto/in-toto-golang v0.5.0
|
||||||
github.com/mitchellh/hashstructure/v2 v2.0.2
|
github.com/mitchellh/hashstructure/v2 v2.0.2
|
||||||
github.com/moby/buildkit v0.21.0-rc2
|
github.com/moby/buildkit v0.21.0
|
||||||
github.com/moby/sys/mountinfo v0.7.2
|
github.com/moby/sys/mountinfo v0.7.2
|
||||||
github.com/moby/sys/signal v0.7.1
|
github.com/moby/sys/signal v0.7.1
|
||||||
github.com/morikuni/aec v1.0.0
|
github.com/morikuni/aec v1.0.0
|
||||||
|
4
go.sum
4
go.sum
@ -279,8 +279,8 @@ github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZX
|
|||||||
github.com/mitchellh/hashstructure/v2 v2.0.2 h1:vGKWl0YJqUNxE8d+h8f6NJLcCJrgbhC4NcD46KavDd4=
|
github.com/mitchellh/hashstructure/v2 v2.0.2 h1:vGKWl0YJqUNxE8d+h8f6NJLcCJrgbhC4NcD46KavDd4=
|
||||||
github.com/mitchellh/hashstructure/v2 v2.0.2/go.mod h1:MG3aRVU/N29oo/V/IhBX8GR/zz4kQkprJgF2EVszyDE=
|
github.com/mitchellh/hashstructure/v2 v2.0.2/go.mod h1:MG3aRVU/N29oo/V/IhBX8GR/zz4kQkprJgF2EVszyDE=
|
||||||
github.com/mitchellh/mapstructure v0.0.0-20150613213606-2caf8efc9366/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
github.com/mitchellh/mapstructure v0.0.0-20150613213606-2caf8efc9366/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||||
github.com/moby/buildkit v0.21.0-rc2 h1:JxocuYzqoGLPzftFiDi/Afb85RbXWqt3ObEADRdFFE0=
|
github.com/moby/buildkit v0.21.0 h1:+z4vVqgt0spLrOSxi4DLedRbIh2gbNVlZ5q4rsnNp60=
|
||||||
github.com/moby/buildkit v0.21.0-rc2/go.mod h1:mBq0D44uCyz2PdX8T/qym5LBbkBO3GGv0wqgX9ABYYw=
|
github.com/moby/buildkit v0.21.0/go.mod h1:mBq0D44uCyz2PdX8T/qym5LBbkBO3GGv0wqgX9ABYYw=
|
||||||
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
|
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
|
||||||
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
|
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
|
||||||
github.com/moby/locker v1.0.1 h1:fOXqR41zeveg4fFODix+1Ch4mj/gT0NE1XJbp/epuBg=
|
github.com/moby/locker v1.0.1 h1:fOXqR41zeveg4fFODix+1Ch4mj/gT0NE1XJbp/epuBg=
|
||||||
|
@ -13,7 +13,7 @@ function "add" {
|
|||||||
|
|
||||||
function "list" {
|
function "list" {
|
||||||
params = []
|
params = []
|
||||||
variadic_param = items
|
variadic_params = items
|
||||||
result = items
|
result = items
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -1,79 +0,0 @@
|
|||||||
package userfunc
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/hashicorp/hcl/v2"
|
|
||||||
"github.com/zclconf/go-cty/cty/function"
|
|
||||||
)
|
|
||||||
|
|
||||||
var funcBodySchema = &hcl.BodySchema{
|
|
||||||
Attributes: []hcl.AttributeSchema{
|
|
||||||
{
|
|
||||||
Name: "params",
|
|
||||||
Required: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "variadic_param",
|
|
||||||
Required: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "result",
|
|
||||||
Required: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
func decodeUserFunctions(body hcl.Body, blockType string, contextFunc ContextFunc) (funcs map[string]function.Function, remain hcl.Body, diags hcl.Diagnostics) {
|
|
||||||
schema := &hcl.BodySchema{
|
|
||||||
Blocks: []hcl.BlockHeaderSchema{
|
|
||||||
{
|
|
||||||
Type: blockType,
|
|
||||||
LabelNames: []string{"name"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
content, remain, diags := body.PartialContent(schema)
|
|
||||||
if diags.HasErrors() {
|
|
||||||
return nil, remain, diags
|
|
||||||
}
|
|
||||||
|
|
||||||
// first call to getBaseCtx will populate context, and then the same
|
|
||||||
// context will be used for all subsequent calls. It's assumed that
|
|
||||||
// all functions in a given body should see an identical context.
|
|
||||||
var baseCtx *hcl.EvalContext
|
|
||||||
getBaseCtx := func() *hcl.EvalContext {
|
|
||||||
if baseCtx == nil {
|
|
||||||
if contextFunc != nil {
|
|
||||||
baseCtx = contextFunc()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// baseCtx might still be nil here, and that's okay
|
|
||||||
return baseCtx
|
|
||||||
}
|
|
||||||
|
|
||||||
funcs = make(map[string]function.Function)
|
|
||||||
|
|
||||||
for _, block := range content.Blocks {
|
|
||||||
name := block.Labels[0]
|
|
||||||
funcContent, funcDiags := block.Body.Content(funcBodySchema)
|
|
||||||
diags = append(diags, funcDiags...)
|
|
||||||
if funcDiags.HasErrors() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
paramsExpr := funcContent.Attributes["params"].Expr
|
|
||||||
resultExpr := funcContent.Attributes["result"].Expr
|
|
||||||
var varParamExpr hcl.Expression
|
|
||||||
if funcContent.Attributes["variadic_param"] != nil {
|
|
||||||
varParamExpr = funcContent.Attributes["variadic_param"].Expr
|
|
||||||
}
|
|
||||||
f, funcDiags := NewFunction(paramsExpr, varParamExpr, resultExpr, getBaseCtx)
|
|
||||||
if funcDiags.HasErrors() {
|
|
||||||
diags = append(diags, funcDiags...)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
funcs[name] = f
|
|
||||||
}
|
|
||||||
|
|
||||||
return funcs, remain, diags
|
|
||||||
}
|
|
@ -20,28 +20,6 @@ import (
|
|||||||
// structure a function declaration is found, etc.
|
// structure a function declaration is found, etc.
|
||||||
type ContextFunc func() *hcl.EvalContext
|
type ContextFunc func() *hcl.EvalContext
|
||||||
|
|
||||||
// DecodeUserFunctions looks for blocks of the given type in the given body
|
|
||||||
// and, for each one found, interprets it as a custom function definition.
|
|
||||||
//
|
|
||||||
// On success, the result is a mapping of function names to implementations,
|
|
||||||
// along with a new body that represents the remaining content of the given
|
|
||||||
// body which can be used for further processing.
|
|
||||||
//
|
|
||||||
// The result expression of each function is parsed during decoding but not
|
|
||||||
// evaluated until the function is called.
|
|
||||||
//
|
|
||||||
// If the given ContextFunc is non-nil, it will be called to obtain the
|
|
||||||
// context in which the function result expressions will be evaluated. If nil,
|
|
||||||
// or if it returns nil, the result expression will have access only to
|
|
||||||
// variables named after the declared parameters. A non-nil context turns
|
|
||||||
// the returned functions into closures, bound to the given context.
|
|
||||||
//
|
|
||||||
// If the returned diagnostics set has errors then the function map and
|
|
||||||
// remain body may be nil or incomplete.
|
|
||||||
func DecodeUserFunctions(body hcl.Body, blockType string, context ContextFunc) (funcs map[string]function.Function, remain hcl.Body, diags hcl.Diagnostics) {
|
|
||||||
return decodeUserFunctions(body, blockType, context)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewFunction creates a new function instance from preparsed HCL expressions.
|
// NewFunction creates a new function instance from preparsed HCL expressions.
|
||||||
func NewFunction(paramsExpr, varParamExpr, resultExpr hcl.Expression, getBaseCtx func() *hcl.EvalContext) (function.Function, hcl.Diagnostics) {
|
func NewFunction(paramsExpr, varParamExpr, resultExpr hcl.Expression, getBaseCtx func() *hcl.EvalContext) (function.Function, hcl.Diagnostics) {
|
||||||
var params []string
|
var params []string
|
||||||
@ -69,7 +47,7 @@ func NewFunction(paramsExpr, varParamExpr, resultExpr hcl.Expression, getBaseCtx
|
|||||||
if varParam == "" {
|
if varParam == "" {
|
||||||
return function.Function{}, hcl.Diagnostics{{
|
return function.Function{}, hcl.Diagnostics{{
|
||||||
Severity: hcl.DiagError,
|
Severity: hcl.DiagError,
|
||||||
Summary: "Invalid variadic_param",
|
Summary: "Invalid variadic_params",
|
||||||
Detail: "The variadic parameter name must be an identifier.",
|
Detail: "The variadic parameter name must be an identifier.",
|
||||||
Subject: varParamExpr.Range().Ptr(),
|
Subject: varParamExpr.Range().Ptr(),
|
||||||
}}
|
}}
|
||||||
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
@ -479,7 +479,7 @@ github.com/mitchellh/go-wordwrap
|
|||||||
# github.com/mitchellh/hashstructure/v2 v2.0.2
|
# github.com/mitchellh/hashstructure/v2 v2.0.2
|
||||||
## explicit; go 1.14
|
## explicit; go 1.14
|
||||||
github.com/mitchellh/hashstructure/v2
|
github.com/mitchellh/hashstructure/v2
|
||||||
# github.com/moby/buildkit v0.21.0-rc2
|
# github.com/moby/buildkit v0.21.0
|
||||||
## explicit; go 1.23.0
|
## explicit; go 1.23.0
|
||||||
github.com/moby/buildkit/api/services/control
|
github.com/moby/buildkit/api/services/control
|
||||||
github.com/moby/buildkit/api/types
|
github.com/moby/buildkit/api/types
|
||||||
|
Loading…
x
Reference in New Issue
Block a user