mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-29 08:57:44 +08:00
Parse bake config as hcl falling back to json
Signed-off-by: Patrick Van Stee <patrick@vanstee.me>
This commit is contained in:
parent
44c840b31d
commit
355261e49e
26
bake/hcl.go
26
bake/hcl.go
@ -74,18 +74,20 @@ type staticConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ParseHCL(dt []byte, fn string) (*Config, error) {
|
func ParseHCL(dt []byte, fn string) (*Config, error) {
|
||||||
var file *hcl.File
|
// Decode user defined functions, first parsing as hcl and falling back to
|
||||||
var diags hcl.Diagnostics
|
// json, returning errors based on the file suffix.
|
||||||
|
file, hcldiags := hclsyntax.ParseConfig(dt, fn, hcl.Pos{Line: 1, Column: 1})
|
||||||
// Decode user defined functions.
|
if hcldiags.HasErrors() {
|
||||||
fnl := strings.ToLower(fn)
|
var jsondiags hcl.Diagnostics
|
||||||
if strings.HasSuffix(fnl, ".json") {
|
file, jsondiags = json.Parse(dt, fn)
|
||||||
file, diags = json.Parse(dt, fn)
|
if jsondiags.HasErrors() {
|
||||||
} else {
|
fnl := strings.ToLower(fn)
|
||||||
file, diags = hclsyntax.ParseConfig(dt, fn, hcl.Pos{Line: 1, Column: 1})
|
if strings.HasSuffix(fnl, ".json") {
|
||||||
}
|
return nil, jsondiags
|
||||||
if diags.HasErrors() {
|
} else {
|
||||||
return nil, diags
|
return nil, hcldiags
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
userFunctions, _, diags := userfunc.DecodeUserFunctions(file.Body, "function", func() *hcl.EvalContext {
|
userFunctions, _, diags := userfunc.DecodeUserFunctions(file.Body, "function", func() *hcl.EvalContext {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user