Skip to content

Commit

Permalink
Create bzl_library entries using gazelle-skylark
Browse files Browse the repository at this point in the history
There are a few minor manual modifications that needed to be performed.
For example, some `.bzl` files depend on `.bzl` files that are generated
outside of this repo and do not presently exist. `@bazel_tools` is a
great example of this.

Additionally this effort has revealed that bazel gazelle has an explicit
dependency on the private parts of rules_go in
internal/gazelle_binary.bzl on line 21 where it imports from
`go/private:rules/transitions.bzl` which is no longer the path to import
from once I created the BUILD file in `go/private/rules`.

As a temporary fix for this, I'm included a patch that changes that to
point to the new path. I will provide a follow up patch once rules_go
has been released to fix it properly in the gazelle repo and then remove
the patch from rules_go.

Fixed: bazel-contrib#2619
Bug: bazelbuild/bazel-skylib#250
Bug: bazel-contrib/bazel-gazelle#803
Co-authored-by: Andreas Herrmann <[email protected]>
  • Loading branch information
achew22 and aherrmann committed Aug 27, 2020
1 parent 384d290 commit 8e545b0
Show file tree
Hide file tree
Showing 44 changed files with 598 additions and 59 deletions.
8 changes: 4 additions & 4 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
load(
"@io_bazel_rules_go//go/private:tools/lines_sorted_test.bzl",
"@io_bazel_rules_go//go/private/tools:lines_sorted_test.bzl",
"lines_sorted_test",
)
load(
"@io_bazel_rules_go//go/private:rules/nogo.bzl",
"@io_bazel_rules_go//go/private/rules:nogo.bzl",
"nogo",
)
load(
"@io_bazel_rules_go//go/private:rules/info.bzl",
"@io_bazel_rules_go//go/private/rules:info.bzl",
"go_info",
)
load(
Expand All @@ -22,7 +22,7 @@ load(
"go_context_data",
)
load(
"@io_bazel_rules_go//go/private:rules/stdlib.bzl",
"@io_bazel_rules_go//go/private/rules:stdlib.bzl",
"stdlib",
)

Expand Down
3 changes: 3 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ bazel_skylib_workspace()

http_archive(
name = "bazel_gazelle",
patches = [
"//third_party:com_google_github_bazel_gazelle-internal-in-their-new-location.patch",
],
sha256 = "d8c45ee70ec39a57e7a05e5027c32b1576cc7f16d9dd37135b0eddde45cf1b10",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.20.0/bazel-gazelle-v0.20.0.tar.gz",
Expand Down
31 changes: 31 additions & 0 deletions extras/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

filegroup(
name = "all_rules",
srcs = glob(["*.bzl"]) + ["//go/private:all_rules"],
Expand All @@ -10,3 +12,32 @@ filegroup(
srcs = glob(["**"]),
visibility = ["//visibility:public"],
)

bzl_library(
name = "bindata",
srcs = ["bindata.bzl"],
visibility = ["//visibility:public"],
deps = [
"@io_bazel_rules_go//go:def",
"@io_bazel_rules_go//go/private/rules:rule",
],
)

bzl_library(
name = "embed_data",
srcs = ["embed_data.bzl"],
visibility = ["//visibility:public"],
deps = [
"@io_bazel_rules_go//go/private:context",
"@io_bazel_rules_go//go/private/rules:rule",
],
)

bzl_library(
name = "embed_data_deps",
srcs = ["embed_data_deps.bzl"],
visibility = ["//visibility:public"],
deps = [
#"@bazel_tools//tools/build_defs/repo:git",
],
)
2 changes: 1 addition & 1 deletion extras/bindata.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ load(
"go_context",
)
load(
"@io_bazel_rules_go//go/private:rules/rule.bzl",
"@io_bazel_rules_go//go/private/rules:rule.bzl",
"go_rule",
)

Expand Down
2 changes: 1 addition & 1 deletion extras/embed_data.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ load(
"go_context",
)
load(
"@io_bazel_rules_go//go/private:rules/rule.bzl",
"@io_bazel_rules_go//go/private/rules:rule.bzl",
"go_rule",
)

Expand Down
31 changes: 31 additions & 0 deletions go/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

filegroup(
name = "all_files",
testonly = True,
Expand Down Expand Up @@ -25,3 +27,32 @@ toolchain_type(
name = "toolchain",
visibility = ["//visibility:public"],
)

bzl_library(
name = "def",
srcs = ["def.bzl"],
visibility = ["//visibility:public"],
deps = [
"@io_bazel_rules_go//extras:embed_data",
"@io_bazel_rules_go//go/private:context",
"@io_bazel_rules_go//go/private:go_toolchain",
"@io_bazel_rules_go//go/private:providers",
"@io_bazel_rules_go//go/private/rules:library",
"@io_bazel_rules_go//go/private/rules:nogo",
"@io_bazel_rules_go//go/private/rules:rule",
"@io_bazel_rules_go//go/private/rules:sdk",
"@io_bazel_rules_go//go/private/rules:source",
"@io_bazel_rules_go//go/private/rules:wrappers",
"@io_bazel_rules_go//go/private/tools:path",
],
)

bzl_library(
name = "deps",
srcs = ["deps.bzl"],
visibility = ["//visibility:public"],
deps = [
"@io_bazel_rules_go//go/private:repositories",
"@io_bazel_rules_go//go/private:sdk",
],
)
14 changes: 7 additions & 7 deletions go/def.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ load(
_GoSource = "GoSource",
)
load(
"@io_bazel_rules_go//go/private:rules/sdk.bzl",
"@io_bazel_rules_go//go/private/rules:sdk.bzl",
_go_sdk = "go_sdk",
)
load(
Expand All @@ -45,33 +45,33 @@ load(
_go_toolchain = "go_toolchain",
)
load(
"@io_bazel_rules_go//go/private:rules/wrappers.bzl",
"@io_bazel_rules_go//go/private/rules:wrappers.bzl",
_go_binary_macro = "go_binary_macro",
_go_library_macro = "go_library_macro",
_go_test_macro = "go_test_macro",
)
load(
"@io_bazel_rules_go//go/private:rules/source.bzl",
"@io_bazel_rules_go//go/private/rules:source.bzl",
_go_source = "go_source",
)
load(
"@io_bazel_rules_go//extras:embed_data.bzl",
_go_embed_data = "go_embed_data",
)
load(
"@io_bazel_rules_go//go/private:tools/path.bzl",
"@io_bazel_rules_go//go/private/tools:path.bzl",
_go_path = "go_path",
)
load(
"@io_bazel_rules_go//go/private:rules/rule.bzl",
"@io_bazel_rules_go//go/private/rules:rule.bzl",
_go_rule = "go_rule",
)
load(
"@io_bazel_rules_go//go/private:rules/library.bzl",
"@io_bazel_rules_go//go/private/rules:library.bzl",
_go_tool_library = "go_tool_library",
)
load(
"@io_bazel_rules_go//go/private:rules/nogo.bzl",
"@io_bazel_rules_go//go/private/rules:nogo.bzl",
_nogo = "nogo_wrapper",
)

Expand Down
13 changes: 13 additions & 0 deletions go/platform/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

# This file declares a config_setting for each platform supported by the
# Go SDK. These rules follow a goos_goarch naming convention, for example,
# //go/platform:linux_amd64
Expand All @@ -23,3 +25,14 @@ filegroup(
srcs = glob(["**"]),
visibility = ["//visibility:public"],
)

bzl_library(
name = "list",
srcs = ["list.bzl"],
deps = ["@io_bazel_rules_go//go/private:platforms"],
)

bzl_library(
name = "apple",
srcs = ["apple.bzl"],
)
102 changes: 102 additions & 0 deletions go/private/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

filegroup(
name = "all_rules",
srcs = glob(["**/*.bzl"]),
Expand Down Expand Up @@ -30,3 +32,103 @@ config_setting(
name = "stamp",
values = {"stamp": "true"},
)

bzl_library(
name = "context",
srcs = ["context.bzl"],
visibility = [
"//extras:__pkg__",
"//go:__subpackages__",
],
deps = [
"@bazel_skylib//lib:paths",
"@bazel_skylib//rules:common_settings",
#"@bazel_tools//tools/build_defs/cc:action_names",
#"@bazel_tools//tools/cpp:toolchain_utils",
"@io_bazel_rules_go//go/platform:apple",
],
)

bzl_library(
name = "go_toolchain",
srcs = ["go_toolchain.bzl"],
visibility = ["//go:__subpackages__"],
deps = [
"@io_bazel_rules_go//go/private:platforms",
"@io_bazel_rules_go//go/private:providers",
"@io_bazel_rules_go//go/private/actions:archive",
"@io_bazel_rules_go//go/private/actions:asm",
"@io_bazel_rules_go//go/private/actions:binary",
"@io_bazel_rules_go//go/private/actions:compile",
"@io_bazel_rules_go//go/private/actions:cover",
"@io_bazel_rules_go//go/private/actions:link",
"@io_bazel_rules_go//go/private/actions:pack",
"@io_bazel_rules_go//go/private/actions:stdlib",
],
)

bzl_library(
name = "repositories",
srcs = ["repositories.bzl"],
visibility = ["//go:__subpackages__"],
deps = [
#"@bazel_tools//tools/build_defs/repo:git",
#"@bazel_tools//tools/build_defs/repo:http",
"@io_bazel_rules_go//go/private:common",
"@io_bazel_rules_go//go/private:nogo",
"@io_bazel_rules_go//go/private/skylib/lib:versions",
"@io_bazel_rules_go//proto:gogo",
],
)

bzl_library(
name = "sdk",
srcs = ["sdk.bzl"],
visibility = ["//go:__subpackages__"],
deps = [
"@io_bazel_rules_go//go/private:common",
"@io_bazel_rules_go//go/private:nogo",
"@io_bazel_rules_go//go/private:platforms",
"@io_bazel_rules_go//go/private:sdk_list",
"@io_bazel_rules_go//go/private/skylib/lib:versions",
],
)

bzl_library(
name = "common",
srcs = ["common.bzl"],
visibility = ["//go:__subpackages__"],
)

bzl_library(
name = "mode",
srcs = ["mode.bzl"],
visibility = ["//go:__subpackages__"],
)

bzl_library(
name = "nogo",
srcs = ["nogo.bzl"],
visibility = ["//go:__subpackages__"],
)

bzl_library(
name = "platforms",
srcs = ["platforms.bzl"],
visibility = ["//go:__subpackages__"],
)

bzl_library(
name = "providers",
srcs = ["providers.bzl"],
visibility = [
"//go:__subpackages__",
"//proto:__pkg__", # keep
],
)

bzl_library(
name = "sdk_list",
srcs = ["sdk_list.bzl"],
visibility = ["//go:__subpackages__"],
)
4 changes: 2 additions & 2 deletions go/private/BUILD.sdk.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@io_bazel_rules_go//go/private:rules/binary.bzl", "go_tool_binary")
load("@io_bazel_rules_go//go/private:rules/sdk.bzl", "package_list")
load("@io_bazel_rules_go//go/private/rules:binary.bzl", "go_tool_binary")
load("@io_bazel_rules_go//go/private/rules:sdk.bzl", "package_list")
load("@io_bazel_rules_go//go:def.bzl", "declare_toolchains", "go_sdk")

package(default_visibility = ["//visibility:public"])
Expand Down
Loading

0 comments on commit 8e545b0

Please sign in to comment.