build: small readability improvements by reversal of conditions

This adds some ideomatic earlier returns and loop continuations
to avoid deeply nested coditional blocks that are several lines
long.

Signed-off-by: Ilya Dmitrichenko <errordeveloper@gmail.com>
pull/1466/head
Ilya Dmitrichenko 3 years ago
parent 387cc633c7
commit 08b6d36deb
No known key found for this signature in database
GPG Key ID: E7889175A6C0CEB9

@ -691,7 +691,10 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
return nil return nil
} }
if pushNames != "" { if pushNames == "" {
return nil
}
progress.Write(pw, fmt.Sprintf("merging manifest list %s", pushNames), func() error { progress.Write(pw, fmt.Sprintf("merging manifest list %s", pushNames), func() error {
descs := make([]specs.Descriptor, 0, len(res)) descs := make([]specs.Descriptor, 0, len(res))
@ -705,7 +708,11 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
}) })
} }
} }
if len(descs) > 0 {
if len(descs) == 0 {
return nil
}
var imageopt imagetools.Opt var imageopt imagetools.Opt
for _, dp := range dps { for _, dp := range dps {
imageopt = nodes[dp.driverIndex].ImageOpt imageopt = nodes[dp.driverIndex].ImageOpt
@ -773,10 +780,10 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
}, },
} }
respMu.Unlock() respMu.Unlock()
}
return nil return nil
}) })
}
return nil return nil
}) })
@ -866,7 +873,9 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
return nil, err return nil, err
} }
var reqErr *errdefs.UnsupportedSubrequestError var reqErr *errdefs.UnsupportedSubrequestError
if !isFallback { if isFallback {
return nil, err
}
if errors.As(err, &reqErr) { if errors.As(err, &reqErr) {
switch reqErr.Name { switch reqErr.Name {
case "frontend.outline", "frontend.targets": case "frontend.outline", "frontend.targets":
@ -882,7 +891,6 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
origErr = err origErr = err
continue continue
} }
}
return nil, err return nil, err
} }
if opt.PrintFunc != nil { if opt.PrintFunc != nil {
@ -908,10 +916,15 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
} }
node := nodes[dp.driverIndex].Driver node := nodes[dp.driverIndex].Driver
if node.IsMobyDriver() { if !node.IsMobyDriver() {
return nil
}
for _, e := range so.Exports { for _, e := range so.Exports {
if e.Type == "moby" && e.Attrs["push"] != "" { if e.Type == "moby" && e.Attrs["push"] != "" {
if ok, _ := strconv.ParseBool(e.Attrs["push"]); ok { if ok, _ := strconv.ParseBool(e.Attrs["push"]); !ok {
continue
}
pushNames = e.Attrs["name"] pushNames = e.Attrs["name"]
if pushNames == "" { if pushNames == "" {
return errors.Errorf("tag is needed when pushing to registry") return errors.Errorf("tag is needed when pushing to registry")
@ -940,8 +953,7 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
} }
} }
} }
}
}
return nil return nil
}) })
@ -1315,7 +1327,11 @@ func waitContextDeps(ctx context.Context, index int, results *waitmap.Map, so *c
} }
delete(so.FrontendAttrs, v) delete(so.FrontendAttrs, v)
} }
if rr.Ref != nil {
if rr.Ref == nil {
continue
}
st, err := rr.Ref.ToState() st, err := rr.Ref.ToState()
if err != nil { if err != nil {
return err return err
@ -1337,7 +1353,6 @@ func waitContextDeps(ctx context.Context, index int, results *waitmap.Map, so *c
so.FrontendAttrs["input-metadata:"+k] = string(dt) so.FrontendAttrs["input-metadata:"+k] = string(dt)
} }
} }
}
return nil return nil
} }

Loading…
Cancel
Save