diff --git a/.bazelrc b/.bazelrc index 610c9114f9..81f19be437 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,5 +1,6 @@ ### common options for all subcommands (help, query, build, ...) -common --show_timestamps +common --show_timestamps --define gotags=sqlite_modernc + # connect to buchgr/bazel-remote cache # These flags can unfortunately not be specified for `common`, as they are not accepted by all subcommands (help, version, dump) build --remote_cache=grpc://localhost:9092 --experimental_remote_downloader=grpc://localhost:9092 diff --git a/BUILD.bazel b/BUILD.bazel index 6e8445b1dd..0bf1a0dad1 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -17,7 +17,40 @@ load("@cgrindel_bazel_starlib//updatesrc:defs.bzl", "updatesrc_update_all") # gazelle:exclude doc/** # gazelle:exclude rules_openapi/tools/node_modules/** # gazelle:exclude tools/lint/**/testdata/src/** -gazelle(name = "gazelle") + +# This is simplistic but the complete, by-the-everchanging-bazel-book, solution +# is ludicrously complicated. Go there if and when needed. +config_setting( + name = "sqlite_mattn", + define_values = { + "gotags": "sqlite_mattn", + }, +) + +config_setting( + name = "sqlite_modernc", + define_values = { + "gotags": "sqlite_modernc", + }, +) + +gazelle( + name = "gazelle", + build_tags = select({ + ":sqlite_modernc": ["sqlite_modernc"], + ":sqlite_mattn": ["sqlite_mattn"], + }), + command = "update", + extra_args = [ + "-go_naming_convention", + "go_default_library", + ], +) + +gazelle( + name = "gazelle_update_repos", + command = "update-repos", +) go_lint_config( name = "go_lint_config", diff --git a/Makefile b/Makefile index 6debc27aa0..98cffce677 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ build: bazel # Use NOTPARALLEL to force correct order. # Note: From GNU make 4.4, this still allows building any other targets (e.g. lint) in parallel. .NOTPARALLEL: all -all: go_deps.bzl protobuf mocks gazelle licenses build antlr write_all_source_files +all: go_deps.bzl protobuf mocks gazelle build antlr write_all_source_files licenses clean: bazel clean @@ -32,7 +32,8 @@ go.mod: bazel run --config=quiet @go_sdk//:bin/go -- mod tidy go_deps.bzl: go.mod - bazel run --config=quiet //:gazelle -- update-repos -prune -from_file=go.mod -to_macro=go_deps.bzl%go_deps + @# gazelle is run with "-args"; so our arguments are added to those from the gazelle() rule. + bazel run --verbose_failures --config=quiet //:gazelle_update_repos -- -args -prune -from_file=go.mod -to_macro=go_deps.bzl%go_deps @# XXX(matzf): clean up; gazelle update-repose inconsistently inserts blank lines (see bazelbuild/bazel-gazelle#1088). @sed -e '/def go_deps/,$${/^$$/d}' -i go_deps.bzl @@ -58,10 +59,10 @@ mocks: tools/gomocks.py gazelle: go_deps.bzl - tools/licenses.sh - bazel run //:gazelle --config=quiet -- update -mode=$(GAZELLE_MODE) -go_naming_convention go_default_library $(GAZELLE_DIRS) + @# call gazelle with -args, which appends our arguments to those from the gazelle() rule + bazel run //:gazelle --verbose_failures --config=quiet -- -args -mode=$(GAZELLE_MODE) $(GAZELLE_DIRS) -licenses: +licenses: bazel tools/licenses.sh antlr: diff --git a/private/storage/db/BUILD.bazel b/private/storage/db/BUILD.bazel index b1161d1aa9..7c5ee76742 100644 --- a/private/storage/db/BUILD.bazel +++ b/private/storage/db/BUILD.bazel @@ -1,15 +1,7 @@ load("//tools/lint:go.bzl", "go_library", "go_test") -# Gazelle cannot deal with a select() in srcs, and neither can lint. -# replace sqlite_mattn.go with sqlite_modernc.go in the list below if -# you want to use the modernc implementation. -# DO NOT remove the keep comment. -# In the deps attribute, only one of the two sqlite libraries -# is needed at any one time, but since Gazelle can't deal with it, -# just leave both. It doesn't hurt. go_library( name = "go_default_library", - # keep srcs = [ "doc.go", "errors.go", @@ -24,7 +16,6 @@ go_library( "//pkg/private/common:go_default_library", "//pkg/private/prom:go_default_library", "//pkg/private/serrors:go_default_library", - "@com_github_mattn_go_sqlite3//:go_default_library", "@org_modernc_sqlite//:go_default_library", ], ) diff --git a/private/storage/db/sqlite_mattn.go b/private/storage/db/sqlite_mattn.go index be817b8178..c2c205470d 100644 --- a/private/storage/db/sqlite_mattn.go +++ b/private/storage/db/sqlite_mattn.go @@ -12,6 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. +// go:build (sqlite_mattn) +// +build sqlite_mattn + package db import ( diff --git a/private/storage/db/sqlite_modernc.go b/private/storage/db/sqlite_modernc.go index 096a424b9f..0b93386ce8 100644 --- a/private/storage/db/sqlite_modernc.go +++ b/private/storage/db/sqlite_modernc.go @@ -12,6 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. +// go:build (sqlite_modernc) +// +build sqlite_modernc + package db import (