Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

language/go: merge new Go naming convention to master #863

Merged
merged 9 commits into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
35 changes: 35 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,17 @@ The following flags are accepted:
| See `Predefined plugins`_ for available options; commonly used options include |
| ``@io_bazel_rules_go//proto:gofast_grpc`` and ``@io_bazel_rules_go//proto:gogofaster_grpc``. |
+--------------------------------------------------------------+----------------------------------------+
| :flag:`-go_naming_convention` | |
+--------------------------------------------------------------+----------------------------------------+
| Controls the names of generated Go targets. Equivalent to the |
| ``# gazelle:go_naming_convention`` directive. |
+--------------------------------------------------------------+----------------------------------------+
| :flag:`-go_naming_convention_extern` | |
+--------------------------------------------------------------+----------------------------------------+
| Controls the default naming convention used when resolving libraries in |
| external repositories with unknown naming conventions. Equivalent to the |
| ``# gazelle:go_naming_convention_extern`` directive. |
+--------------------------------------------------------------+----------------------------------------+
| :flag:`-go_prefix example.com/repo` | |
+--------------------------------------------------------------+----------------------------------------+
| A prefix of import paths for libraries in the repository that corresponds to |
Expand Down Expand Up @@ -576,6 +587,30 @@ The following directives are recognized:
| ``@io_bazel_rules_go//proto:gofast_grpc`` and |
| ``@io_bazel_rules_go//proto:gogofaster_grpc``. |
+---------------------------------------------------+----------------------------------------+
| :direc:`# gazelle:go_naming_convention` | n/a |
+---------------------------------------------------+----------------------------------------+
| Controls the names of generated Go targets. By default, library targets are named |
| ``go_default_library`` and test targets ``go_default_test``. |
| |
| Valid values are: |
| |
| * ``go_default_library``: Library targets are named ``go_default_library``, test targets |
| are named ``go_default_test``. |
| * ``import``: Library and test targets are named after the last segment of their import |
| path. |
| For example, ``example.repo/foo`` is named ``foo``, and the test target is ``foo_test``. |
| Major version suffixes like ``/v2`` are dropped. |
| For a main package with a binary ``foobin``, the names are instead ``foobin_lib`` and |
| ``foobin_test``. |
| * ``import_alias``: Same as ``import``, but an ``alias`` target is generated named |
| ``go_default_library`` to ensure backwards compatibility. |
+---------------------------------------------------+----------------------------------------+
| :direc:`# gazelle:go_naming_convention_extern` | n/a |
+---------------------------------------------------+----------------------------------------+
| Controls the default naming convention used when resolving libraries in |
| external repositories with unknown naming conventions. Accepts the same values |
| as ``go_naming_convention``. |
+---------------------------------------------------+----------------------------------------+
| :direc:`# gazelle:go_proto_compilers` | ``@io_bazel_rules_go//proto:go_proto`` |
+---------------------------------------------------+----------------------------------------+
| The protocol buffers compiler(s) to use for building go bindings. |
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
6 changes: 3 additions & 3 deletions cmd/gazelle/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestDiffExisting(t *testing.T) {
# gazelle:prefix example.com/hello

+go_library(
+ name = "go_default_library",
+ name = "hello",
+ srcs = ["hello.go"],
+ importpath = "example.com/hello",
+ visibility = ["//visibility:public"],
Expand Down Expand Up @@ -91,7 +91,7 @@ func TestDiffNew(t *testing.T) {
+load("@io_bazel_rules_go//go:def.bzl", "go_library")
+
+go_library(
+ name = "go_default_library",
+ name = "hello",
+ srcs = ["hello.go"],
+ importpath = "example.com/hello",
+ visibility = ["//visibility:public"],
Expand Down Expand Up @@ -138,7 +138,7 @@ func TestDiffReadWriteDir(t *testing.T) {
# gazelle:prefix example.com/hello
+
+go_library(
+ name = "go_default_library",
+ name = "hello",
+ srcs = ["hello.go"],
+ importpath = "example.com/hello",
+ visibility = ["//visibility:public"],
Expand Down
12 changes: 6 additions & 6 deletions cmd/gazelle/fix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,13 @@ load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

go_binary(
name = "hello",
embed = [":go_default_library"],
embed = [":repo_lib"],
pure = "on",
visibility = ["//visibility:public"],
)

go_library(
name = "go_default_library",
name = "repo_lib",
srcs = ["hello.go"],
importpath = "example.com/repo",
visibility = ["//visibility:private"],
Expand Down Expand Up @@ -291,15 +291,15 @@ load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
# src build file

go_library(
name = "go_default_library",
name = "repo_lib",
srcs = ["hello.go"],
importpath = "example.com/repo",
visibility = ["//visibility:private"],
)

go_binary(
name = "repo",
embed = [":go_default_library"],
embed = [":repo_lib"],
visibility = ["//visibility:public"],
)
`,
Expand All @@ -324,13 +324,13 @@ load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

go_binary(
name = "hello",
embed = [":go_default_library"],
embed = [":repo_lib"],
pure = "on",
visibility = ["//visibility:public"],
)

go_library(
name = "go_default_library",
name = "repo_lib",
srcs = ["hello.go"],
importpath = "example.com/repo",
visibility = ["//visibility:private"],
Expand Down
Loading