Skip to content

Commit

Permalink
replace golang.org/x/tools with golang.org/x/tools/go/[email protected]
Browse files Browse the repository at this point in the history
…ecated (#1603)

* replace golang.org/x/tools with golang.org/x/tools/go/[email protected]

* Update buildtools to work with `import`-style targets

Allows the following to work:

bazel run //:gazelle_ci --enable_bzlmod

* Remove build_naming_convention=go_default_library for bazel buildtools

* update buildtools override in BCR test
  • Loading branch information
malt3 authored Aug 28, 2023
1 parent 390f0d8 commit 2f257dc
Show file tree
Hide file tree
Showing 44 changed files with 492 additions and 93 deletions.
2 changes: 1 addition & 1 deletion Design.rst
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ Gazelle resolves each import string in ``_gazelle_imports`` as follows:
* In ``external`` mode, Gazelle determines the portion of the import path
that corresponds to a repository using `golang.org/x/tools/go/vcs`_. This
part of the path is converted into a repository name (for example,
``@org_golang_x_tools``), and the rest is converted to a package name.
``@org_golang_x_tools_go_vcs``), and the rest is converted to a package name.

* In ``vendored`` mode, Gazelle constructs a label by prepending ``vendor/``
to the import path.
Expand Down
9 changes: 9 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ use_repo(

go_deps = use_extension("//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")

# golang.org/x/tools is not a direct dependency of the go code anymore
# but bazel buildtools and nogo depend on it.
go_deps.module(
path = "golang.org/x/tools",
sum = "h1:8WMNJAz3zrtPmnYC7ISf5dEn3MT0gY7jBJfw27yrrLo=",
version = "v0.9.1",
)
use_repo(
go_deps,
"com_github_bazelbuild_buildtools",
Expand All @@ -36,6 +44,7 @@ use_repo(
"org_golang_x_mod",
"org_golang_x_sync",
"org_golang_x_tools",
"org_golang_x_tools_go_vcs",
# Referenced by `gazelle_binary`.
"bazel_gazelle_go_repository_config",
)
Expand Down
3 changes: 2 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ load("@bazel_skylib//lib:unittest.bzl", "register_unittest_toolchains")
register_unittest_toolchains()

# gazelle:repository go_repository name=co_honnef_go_tools importpath=honnef.co/go/tools
# gazelle:repository go_repository name=com_github_bazelbuild_buildtools importpath=github.com/bazelbuild/buildtools build_naming_convention=go_default_library
# gazelle:repository go_repository name=com_github_bazelbuild_buildtools importpath=github.com/bazelbuild/buildtools
# gazelle:repository go_repository name=com_github_bazelbuild_rules_go importpath=github.com/bazelbuild/rules_go
# gazelle:repository go_repository name=com_github_bmatcuk_doublestar_v4 importpath=github.com/bmatcuk/doublestar/v4
# gazelle:repository go_repository name=com_github_burntsushi_toml importpath=github.com/BurntSushi/toml
Expand Down Expand Up @@ -87,4 +87,5 @@ register_unittest_toolchains()
# gazelle:repository go_repository name=org_golang_x_sys importpath=golang.org/x/sys
# gazelle:repository go_repository name=org_golang_x_text importpath=golang.org/x/text
# gazelle:repository go_repository name=org_golang_x_tools importpath=golang.org/x/tools
# gazelle:repository go_repository name=org_golang_x_tools_go_vcs importpath=golang.org/x/tools/go/vcs
# gazelle:repository go_repository name=org_golang_x_xerrors importpath=golang.org/x/xerrors
4 changes: 2 additions & 2 deletions cmd/fetch_repo/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ go_library(
],
importpath = "github.com/bazelbuild/bazel-gazelle/cmd/fetch_repo",
visibility = ["//visibility:private"],
deps = ["@org_golang_x_tools//go/vcs"],
deps = ["@org_golang_x_tools_go_vcs//:vcs"],
)

go_binary(
Expand All @@ -22,7 +22,7 @@ go_test(
name = "fetch_repo_test",
srcs = ["fetch_repo_test.go"],
embed = [":fetch_repo_lib"],
deps = ["@org_golang_x_tools//go/vcs"],
deps = ["@org_golang_x_tools_go_vcs//:vcs"],
)

filegroup(
Expand Down
2 changes: 1 addition & 1 deletion cmd/move_labels/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ go_library(
"//internal/wspace",
"//label",
"//pathtools",
"@com_github_bazelbuild_buildtools//build:go_default_library",
"@com_github_bazelbuild_buildtools//build",
],
)

Expand Down
15 changes: 11 additions & 4 deletions deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ def gazelle_dependencies(
name = "com_github_bazelbuild_buildtools",
build_naming_convention = "go_default_library",
importpath = "github.com/bazelbuild/buildtools",
sum = "h1:Fl1FfItZp34QIQmmDTbZXHB5XA6JfbNNfH7tRRGWvQo=",
version = "v0.0.0-20230510134650-37bd1811516d",
sum = "h1:Ok7SjJ73qAaUasBxHavkfjgaXr2jkpvu0/yQ39mMaBo=",
version = "v0.0.0-20230823134145-56628089db01",
)
_maybe(
go_repository,
Expand Down Expand Up @@ -320,8 +320,8 @@ def gazelle_dependencies(
go_repository,
name = "org_golang_x_sys",
importpath = "golang.org/x/sys",
sum = "h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=",
version = "v0.8.0",
sum = "h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=",
version = "v0.9.0",
)
_maybe(
go_repository,
Expand All @@ -337,6 +337,13 @@ def gazelle_dependencies(
sum = "h1:8WMNJAz3zrtPmnYC7ISf5dEn3MT0gY7jBJfw27yrrLo=",
version = "v0.9.1",
)
_maybe(
go_repository,
name = "org_golang_x_tools_go_vcs",
importpath = "golang.org/x/tools/go/vcs",
sum = "h1:cOIJqWBl99H1dH5LWizPa+0ImeeJq3t3cJjaeOWUAL4=",
version = "v0.1.0-deprecated",
)
_maybe(
go_repository,
name = "org_golang_x_xerrors",
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ module github.com/bazelbuild/bazel-gazelle
go 1.20

require (
github.com/bazelbuild/buildtools v0.0.0-20230510134650-37bd1811516d
github.com/bazelbuild/buildtools v0.0.0-20230823134145-56628089db01
github.com/bazelbuild/rules_go v0.39.1
github.com/bmatcuk/doublestar/v4 v4.6.0
github.com/fsnotify/fsnotify v1.6.0
github.com/google/go-cmp v0.5.9
github.com/pmezard/go-difflib v1.0.0
golang.org/x/mod v0.12.0
golang.org/x/sync v0.2.0
golang.org/x/tools v0.9.1
golang.org/x/tools/go/vcs v0.1.0-deprecated
)

require golang.org/x/sys v0.8.0 // indirect
require golang.org/x/sys v0.9.0 // indirect
14 changes: 6 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/bazelbuild/buildtools v0.0.0-20230510134650-37bd1811516d h1:Fl1FfItZp34QIQmmDTbZXHB5XA6JfbNNfH7tRRGWvQo=
github.com/bazelbuild/buildtools v0.0.0-20230510134650-37bd1811516d/go.mod h1:689QdV3hBP7Vo9dJMmzhoYIyo/9iMhEmHkJcnaPRCbo=
github.com/bazelbuild/buildtools v0.0.0-20230823134145-56628089db01 h1:Ok7SjJ73qAaUasBxHavkfjgaXr2jkpvu0/yQ39mMaBo=
github.com/bazelbuild/buildtools v0.0.0-20230823134145-56628089db01/go.mod h1:689QdV3hBP7Vo9dJMmzhoYIyo/9iMhEmHkJcnaPRCbo=
github.com/bazelbuild/rules_go v0.39.1 h1:wkJLUDx59dntWMghuL8++GteoU1To6sRoKJXuyFtmf8=
github.com/bazelbuild/rules_go v0.39.1/go.mod h1:TMHmtfpvyfsxaqfL9WnahCsXMWDMICTw7XeK9yVb+YU=
github.com/bmatcuk/doublestar/v4 v4.6.0 h1:HTuxyug8GyFbRkrffIpzNCSK4luc0TY3wzXvzIZhEXc=
Expand Down Expand Up @@ -43,8 +43,6 @@ golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk=
golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand All @@ -61,15 +59,15 @@ golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.9.1 h1:8WMNJAz3zrtPmnYC7ISf5dEn3MT0gY7jBJfw27yrrLo=
golang.org/x/tools v0.9.1/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc=
golang.org/x/tools/go/vcs v0.1.0-deprecated h1:cOIJqWBl99H1dH5LWizPa+0ImeeJq3t3cJjaeOWUAL4=
golang.org/x/tools/go/vcs v0.1.0-deprecated/go.mod h1:zUrvATBAvEI9535oC0yWYsLsHIV4Z7g63sNPVMtuBy8=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
Expand Down
2 changes: 1 addition & 1 deletion internal/module/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go_library(
srcs = ["module.go"],
importpath = "github.com/bazelbuild/bazel-gazelle/internal/module",
visibility = ["//:__subpackages__"],
deps = ["@com_github_bazelbuild_buildtools//build:go_default_library"],
deps = ["@com_github_bazelbuild_buildtools//build"],
)

filegroup(
Expand Down
6 changes: 3 additions & 3 deletions language/go/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ go_library(
"//repo",
"//resolve",
"//rule",
"@com_github_bazelbuild_buildtools//build:go_default_library",
"@com_github_bazelbuild_buildtools//build",
"@org_golang_x_mod//modfile",
"@org_golang_x_mod//module",
"@org_golang_x_sync//errgroup",
Expand Down Expand Up @@ -81,10 +81,10 @@ go_test(
"//rule",
"//testtools",
"//walk",
"@com_github_bazelbuild_buildtools//build:go_default_library",
"@com_github_bazelbuild_buildtools//build",
"@com_github_google_go_cmp//cmp",
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
"@org_golang_x_tools//go/vcs",
"@org_golang_x_tools_go_vcs//:vcs",
],
)

Expand Down
2 changes: 1 addition & 1 deletion language/proto/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ go_test(
"//rule",
"//testtools",
"//walk",
"@com_github_bazelbuild_buildtools//build:go_default_library",
"@com_github_bazelbuild_buildtools//build",
],
)

Expand Down
4 changes: 2 additions & 2 deletions merger/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//rule",
"@com_github_bazelbuild_buildtools//build:go_default_library",
"@com_github_bazelbuild_buildtools//build",
],
)

Expand All @@ -27,7 +27,7 @@ go_test(
"//language/go",
"//language/proto",
"//rule",
"@com_github_bazelbuild_buildtools//build:go_default_library",
"@com_github_bazelbuild_buildtools//build",
"@com_github_google_go_cmp//cmp",
],
)
Expand Down
4 changes: 2 additions & 2 deletions repo/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ go_library(
"//pathtools",
"//rule",
"@org_golang_x_mod//modfile",
"@org_golang_x_tools//go/vcs",
"@org_golang_x_tools_go_vcs//:vcs",
],
)

Expand All @@ -29,7 +29,7 @@ go_test(
"//pathtools",
"//rule",
"//testtools",
"@org_golang_x_tools//go/vcs",
"@org_golang_x_tools_go_vcs//:vcs",
],
)

