From d51d2da67ad18412555bf9e96a693ad8dce71932 Mon Sep 17 00:00:00 2001 From: Nikolaos Georgiou Date: Thu, 12 Aug 2021 09:07:42 +0000 Subject: [PATCH 1/4] Export bzl files with bzl_library to be able to use stardoc Stardoc is a documentation tool for Bazel rules/macros/etc. We need to group the bzl files of bazel-gazelle into bzl_library targets so that stardoc can pick them up. --- BUILD.bazel | 8 ++++++++ internal/BUILD.bazel | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/BUILD.bazel b/BUILD.bazel index 92664dd7e..a9d9c348e 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,4 +1,5 @@ load("@io_bazel_rules_go//go:def.bzl", "nogo") +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("//:def.bzl", "gazelle", "gazelle_binary") # gazelle:prefix github.com/bazelbuild/bazel-gazelle @@ -71,3 +72,10 @@ filegroup( ], visibility = ["//visibility:public"], ) + +# needed for stardoc +bzl_library( + name = "lib", + srcs = glob(["*.bzl"]), + visibility = ["//visibility:public"], +) diff --git a/internal/BUILD.bazel b/internal/BUILD.bazel index c92e1be7b..fd4f85880 100644 --- a/internal/BUILD.bazel +++ b/internal/BUILD.bazel @@ -1,4 +1,5 @@ load("@io_bazel_rules_go//go/tools/bazel_testing:def.bzl", "go_bazel_test") +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") # gazelle:exclude *_test.go go_bazel_test( @@ -47,3 +48,10 @@ filegroup( ], visibility = ["//visibility:public"], ) + +# needed for stardoc +bzl_library( + name = "internal", + srcs = glob(["*.bzl"]), + visibility = ["//visibility:public"], +) From 523d49e5d0e7a847781753db6794b95865f50b7f Mon Sep 17 00:00:00 2001 From: Nikolaos Georgiou Date: Wed, 18 Aug 2021 06:47:02 +0000 Subject: [PATCH 2/4] trying to add gazelle/bzl language --- BUILD.bazel | 1 + deps.bzl | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/BUILD.bazel b/BUILD.bazel index a9d9c348e..4bbd29a7a 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -22,6 +22,7 @@ gazelle_binary( "//language/proto", "//language/go", "//internal/language/test_filegroup", + "@bazel_skylib//gazelle/bzl" ], ) diff --git a/deps.bzl b/deps.bzl index 6acddd400..6d38f49d7 100644 --- a/deps.bzl +++ b/deps.bzl @@ -79,7 +79,7 @@ def gazelle_dependencies( _tools_git_repository, name = "bazel_skylib", remote = "https://github.com/bazelbuild/bazel-skylib", - commit = "3fea8cb680f4a53a129f7ebace1a5a4d1e035914", # 0.5.0 as of 2018-11-01 + tag = "1.0.3" ) _maybe( From c9ef4cda29f84a63e5c751a10749ec56036fa36b Mon Sep 17 00:00:00 2001 From: Nikolaos Georgiou Date: Thu, 19 Aug 2021 07:35:39 +0000 Subject: [PATCH 3/4] Move skylib definition into WORKSPACE Generate skylib targets with gazelle --- BUILD.bazel | 26 ++++++++++++--- WORKSPACE | 10 ++++++ deps.bzl | 7 ---- internal/BUILD.bazel | 59 +++++++++++++++++++++++++++++++--- language/go/BUILD.bazel | 8 +++++ language/proto/gen/BUILD.bazel | 7 ++++ 6 files changed, 102 insertions(+), 15 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 4bbd29a7a..11ce4daed 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -22,7 +22,7 @@ gazelle_binary( "//language/proto", "//language/go", "//internal/language/test_filegroup", - "@bazel_skylib//gazelle/bzl" + "@bazel_skylib//gazelle/bzl", ], ) @@ -74,9 +74,27 @@ filegroup( visibility = ["//visibility:public"], ) -# needed for stardoc bzl_library( - name = "lib", - srcs = glob(["*.bzl"]), + name = "def", + srcs = ["def.bzl"], visibility = ["//visibility:public"], + deps = [ + "//internal:gazelle_binary", + "//internal:go_repository", + "//internal:overlay_repository", + "@bazel_skylib//lib:shell", + ], +) + +bzl_library( + name = "deps", + srcs = ["deps.bzl"], + visibility = ["//visibility:public"], + deps = [ + "@bazel_gazelle//internal:go_repository", + "@bazel_gazelle//internal:go_repository_cache", + "@bazel_gazelle//internal:go_repository_config", + "@bazel_gazelle//internal:go_repository_tools", + "@bazel_tools//tools/build_defs/repo:git.bzl", + ], ) diff --git a/WORKSPACE b/WORKSPACE index 916dca22a..61b4deeef 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,6 +1,16 @@ workspace(name = "bazel_gazelle") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load( + "@bazel_tools//tools/build_defs/repo:git.bzl", + "git_repository", +) + +git_repository( + name = "bazel_skylib", + commit = "df3c9e2735f02a7fe8cd80db4db00fec8e13d25f", # `master` as of 2021-08-19 + remote = "https://github.com/bazelbuild/bazel-skylib", +) http_archive( name = "io_bazel_rules_go", diff --git a/deps.bzl b/deps.bzl index 6d38f49d7..b50429f2d 100644 --- a/deps.bzl +++ b/deps.bzl @@ -75,13 +75,6 @@ def gazelle_dependencies( config = go_repository_default_config, ) - _maybe( - _tools_git_repository, - name = "bazel_skylib", - remote = "https://github.com/bazelbuild/bazel-skylib", - tag = "1.0.3" - ) - _maybe( go_repository, name = "com_github_bazelbuild_buildtools", diff --git a/internal/BUILD.bazel b/internal/BUILD.bazel index fd4f85880..343e0d63e 100644 --- a/internal/BUILD.bazel +++ b/internal/BUILD.bazel @@ -49,9 +49,60 @@ filegroup( visibility = ["//visibility:public"], ) -# needed for stardoc bzl_library( - name = "internal", - srcs = glob(["*.bzl"]), - visibility = ["//visibility:public"], + name = "gazelle_binary", + srcs = ["gazelle_binary.bzl"], + visibility = ["//:__subpackages__"], + deps = ["@io_bazel_rules_go//go:def"], +) + +bzl_library( + name = "go_repository", + srcs = ["go_repository.bzl"], + visibility = ["//:__subpackages__"], + deps = [ + "@bazel_gazelle//internal:go_repository_cache", + "@bazel_tools//tools/build_defs/repo:utils.bzl", + "@io_bazel_rules_go//go/private:common", + ], +) + +bzl_library( + name = "go_repository_cache", + srcs = ["go_repository_cache.bzl"], + visibility = ["//:__subpackages__"], + deps = ["@io_bazel_rules_go//go/private:common"], +) + +bzl_library( + name = "go_repository_config", + srcs = ["go_repository_config.bzl"], + visibility = ["//:__subpackages__"], + deps = [ + "@bazel_gazelle//internal:go_repository_cache", + "@io_bazel_rules_go//go/private:common", + ], +) + +bzl_library( + name = "go_repository_tools", + srcs = ["go_repository_tools.bzl"], + visibility = ["//:__subpackages__"], + deps = [ + "@bazel_gazelle//internal:go_repository_cache", + "@bazel_gazelle//internal:go_repository_tools_srcs", + "@io_bazel_rules_go//go/private:common", + ], +) + +bzl_library( + name = "go_repository_tools_srcs", + srcs = ["go_repository_tools_srcs.bzl"], + visibility = ["//:__subpackages__"], +) + +bzl_library( + name = "overlay_repository", + srcs = ["overlay_repository.bzl"], + visibility = ["//:__subpackages__"], ) diff --git a/language/go/BUILD.bazel b/language/go/BUILD.bazel index 44214c862..3e8b311c6 100644 --- a/language/go/BUILD.bazel +++ b/language/go/BUILD.bazel @@ -1,3 +1,4 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") load(":def.bzl", "std_package_list") @@ -120,3 +121,10 @@ alias( actual = ":go", visibility = ["//visibility:public"], ) + +bzl_library( + name = "def", + srcs = ["def.bzl"], + visibility = ["//visibility:public"], + deps = ["@io_bazel_rules_go//go:def"], +) diff --git a/language/proto/gen/BUILD.bazel b/language/proto/gen/BUILD.bazel index b334f9dcf..3e5e6b397 100644 --- a/language/proto/gen/BUILD.bazel +++ b/language/proto/gen/BUILD.bazel @@ -1,3 +1,4 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") go_library( @@ -25,3 +26,9 @@ filegroup( ], visibility = ["//visibility:public"], ) + +bzl_library( + name = "def", + srcs = ["def.bzl"], + visibility = ["//visibility:public"], +) From 658bd6d88522b6e915ecccaa10bada8a37cdcbbf Mon Sep 17 00:00:00 2001 From: Nikolaos Georgiou Date: Thu, 19 Aug 2021 08:06:33 +0000 Subject: [PATCH 4/4] manually removed some private deps added by gazelle/skylib plugin --- internal/BUILD.bazel | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/internal/BUILD.bazel b/internal/BUILD.bazel index 343e0d63e..de1eaec2d 100644 --- a/internal/BUILD.bazel +++ b/internal/BUILD.bazel @@ -63,7 +63,6 @@ bzl_library( deps = [ "@bazel_gazelle//internal:go_repository_cache", "@bazel_tools//tools/build_defs/repo:utils.bzl", - "@io_bazel_rules_go//go/private:common", ], ) @@ -71,7 +70,7 @@ bzl_library( name = "go_repository_cache", srcs = ["go_repository_cache.bzl"], visibility = ["//:__subpackages__"], - deps = ["@io_bazel_rules_go//go/private:common"], + deps = [], ) bzl_library( @@ -80,7 +79,6 @@ bzl_library( visibility = ["//:__subpackages__"], deps = [ "@bazel_gazelle//internal:go_repository_cache", - "@io_bazel_rules_go//go/private:common", ], ) @@ -91,7 +89,6 @@ bzl_library( deps = [ "@bazel_gazelle//internal:go_repository_cache", "@bazel_gazelle//internal:go_repository_tools_srcs", - "@io_bazel_rules_go//go/private:common", ], )