Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: rename PrintFunc to CallFunc #2654

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bake/bake.go
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,7 @@ func toBuildOpt(t *Target, inp *Input) (*build.Options, error) {
}

if t.Call != nil {
bo.PrintFunc = &build.PrintFunc{
bo.CallFunc = &build.CallFunc{
Name: *t.Call,
}
}
Expand Down
24 changes: 12 additions & 12 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ type Options struct {

Session []session.Attachable
Linked bool // Linked marks this target as exclusively linked (not requested by the user).
PrintFunc *PrintFunc
CallFunc *CallFunc
ProvenanceResponseMode confutil.MetadataProvenanceMode
SourcePolicy *spb.Policy
GroupRef string
}

type PrintFunc struct {
type CallFunc struct {
Name string
Format string
IgnoreStatus bool
Expand Down Expand Up @@ -169,7 +169,7 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
}
}

if noMobyDriver != nil && !noDefaultLoad() && noPrintFunc(opt) {
if noMobyDriver != nil && !noDefaultLoad() && noCallFunc(opt) {
var noOutputTargets []string
for name, opt := range opt {
if noMobyDriver.Features(ctx)[driver.DefaultLoad] {
Expand Down Expand Up @@ -426,15 +426,15 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
defer func() { <-done }()

cc := c
var printRes map[string][]byte
var callRes map[string][]byte
buildFunc := func(ctx context.Context, c gateway.Client) (*gateway.Result, error) {
if opt.PrintFunc != nil {
if opt.CallFunc != nil {
if _, ok := req.FrontendOpt["frontend.caps"]; !ok {
req.FrontendOpt["frontend.caps"] = "moby.buildkit.frontend.subrequests+forward"
} else {
req.FrontendOpt["frontend.caps"] += ",moby.buildkit.frontend.subrequests+forward"
}
req.FrontendOpt["requestid"] = "frontend." + opt.PrintFunc.Name
req.FrontendOpt["requestid"] = "frontend." + opt.CallFunc.Name
}

res, err := c.Solve(ctx, req)
Expand All @@ -450,8 +450,8 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
return nil, err
}
}
if opt.PrintFunc != nil {
printRes = res.Metadata
if opt.CallFunc != nil {
callRes = res.Metadata
}

rKey := resultKey(dp.driverIndex, k)
Expand Down Expand Up @@ -507,10 +507,10 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
if rr.ExporterResponse == nil {
rr.ExporterResponse = map[string]string{}
}
for k, v := range printRes {
for k, v := range callRes {
rr.ExporterResponse[k] = string(v)
}
if opt.PrintFunc == nil {
if opt.CallFunc == nil {
rr.ExporterResponse["buildx.build.ref"] = buildRef
if node.Driver.HistoryAPISupported(ctx) {
if err := setRecordProvenance(ctx, c, rr, so.Ref, opt.ProvenanceResponseMode, pw); err != nil {
Expand Down Expand Up @@ -1093,9 +1093,9 @@ func fallbackPrintError(err error, req gateway.SolveRequest) (gateway.SolveReque
return req, false
}

func noPrintFunc(opt map[string]Options) bool {
func noCallFunc(opt map[string]Options) bool {
for _, v := range opt {
if v.PrintFunc != nil {
if v.CallFunc != nil {
return false
}
}
Expand Down
6 changes: 3 additions & 3 deletions build/opt.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func toSolveOpt(ctx context.Context, node builder.Node, multiDriver bool, opt Op
case 1:
// valid
case 0:
if !noDefaultLoad() && opt.PrintFunc == nil {
if !noDefaultLoad() && opt.CallFunc == nil {
if nodeDriver.IsMobyDriver() {
// backwards compat for docker driver only:
// this ensures the build results in a docker image.
Expand Down Expand Up @@ -347,8 +347,8 @@ func toSolveOpt(ctx context.Context, node builder.Node, multiDriver bool, opt Op
so.FrontendAttrs["ulimit"] = ulimits
}

// mark info request as internal
if opt.PrintFunc != nil {
// mark call request as internal
if opt.CallFunc != nil {
so.Internal = true
}

Expand Down
20 changes: 10 additions & 10 deletions commands/bake.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func runBake(ctx context.Context, dockerCli command.Cli, targets []string, in ba
targets = []string{"default"}
}

callFunc, err := buildflags.ParsePrintFunc(in.callFunc)
callFunc, err := buildflags.ParseCallFunc(in.callFunc)
if err != nil {
return err
}
Expand Down Expand Up @@ -225,12 +225,12 @@ func runBake(ctx context.Context, dockerCli command.Cli, targets []string, in ba
}

for _, opt := range bo {
if opt.PrintFunc != nil {
cf, err := buildflags.ParsePrintFunc(opt.PrintFunc.Name)
if opt.CallFunc != nil {
cf, err := buildflags.ParseCallFunc(opt.CallFunc.Name)
if err != nil {
return err
}
opt.PrintFunc.Name = cf.Name
opt.CallFunc.Name = cf.Name
}
}

Expand Down Expand Up @@ -286,14 +286,14 @@ func runBake(ctx context.Context, dockerCli command.Cli, targets []string, in ba

for _, name := range names {
req := bo[name]
if req.PrintFunc == nil {
if req.CallFunc == nil {
continue
}

pf := &pb.PrintFunc{
Name: req.PrintFunc.Name,
Format: req.PrintFunc.Format,
IgnoreStatus: req.PrintFunc.IgnoreStatus,
pf := &pb.CallFunc{
Name: req.CallFunc.Name,
Format: req.CallFunc.Format,
IgnoreStatus: req.CallFunc.IgnoreStatus,
}

if callFunc != nil {
Expand Down Expand Up @@ -357,7 +357,7 @@ func runBake(ctx context.Context, dockerCli command.Cli, targets []string, in ba
"build": def,
}
if res, ok := jsonResults[name]; ok {
printName := bo[name].PrintFunc.Name
printName := bo[name].CallFunc.Name
if printName == "lint" {
printName = "check"
}
Expand Down
24 changes: 12 additions & 12 deletions commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ type buildOptions struct {
noCacheFilter []string
outputs []string
platforms []string
printFunc string
callFunc string
secrets []string
shmSize dockeropts.MemBytes
ssh []string
Expand Down Expand Up @@ -199,13 +199,13 @@ func (o *buildOptions) toControllerOptions() (*controllerapi.BuildOptions, error
return nil, err
}

opts.PrintFunc, err = buildflags.ParsePrintFunc(o.printFunc)
opts.CallFunc, err = buildflags.ParseCallFunc(o.callFunc)
if err != nil {
return nil, err
}

prm := confutil.MetadataProvenance()
if opts.PrintFunc != nil || len(o.metadataFile) == 0 {
if opts.CallFunc != nil || len(o.metadataFile) == 0 {
prm = confutil.MetadataProvenanceModeDisabled
}
opts.ProvenanceResponseMode = string(prm)
Expand Down Expand Up @@ -377,7 +377,7 @@ func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions)
}
if options.metadataFile != "" {
dt := decodeExporterResponse(resp.ExporterResponse)
if opts.PrintFunc == nil {
if opts.CallFunc == nil {
if warnings := printer.Warnings(); len(warnings) > 0 && confutil.MetadataWarningsEnabled() {
dt["buildx.build.warnings"] = warnings
}
Expand All @@ -386,8 +386,8 @@ func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions)
return err
}
}
if opts.PrintFunc != nil {
if exitcode, err := printResult(dockerCli.Out(), opts.PrintFunc, resp.ExporterResponse); err != nil {
if opts.CallFunc != nil {
if exitcode, err := printResult(dockerCli.Out(), opts.CallFunc, resp.ExporterResponse); err != nil {
return err
} else if exitcode != 0 {
os.Exit(exitcode)
Expand Down Expand Up @@ -645,8 +645,8 @@ func buildCmd(dockerCli command.Cli, rootOpts *rootOptions, debugConfig *debug.D
cobrautil.MarkFlagsExperimental(flags, "root", "detach", "server-config")
}

flags.StringVar(&options.printFunc, "call", "build", `Set method for evaluating build ("check", "outline", "targets")`)
flags.VarPF(callAlias(&options.printFunc, "check"), "check", "", `Shorthand for "--call=check"`)
flags.StringVar(&options.callFunc, "call", "build", `Set method for evaluating build ("check", "outline", "targets")`)
flags.VarPF(callAlias(&options.callFunc, "check"), "check", "", `Shorthand for "--call=check"`)
flags.Lookup("check").NoOptDefVal = "true"

// hidden flags
Expand All @@ -655,7 +655,7 @@ func buildCmd(dockerCli command.Cli, rootOpts *rootOptions, debugConfig *debug.D
var ignoreBool bool
var ignoreInt int64

flags.StringVar(&options.printFunc, "print", "", "Print result of information request (e.g., outline, targets)")
flags.StringVar(&options.callFunc, "print", "", "Print result of information request (e.g., outline, targets)")
cobrautil.MarkFlagsExperimental(flags, "print")
flags.MarkHidden("print")

Expand Down Expand Up @@ -882,7 +882,7 @@ func printWarnings(w io.Writer, warnings []client.VertexWarning, mode progressui
}
}

func printResult(w io.Writer, f *controllerapi.PrintFunc, res map[string]string) (int, error) {
func printResult(w io.Writer, f *controllerapi.CallFunc, res map[string]string) (int, error) {
switch f.Name {
case "outline":
return 0, printValue(w, outline.PrintOutline, outline.SubrequestsOutlineDefinition.Version, f.Format, res)
Expand Down Expand Up @@ -940,9 +940,9 @@ func printResult(w io.Writer, f *controllerapi.PrintFunc, res map[string]string)
return 0, nil
}

type printFunc func([]byte, io.Writer) error
type callFunc func([]byte, io.Writer) error

func printValue(w io.Writer, printer printFunc, version string, format string, res map[string]string) error {
func printValue(w io.Writer, printer callFunc, version string, format string, res map[string]string) error {
if format == "json" {
fmt.Fprintln(w, res["result.json"])
return nil
Expand Down
10 changes: 5 additions & 5 deletions controller/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ func RunBuild(ctx context.Context, dockerCli command.Cli, in controllerapi.Build
}
opts.Allow = allow

if in.PrintFunc != nil {
opts.PrintFunc = &build.PrintFunc{
Name: in.PrintFunc.Name,
Format: in.PrintFunc.Format,
IgnoreStatus: in.PrintFunc.IgnoreStatus,
if in.CallFunc != nil {
opts.CallFunc = &build.CallFunc{
Name: in.CallFunc.Name,
Format: in.CallFunc.Format,
IgnoreStatus: in.CallFunc.IgnoreStatus,
}
}

Expand Down
Loading