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

fix(gpd): Write large target patterns to file #3372

Merged
merged 5 commits into from
Dec 5, 2022
Merged
Changes from 4 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
29 changes: 28 additions & 1 deletion go/tools/gopackagesdriver/bazel_json_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
package main

import (
"bufio"
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -166,7 +168,32 @@ func (b *BazelJSONBuilder) Build(ctx context.Context, mode LoadMode) ([]string,
"--aspects=" + strings.Join(aspects, ","),
"--output_groups=" + b.outputGroupsForMode(mode),
"--keep_going", // Build all possible packages
}, bazelBuildFlags, labels)
}, bazelBuildFlags)

if len(labels) < 100 {
buildArgs = append(buildArgs, labels...)
} else {
// To avoid hitting MAX_ARGS length, write labels to a file and use `--target_pattern_file`
targetsFile, err := ioutil.TempFile("", "gopackagesdriver_targets_")
if err != nil {
return nil, fmt.Errorf("unable to create target pattern file: %w", err)
}
writer := bufio.NewWriter(targetsFile)
defer writer.Flush()
for _, l := range labels {
writer.WriteString(l+"\n")
}
err = writer.Flush()
if err != nil {
JamyDev marked this conversation as resolved.
Show resolved Hide resolved
return nil, fmt.Errorf("unable to flush data to target pattern file: %w", err)
}
defer func() {
targetsFile.Close()
os.Remove(targetsFile.Name())
}()

buildArgs = append(buildArgs, "--target_pattern_file="+targetsFile.Name())
}
files, err := b.bazel.Build(ctx, buildArgs...)
if err != nil {
return nil, fmt.Errorf("unable to bazel build %v: %w", buildArgs, err)
Expand Down