Skip to content

Commit

Permalink
Migrate Gazelle to Go import_alias naming convention (#861)
Browse files Browse the repository at this point in the history
* Set naming convention in main build file.
* Add gazelle:repository declarations in WORKSPACE for repos in gazelle_dependencies.
* Run 'gazelle fix'.
* Manual fixes for manually written targets.

For #5
  • Loading branch information
Jay Conrod authored Aug 7, 2020
1 parent 7662741 commit 570264c
Show file tree
Hide file tree
Showing 29 changed files with 307 additions and 206 deletions.
7 changes: 4 additions & 3 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ load("//:def.bzl", "gazelle", "gazelle_binary")
# gazelle:exclude third_party
# gazelle:exclude .bazelci
# gazelle:exclude .github
# gazelle:go_naming_convention import_alias
gazelle(
name = "gazelle",
command = "fix",
Expand All @@ -15,9 +16,9 @@ gazelle(
gazelle_binary(
name = "gazelle_local",
languages = [
"//language/proto:go_default_library",
"//language/go:go_default_library",
"//internal/language/test_filegroup:go_default_library",
"//language/proto",
"//language/go",
"//internal/language/test_filegroup",
],
)

Expand Down
10 changes: 10 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,13 @@ go_register_toolchains(nogo = "@bazel_gazelle//:nogo")
load("//:deps.bzl", "gazelle_dependencies")

gazelle_dependencies()

# gazelle:repository go_repository name=org_golang_x_sync importpath=golang.org/x/sync
# gazelle:repository go_repository name=org_golang_x_sys importpath=golang.org/x/sys
# gazelle:repository go_repository name=org_golang_x_xerrors importpath=golang.org/x/xerrors
# 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_fsnotify_fsnotify importpath=github.com/fsnotify/fsnotify
# gazelle:repository go_repository name=com_github_pelletier_go_toml importpath=github.com/pelletier/go-toml
# gazelle:repository go_repository name=com_github_pmezard_go_difflib importpath=github.com/pmezard/go-difflib
# gazelle:repository go_repository name=com_github_bmatcuk_doublestar importpath=github.com/bmatcuk/doublestar
# gazelle:repository go_repository name=com_github_google_go_cmp importpath=github.com/google/go-cmp
24 changes: 12 additions & 12 deletions cmd/autogazelle/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

go_library(
name = "go_default_library",
name = "autogazelle_lib",
srcs = [
"autogazelle.go",
"client_unix.go",
Expand All @@ -11,42 +11,42 @@ go_library(
visibility = ["//visibility:private"],
deps = select({
"@io_bazel_rules_go//go/platform:android": [
"@com_github_fsnotify_fsnotify//:go_default_library",
"@com_github_fsnotify_fsnotify//:fsnotify",
],
"@io_bazel_rules_go//go/platform:darwin": [
"@com_github_fsnotify_fsnotify//:go_default_library",
"@com_github_fsnotify_fsnotify//:fsnotify",
],
"@io_bazel_rules_go//go/platform:dragonfly": [
"@com_github_fsnotify_fsnotify//:go_default_library",
"@com_github_fsnotify_fsnotify//:fsnotify",
],
"@io_bazel_rules_go//go/platform:freebsd": [
"@com_github_fsnotify_fsnotify//:go_default_library",
"@com_github_fsnotify_fsnotify//:fsnotify",
],
"@io_bazel_rules_go//go/platform:ios": [
"@com_github_fsnotify_fsnotify//:go_default_library",
"@com_github_fsnotify_fsnotify//:fsnotify",
],
"@io_bazel_rules_go//go/platform:linux": [
"@com_github_fsnotify_fsnotify//:go_default_library",
"@com_github_fsnotify_fsnotify//:fsnotify",
],
"@io_bazel_rules_go//go/platform:nacl": [
"@com_github_fsnotify_fsnotify//:go_default_library",
"@com_github_fsnotify_fsnotify//:fsnotify",
],
"@io_bazel_rules_go//go/platform:netbsd": [
"@com_github_fsnotify_fsnotify//:go_default_library",
"@com_github_fsnotify_fsnotify//:fsnotify",
],
"@io_bazel_rules_go//go/platform:openbsd": [
"@com_github_fsnotify_fsnotify//:go_default_library",
"@com_github_fsnotify_fsnotify//:fsnotify",
],
"@io_bazel_rules_go//go/platform:solaris": [
"@com_github_fsnotify_fsnotify//:go_default_library",
"@com_github_fsnotify_fsnotify//:fsnotify",
],
"//conditions:default": [],
}),
)

go_binary(
name = "autogazelle",
embed = [":go_default_library"],
embed = [":autogazelle_lib"],
visibility = ["//visibility:public"],
)

Expand Down
8 changes: 4 additions & 4 deletions cmd/fetch_repo/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")

go_library(
name = "go_default_library",
name = "fetch_repo_lib",
srcs = [
"fetch_repo.go",
"module.go",
Expand All @@ -14,14 +14,14 @@ go_library(

go_binary(
name = "fetch_repo",
embed = [":go_default_library"],
embed = [":fetch_repo_lib"],
visibility = ["//visibility:public"],
)

go_test(
name = "go_default_test",
name = "fetch_repo_test",
srcs = ["fetch_repo_test.go"],
embed = [":go_default_library"],
embed = [":fetch_repo_lib"],
deps = ["@org_golang_x_tools//go/vcs:go_default_library"],
)

Expand Down
38 changes: 19 additions & 19 deletions cmd/gazelle/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ gazelle_binary(
)

go_library(
name = "go_default_library",
name = "gazelle_lib",
# keep
srcs = [
"diff.go",
Expand All @@ -38,25 +38,25 @@ go_library(
tags = ["manual"],
visibility = ["//visibility:public"],
deps = [
"//config:go_default_library",
"//flag:go_default_library",
"//internal/wspace:go_default_library",
"//label:go_default_library",
"//language:go_default_library",
"//language/go:go_default_library",
"//language/proto:go_default_library",
"//merger:go_default_library",
"//repo:go_default_library",
"//resolve:go_default_library",
"//rule:go_default_library",
"//walk:go_default_library",
"//config",
"//flag",
"//internal/wspace",
"//label",
"//language",
"//language/go",
"//language/proto",
"//merger",
"//repo",
"//resolve",
"//rule",
"//walk",
"@com_github_bazelbuild_buildtools//build:go_default_library",
"@com_github_pmezard_go_difflib//difflib:go_default_library",
"@com_github_pmezard_go_difflib//difflib",
],
)

go_test(
name = "go_default_test",
name = "gazelle_test",
size = "small",
srcs = [
"diff_test.go",
Expand All @@ -66,11 +66,11 @@ go_test(
],
args = ["-go_sdk=go_sdk"],
data = ["@go_sdk//:files"],
embed = [":go_default_library"],
embed = [":gazelle_lib"],
deps = [
"//config:go_default_library",
"//internal/wspace:go_default_library",
"//testtools:go_default_library",
"//config",
"//internal/wspace",
"//testtools",
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
],
)
Expand Down
14 changes: 7 additions & 7 deletions cmd/generate_repo_config/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")

go_library(
name = "go_default_library",
name = "generate_repo_config_lib",
srcs = ["generate_repo_config.go"],
importpath = "github.com/bazelbuild/bazel-gazelle/cmd/generate_repo_config",
visibility = ["//visibility:private"],
deps = [
"//repo:go_default_library",
"//rule:go_default_library",
"//repo",
"//rule",
],
)

go_binary(
name = "generate_repo_config",
embed = [":go_default_library"],
embed = [":generate_repo_config_lib"],
visibility = ["//visibility:public"],
)

go_test(
name = "go_default_test",
name = "generate_repo_config_test",
srcs = ["generate_repo_config_test.go"],
embed = [":go_default_library"],
deps = ["//testtools:go_default_library"],
embed = [":generate_repo_config_lib"],
deps = ["//testtools"],
)

filegroup(
Expand Down
16 changes: 8 additions & 8 deletions cmd/move_labels/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")

go_library(
name = "go_default_library",
name = "move_labels_lib",
srcs = ["move_labels.go"],
importpath = "github.com/bazelbuild/bazel-gazelle/cmd/move_labels",
visibility = ["//visibility:private"],
deps = [
"//internal/wspace:go_default_library",
"//label:go_default_library",
"//pathtools:go_default_library",
"//internal/wspace",
"//label",
"//pathtools",
"@com_github_bazelbuild_buildtools//build:go_default_library",
],
)

go_binary(
name = "move_labels",
embed = [":go_default_library"],
embed = [":move_labels_lib"],
visibility = ["//visibility:public"],
)

go_test(
name = "go_default_test",
name = "move_labels_test",
srcs = ["move_labels_test.go"],
embed = [":go_default_library"],
deps = ["//testtools:go_default_library"],
embed = [":move_labels_lib"],
deps = ["//testtools"],
)

filegroup(
Expand Down
18 changes: 12 additions & 6 deletions config/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "go_default_library",
name = "config",
srcs = [
"config.go",
"constants.go",
],
importpath = "github.com/bazelbuild/bazel-gazelle/config",
visibility = ["//visibility:public"],
deps = [
"//internal/wspace:go_default_library",
"//rule:go_default_library",
"//internal/wspace",
"//rule",
],
)

go_test(
name = "go_default_test",
name = "config_test",
srcs = ["config_test.go"],
embed = [":go_default_library"],
deps = ["//rule:go_default_library"],
embed = [":config"],
deps = ["//rule"],
)

filegroup(
Expand All @@ -32,3 +32,9 @@ filegroup(
],
visibility = ["//visibility:public"],
)

alias(
name = "go_default_library",
actual = ":config",
visibility = ["//visibility:public"],
)
9 changes: 1 addition & 8 deletions deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ load(
"@bazel_gazelle//internal:go_repository_config.bzl",
"go_repository_config",
)
load(
"@bazel_gazelle//internal:overlay_repository.bzl",
# Load overlay git_repository and http_archive in order to re-export.
# These may be removed at some point in the future.
"git_repository",
"http_archive",
)
load(
"@bazel_tools//tools/build_defs/repo:git.bzl",
_tools_git_repository = "git_repository",
Expand Down Expand Up @@ -152,7 +145,7 @@ def gazelle_dependencies(

_maybe(
go_repository,
name = "com_github_google_go_cmp",
name = "org_golang_x_xerrors",
importpath = "golang.org/x/xerrors",
sum = "h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=",
version = "v0.0.0-20191204190536-9bdfabe68543",
Expand Down
8 changes: 7 additions & 1 deletion flag/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
name = "flag",
srcs = ["flag.go"],
importpath = "github.com/bazelbuild/bazel-gazelle/flag",
visibility = ["//visibility:public"],
Expand All @@ -16,3 +16,9 @@ filegroup(
],
visibility = ["//visibility:public"],
)

alias(
name = "go_default_library",
actual = ":flag",
visibility = ["//visibility:public"],
)
2 changes: 1 addition & 1 deletion internal/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ load("@io_bazel_rules_go//go/tools/bazel_testing:def.bzl", "go_bazel_test")
go_bazel_test(
name = "go_repository_test",
srcs = ["go_repository_test.go"],
deps = ["//testtools:go_default_library"],
rule_files = [
"@bazel_gazelle//:all_files",
"@io_bazel_rules_go//:all_files",
],
deps = ["//testtools"],
)

# TODO(jayconrod): test fetch_repo error cases.
Expand Down
7 changes: 1 addition & 6 deletions internal/gazelle_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ load(
"GoArchive",
"go_context",
)
load(
"@io_bazel_rules_go//go/platform:list.bzl",
"GOARCH",
"GOOS",
)
load(
"@io_bazel_rules_go//go/private:rules/transition.bzl",
"go_transition_rule",
Expand Down Expand Up @@ -95,7 +90,7 @@ _gazelle_binary_kwargs = {
),
"_go_context_data": attr.label(default = "@io_bazel_rules_go//:go_context_data"),
"_srcs": attr.label(
default = "//cmd/gazelle:go_default_library",
default = "//cmd/gazelle:gazelle_lib",
),
},
"executable": True,
Expand Down
Loading

0 comments on commit 570264c

Please sign in to comment.