From 12003556bb6380ebc1eaab20c0947365e641153d Mon Sep 17 00:00:00 2001 From: Jamy Timmermans Date: Thu, 20 Oct 2022 14:38:01 -0700 Subject: [PATCH 1/3] feat(pkg-drv): allow setting custom aspect and kinds --- go/tools/gopackagesdriver/bazel_json_builder.go | 8 ++++++-- go/tools/gopackagesdriver/main.go | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/go/tools/gopackagesdriver/bazel_json_builder.go b/go/tools/gopackagesdriver/bazel_json_builder.go index 6a8d46cb8b..e5c2ff695f 100644 --- a/go/tools/gopackagesdriver/bazel_json_builder.go +++ b/go/tools/gopackagesdriver/bazel_json_builder.go @@ -35,7 +35,11 @@ func (b *BazelJSONBuilder) fileQuery(filename string) string { 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) + addtlKinds := "" + if len(additionalKinds) > 0 { + addtlKinds = "|" + strings.Join(additionalKinds, "|") + } + return fmt.Sprintf(`kind("go_library|go_test|go_binary%s", same_pkg_direct_rdeps("%s"))`, addtlKinds, filename) } func (b *BazelJSONBuilder) packageQuery(importPath string) string { @@ -120,7 +124,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) diff --git a/go/tools/gopackagesdriver/main.go b/go/tools/gopackagesdriver/main.go index 17ee60a470..356e5c6c1a 100644 --- a/go/tools/gopackagesdriver/main.go +++ b/go/tools/gopackagesdriver/main.go @@ -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), From 2ef55828f0b889d03d9b5b96963339093163a1df Mon Sep 17 00:00:00 2001 From: Jamy Timmermans Date: Thu, 20 Oct 2022 16:47:02 -0700 Subject: [PATCH 2/3] fixup! use kinds array --- go/tools/gopackagesdriver/bazel_json_builder.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/go/tools/gopackagesdriver/bazel_json_builder.go b/go/tools/gopackagesdriver/bazel_json_builder.go index e5c2ff695f..55b235eeb1 100644 --- a/go/tools/gopackagesdriver/bazel_json_builder.go +++ b/go/tools/gopackagesdriver/bazel_json_builder.go @@ -30,16 +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 } - addtlKinds := "" - if len(additionalKinds) > 0 { - addtlKinds = "|" + strings.Join(additionalKinds, "|") - } - return fmt.Sprintf(`kind("go_library|go_test|go_binary%s", same_pkg_direct_rdeps("%s"))`, addtlKinds, 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 { From bf72488363f3de9ef836e5ab1061e0e13b0b41c2 Mon Sep 17 00:00:00 2001 From: Jamy Timmermans Date: Thu, 20 Oct 2022 16:48:32 -0700 Subject: [PATCH 3/3] fixup! format --- go/tools/gopackagesdriver/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go/tools/gopackagesdriver/main.go b/go/tools/gopackagesdriver/main.go index 356e5c6c1a..ff9f9621ad 100644 --- a/go/tools/gopackagesdriver/main.go +++ b/go/tools/gopackagesdriver/main.go @@ -58,8 +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")) + 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),