Skip to content

Commit

Permalink
feat(pkg-drv): allow setting custom aspect and kinds (#3328)
Browse files Browse the repository at this point in the history
* feat(pkg-drv): allow setting custom aspect and kinds

* fixup! use kinds array

* fixup! format
  • Loading branch information
JamyDev authored Oct 21, 2022
1 parent 8a731c5 commit 997520f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions go/tools/gopackagesdriver/bazel_json_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ const (
RulesGoStdlibLabel = "@io_bazel_rules_go//:stdlib"
)

var _defaultKinds = []string{"go_library", "go_test", "go_binary"}

func (b *BazelJSONBuilder) fileQuery(filename string) string {
if filepath.IsAbs(filename) {
fp, _ := filepath.Rel(b.bazel.WorkspaceRoot(), filename)
filename = fp
}
return fmt.Sprintf(`kind("go_library|go_test|go_binary", same_pkg_direct_rdeps("%s"))`, filename)
kinds := append(_defaultKinds, additionalKinds...)
return fmt.Sprintf(`kind("%s", same_pkg_direct_rdeps("%s"))`, strings.Join(kinds, "|"), filename)
}

func (b *BazelJSONBuilder) packageQuery(importPath string) string {
Expand Down Expand Up @@ -120,7 +123,7 @@ func (b *BazelJSONBuilder) Build(ctx context.Context, mode LoadMode) ([]string,
"--experimental_convenience_symlinks=ignore",
"--ui_event_filters=-info,-stderr",
"--noshow_progress",
"--aspects=" + rulesGoRepositoryName + "//go/tools/gopackagesdriver:aspect.bzl%go_pkg_info_aspect",
"--aspects=" + customAspect,
"--output_groups=" + b.outputGroupsForMode(mode),
"--keep_going", // Build all possible packages
}, bazelFlags, bazelBuildFlags, labels)
Expand Down
2 changes: 2 additions & 0 deletions go/tools/gopackagesdriver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ var (
bazelQueryScope = getenvDefault("GOPACKAGESDRIVER_BAZEL_QUERY_SCOPE", "")
bazelBuildFlags = strings.Fields(os.Getenv("GOPACKAGESDRIVER_BAZEL_BUILD_FLAGS"))
workspaceRoot = os.Getenv("BUILD_WORKSPACE_DIRECTORY")
customAspect = getenvDefault("GOPACKAGESDRIVER_BAZEL_ASPECT", rulesGoRepositoryName+"//go/tools/gopackagesdriver:aspect.bzl%go_pkg_info_aspect")
additionalKinds = strings.Fields(os.Getenv("GOPACKAGESDRIVER_BAZEL_KINDS"))
emptyResponse = &driverResponse{
NotHandled: false,
Sizes: types.SizesFor("gc", "amd64").(*types.StdSizes),
Expand Down

0 comments on commit 997520f

Please sign in to comment.