-
Notifications
You must be signed in to change notification settings - Fork 181
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
Add the gazelle plugin to the distribution #400
Changes from 10 commits
a0b4be3
4f269cd
87394f2
1ed8cad
e96655b
962eebd
242167e
b5938b5
4bf6c88
1d56cbe
d3acf47
4a5457e
73bf9bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,22 +2,22 @@ workspace(name = "bazel_skylib") | |
|
||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") | ||
load(":workspace.bzl", "bazel_skylib_workspace") | ||
|
||
maybe( | ||
name = "io_bazel_rules_go", | ||
repo_rule = http_archive, | ||
sha256 = "685052b498b6ddfe562ca7a97736741d87916fe536623afb7da2824c0211c369", | ||
urls = [ | ||
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.33.0/rules_go-v0.33.0.zip", | ||
"https://github.com/bazelbuild/rules_go/releases/download/v0.33.0/rules_go-v0.33.0.zip", | ||
], | ||
bazel_skylib_workspace() | ||
|
||
local_repository( | ||
name = "bazel_skylib_gazelle_plugin", | ||
path = "gazelle", | ||
) | ||
|
||
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") | ||
load("@bazel_skylib_gazelle_plugin//:workspace.bzl", "bazel_skylib_gazelle_plugin_workspace") | ||
|
||
bazel_skylib_gazelle_plugin_workspace() | ||
|
||
go_rules_dependencies() | ||
load("@bazel_skylib_gazelle_plugin//:setup.bzl", "bazel_skylib_gazelle_plugin_setup") | ||
|
||
go_register_toolchains(version = "1.17.1") | ||
bazel_skylib_gazelle_plugin_setup() | ||
|
||
# Below this line is for documentation generation only, | ||
# and should thus not be included by dependencies on | ||
|
@@ -69,17 +69,5 @@ register_unittest_toolchains() | |
# github.com/bazelbuild/rules_go is available from io_bazel_rules_go and it | ||
# doesn't need to duplicatively fetch it. | ||
# gazelle:repository go_repository name=io_bazel_rules_go importpath=github.com/bazelbuild/rules_go | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not familiar with gazelle repository hints, do these need to be moved to gazelee/WORKSPACE? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've moved them, and everything still seems to build. Apparently, it's fine to move them. |
||
http_archive( | ||
name = "bazel_gazelle", | ||
sha256 = "de69a09dc70417580aabf20a28619bb3ef60d038470c7cf8442fafcf627c21cb", | ||
urls = [ | ||
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.24.0/bazel-gazelle-v0.24.0.tar.gz", | ||
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.24.0/bazel-gazelle-v0.24.0.tar.gz", | ||
], | ||
) | ||
# Another Gazelle repository hint. | ||
# gazelle:repository go_repository name=bazel_gazelle importpath=github.com/bazelbuild/bazel-gazelle/testtools | ||
|
||
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") | ||
|
||
gazelle_dependencies() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
load("@bazel_skylib//:bzl_library.bzl", "bzl_library") | ||
|
||
# The files needed for distribution | ||
filegroup( | ||
name = "distribution", | ||
srcs = glob( | ||
["*"], | ||
allow_empty = True, | ||
), | ||
visibility = [ | ||
"//:__pkg__", | ||
], | ||
) | ||
|
||
bzl_library( | ||
name = "setup", | ||
srcs = ["setup.bzl"], | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"@bazel_gazelle//:deps", | ||
"@io_bazel_rules_go//go:deps", | ||
], | ||
) | ||
|
||
bzl_library( | ||
name = "workspace", | ||
srcs = ["workspace.bzl"], | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"@bazel_skylib//:workspace", | ||
"@bazel_tools//tools/build_defs/repo:http.bzl", | ||
"@bazel_tools//tools/build_defs/repo:utils.bzl", | ||
], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
bazel_dep(name = "bazel_skylib", version = "1.3.0") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
bazel_dep(name = "gazelle", repo_name = "bazel_gazelle", version = "0.28.0") | ||
bazel_dep(name = "rules_go", repo_name = "io_bazel_rules_go", version = "0.35.0") | ||
|
||
go_sdk = use_extension("@io_bazel_rules_go//go:extensions.bzl", "go_sdk") | ||
|
||
go_sdk.download( | ||
name = "go_sdk", | ||
version = "1.18", | ||
) | ||
|
||
use_repo(go_sdk, "go_sdk") | ||
|
||
register_toolchains("@go_sdk//:all") | ||
|
||
go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps") | ||
|
||
go_deps.module( | ||
path = "github.com/bazelbuild/buildtools", | ||
sum = "h1:fmdo+fvvWlhldUcqkhAMpKndSxMN3vH5l7yow5cEaiQ=", | ||
version = "v0.0.0-20220531122519-a43aed7014c8", | ||
) | ||
|
||
use_repo(go_deps, "com_github_bazelbuild_buildtools") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
workspace(name = "bazel_skylib_gazelle_plugin") | ||
|
||
local_repository( | ||
name = "bazel_skylib", | ||
path = "..", | ||
) | ||
|
||
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") | ||
|
||
bazel_skylib_workspace() | ||
|
||
load(":workspace.bzl", "bazel_skylib_gazelle_plugin_workspace") | ||
|
||
bazel_skylib_gazelle_plugin_workspace() | ||
|
||
load(":setup.bzl", "bazel_skylib_gazelle_plugin_setup") | ||
|
||
bazel_skylib_gazelle_plugin_setup() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
workspace(name = "bazel_skylib_gazelle_plugin") |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,3 +51,25 @@ gazelle( | |
name = "gazelle", | ||
gazelle = ":gazelle-skylib", | ||
) | ||
|
||
# The files needed for distribution | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the docs, |
||
# A fake testdata directory is created so that | ||
# the build file has nothing missing, but we | ||
# do not bloat the distribution tarball | ||
filegroup( | ||
name = "distribution", | ||
srcs = glob(["*.go"]) + [ | ||
"BUILD", | ||
":fake-testdata", | ||
], | ||
visibility = [ | ||
"//:__pkg__", | ||
"//distribution:__pkg__", | ||
], | ||
) | ||
|
||
genrule( | ||
name = "fake-testdata", | ||
outs = ["testdata"], | ||
cmd = "touch $@", | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright 2019 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Dependency registration helpers for the gazelle plugin.""" | ||
|
||
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") | ||
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") | ||
|
||
def bazel_skylib_gazelle_plugin_setup(go_version = "1.18.7", register_go_toolchains = True): | ||
"""Set up the dependencies needed by the Gazelle plugin. | ||
|
||
Args: | ||
go_version: The version of Go registered as part of the build as a string | ||
register_go_toolchains: A boolean indicating whether or not to register the Go toolchains. Defaults to `True` | ||
""" | ||
go_rules_dependencies() | ||
|
||
if register_go_toolchains: | ||
go_register_toolchains(version = go_version) | ||
|
||
gazelle_dependencies() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright 2019 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") | ||
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") | ||
|
||
def bazel_skylib_gazelle_plugin_workspace(): | ||
"""Loads dependencies required to use skylib's gazelle plugin""" | ||
bazel_skylib_workspace() | ||
|
||
maybe( | ||
http_archive, | ||
name = "io_bazel_rules_go", | ||
sha256 = "099a9fb96a376ccbbb7d291ed4ecbdfd42f6bc822ab77ae6f1b5cb9e914e94fa", | ||
urls = [ | ||
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip", | ||
"https://github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip", | ||
], | ||
) | ||
|
||
maybe( | ||
http_archive, | ||
name = "bazel_gazelle", | ||
sha256 = "448e37e0dbf61d6fa8f00aaa12d191745e14f07c31cabfa731f0c8e8a4f41b97", | ||
urls = [ | ||
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.28.0/bazel-gazelle-v0.28.0.tar.gz", | ||
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.28.0/bazel-gazelle-v0.28.0.tar.gz", | ||
], | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the plan to remove these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can try removing them and see what breaks....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.