Expand Down
6 changes: 3 additions & 3 deletions rule/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//label",
"@com_github_bazelbuild_buildtools//build:go_default_library",
"@com_github_bazelbuild_buildtools//tables:go_default_library",
"@com_github_bazelbuild_buildtools//build",
"@com_github_bazelbuild_buildtools//tables",
],
)

Expand All @@ -32,7 +32,7 @@ go_test(
],
embed = [":rule"],
deps = [
"@com_github_bazelbuild_buildtools//build:go_default_library",
"@com_github_bazelbuild_buildtools//build",
"@com_github_google_go_cmp//cmp",
],
)
Expand Down
6 changes: 3 additions & 3 deletions tests/bcr/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ go_deps.gazelle_override(
)
go_deps.archive_override(
urls = [
"https://github.com/bazelbuild/buildtools/archive/refs/tags/v6.1.2.tar.gz",
"https://github.com/bazelbuild/buildtools/archive/ae8e3206e815d086269eb208b01f300639a4b194.tar.gz",
],
strip_prefix = "buildtools-6.1.2",
strip_prefix = "buildtools-ae8e3206e815d086269eb208b01f300639a4b194",
path = "github.com/bazelbuild/buildtools",
sha256 = "977a0bd4593c8d4c8f45e056d181c35e48aa01ad4f8090bdb84f78dca42f47dc",
sha256 = "05d7c3d2bd3cc0b02d15672fefa0d6be48c7aebe459c1c99dced7ac5e598508f",
)

# Transitive dependencies have to be listed here explicitly.
Expand Down
Loading

0 comments on commit 2f257dc

Please sign in to comment.