mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 09:17:49 +08:00
build: refactor print fallbacks to own function
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
parent
f0cbc95eaf
commit
126fe653c7
@ -403,38 +403,8 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
|
|||||||
|
|
||||||
res, err := c.Solve(ctx, req)
|
res, err := c.Solve(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fallback := false
|
req, ok := fallbackPrintError(err, req)
|
||||||
fallbackLint := false
|
if ok {
|
||||||
var reqErr *errdefs.UnsupportedSubrequestError
|
|
||||||
if errors.As(err, &reqErr) {
|
|
||||||
switch reqErr.Name {
|
|
||||||
case "frontend.lint":
|
|
||||||
fallbackLint = true
|
|
||||||
fallthrough
|
|
||||||
case "frontend.outline", "frontend.targets":
|
|
||||||
fallback = true
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// buildkit v0.8 vendored in Docker 20.10 does not support typed errors
|
|
||||||
if opt.PrintFunc != nil {
|
|
||||||
for _, req := range []string{"frontend.outline", "frontend.targets", "frontend.lint"} {
|
|
||||||
if strings.Contains(err.Error(), "unsupported request "+req) {
|
|
||||||
fallback = true
|
|
||||||
}
|
|
||||||
if req == "frontend.lint" {
|
|
||||||
fallbackLint = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if fallback {
|
|
||||||
req.FrontendOpt["build-arg:BUILDKIT_SYNTAX"] = printFallbackImage
|
|
||||||
if fallbackLint {
|
|
||||||
req.FrontendOpt["build-arg:BUILDKIT_SYNTAX"] = printLintFallbackImage
|
|
||||||
}
|
|
||||||
res2, err2 := c.Solve(ctx, req)
|
res2, err2 := c.Solve(ctx, req)
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -895,6 +865,46 @@ func waitContextDeps(ctx context.Context, index int, results *waitmap.Map, so *c
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fallbackPrintError(err error, req gateway.SolveRequest) (gateway.SolveRequest, bool) {
|
||||||
|
if _, ok := req.FrontendOpt["requestid"]; !ok {
|
||||||
|
return req, false
|
||||||
|
}
|
||||||
|
|
||||||
|
fallback := false
|
||||||
|
fallbackLint := false
|
||||||
|
var reqErr *errdefs.UnsupportedSubrequestError
|
||||||
|
if errors.As(err, &reqErr) {
|
||||||
|
switch reqErr.Name {
|
||||||
|
case "frontend.lint":
|
||||||
|
fallbackLint = true
|
||||||
|
fallthrough
|
||||||
|
case "frontend.outline", "frontend.targets":
|
||||||
|
fallback = true
|
||||||
|
default:
|
||||||
|
return req, false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// buildkit v0.8 vendored in Docker 20.10 does not support typed errors
|
||||||
|
for _, req := range []string{"frontend.outline", "frontend.targets", "frontend.lint"} {
|
||||||
|
if strings.Contains(err.Error(), "unsupported request "+req) {
|
||||||
|
fallback = true
|
||||||
|
}
|
||||||
|
if req == "frontend.lint" {
|
||||||
|
fallbackLint = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if fallback {
|
||||||
|
req.FrontendOpt["build-arg:BUILDKIT_SYNTAX"] = printFallbackImage
|
||||||
|
if fallbackLint {
|
||||||
|
req.FrontendOpt["build-arg:BUILDKIT_SYNTAX"] = printLintFallbackImage
|
||||||
|
}
|
||||||
|
return req, true
|
||||||
|
}
|
||||||
|
return req, false
|
||||||
|
}
|
||||||
|
|
||||||
func noPrintFunc(opt map[string]Options) bool {
|
func noPrintFunc(opt map[string]Options) bool {
|
||||||
for _, v := range opt {
|
for _, v := range opt {
|
||||||
if v.PrintFunc != nil {
|
if v.PrintFunc != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user