Skip to content

Commit

Permalink
Update and run buildifier (bazelbuild#3416)
Browse files Browse the repository at this point in the history
* Update and run buildifier

* Fix trivial buildifier warnings

* Fix non-trivial buildifier warnings
  • Loading branch information
fmeum authored and healthy-pod committed Feb 17, 2023
1 parent 7205893 commit 7929f65
Show file tree
Hide file tree
Showing 21 changed files with 61 additions and 55 deletions.
18 changes: 12 additions & 6 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module(
name = "rules_go",
repo_name = "io_bazel_rules_go",
version = "0.37.0",
compatibility_level = 0,
repo_name = "io_bazel_rules_go",
)

bazel_dep(name = "bazel_skylib", version = "1.2.0")
Expand All @@ -13,25 +13,31 @@ bazel_dep(name = "protobuf", version = "3.19.2", repo_name = "com_google_protobu
non_module_dependencies = use_extension("//go/private:extensions.bzl", "non_module_dependencies")
use_repo(
non_module_dependencies,
"io_bazel_rules_nogo",
"go_googleapis",
"io_bazel_rules_nogo",
)

go_sdk = use_extension("//go:extensions.bzl", "go_sdk")
go_sdk.download(name = "go_default_sdk", version = "1.18.3")
go_sdk.download(
name = "go_default_sdk",
version = "1.18.3",
)
use_repo(go_sdk, "go_default_sdk_toolchains")

register_toolchains("@go_default_sdk_toolchains//:all")

bazel_dep(name = "gazelle", version = "0.27.0")

go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")
go_deps.module(
build_file_proto_mode = "disable",
path = "github.com/gogo/protobuf",
version = "v1.3.2",
sum = "h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=",
build_file_proto_mode = "disable",
version = "v1.3.2",
)
use_repo(go_deps,
use_repo(
go_deps,
"com_github_gogo_protobuf",
"com_github_golang_mock",
"com_github_golang_protobuf",
Expand Down
11 changes: 4 additions & 7 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
workspace(name = "io_bazel_rules_go")

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")

Expand Down Expand Up @@ -28,13 +27,11 @@ load("@io_bazel_rules_go//extras:embed_data_deps.bzl", "go_embed_data_dependenci
go_embed_data_dependencies()

# Used by //tests:buildifier_test.
# Latest release is not compatible with the incompatible bazel flags we use
# in CI, in particular, --incompatible_load_proto_rules_from_bzl.
git_repository(
http_archive(
name = "com_github_bazelbuild_buildtools",
commit = "f630fda6c1db92241fee1ff66ca07018b2c7a5f3", # master as of 2020-02-03
remote = "https://github.com/bazelbuild/buildtools",
shallow_since = "1580754619 +0100",
sha256 = "05eff86c1d444dde18d55ac890f766bce5e4db56c180ee86b5aacd6704a5feb9",
strip_prefix = "buildtools-6.0.0",
urls = ["https://github.com/bazelbuild/buildtools/archive/refs/tags/6.0.0.tar.gz"],
)

# For manual testing against an LLVM toolchain.
Expand Down
14 changes: 7 additions & 7 deletions go/def.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -185,28 +185,28 @@ go_path = _go_path
# See docs/go/core/rules.md#go_cross_binary for full documentation.
go_cross_binary = _go_cross_binary

def go_vet_test(*args, **kwargs):
def go_vet_test(*_args, **_kwargs):
fail("The go_vet_test rule has been removed. Please migrate to nogo instead, which supports vet tests.")

def go_rule(**kwargs):
def go_rule(**_kwargs):
fail("The go_rule function has been removed. Use rule directly instead. See https://github.com/bazelbuild/rules_go/blob/master/go/toolchains.rst#writing-new-go-rules")

def go_rules_dependencies():
_moved("go_rules_dependencies")

def go_register_toolchains(**kwargs):
def go_register_toolchains(**_kwargs):
_moved("go_register_toolchains")

def go_download_sdk(**kwargs):
def go_download_sdk(**_kwargs):
_moved("go_download_sdk")

def go_host_sdk(**kwargs):
def go_host_sdk(**_kwargs):
_moved("go_host_sdk")

def go_local_sdk(**kwargs):
def go_local_sdk(**_kwargs):
_moved("go_local_sdk")

def go_wrap_sdk(**kwargs):
def go_wrap_sdk(**_kwargs):
_moved("go_wrap_sdK")

def _moved(name):
Expand Down
2 changes: 1 addition & 1 deletion go/platform/apple.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def _apple_env(ctx, platform):
xcode_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig]
return apple_common.target_apple_env(xcode_config, platform)

def apple_ensure_options(ctx, env, tags, compiler_option_lists, linker_option_lists, target_gnu_system_name):
def apple_ensure_options(ctx, env, _tags, compiler_option_lists, linker_option_lists, target_gnu_system_name):
"""Returns environment, flags, and Go tags for Apple targets."""
platform, platform_type = _PLATFORMS.get(target_gnu_system_name, (None, None))
if not platform:
Expand Down
2 changes: 1 addition & 1 deletion go/platform/crosstool.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

def _match_apple(crosstool_top, cpu):
def _match_apple(_crosstool_top, cpu):
"""_match_apple will try to detect wether the inbound crosstool/cpu is
targeting the Apple ecosystem. Apple crosstool CPUs are prefixed, so
matching is easy."""
Expand Down
6 changes: 3 additions & 3 deletions go/private/BUILD.sdk.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ filegroup(
name = "libs",
srcs = glob(
["pkg/{goos}_{goarch}/**/*.a"],
exclude = ["pkg/{goos}_{goarch}/**/cmd/**"],
allow_empty = True,
exclude = ["pkg/{goos}_{goarch}/**/cmd/**"],
),
)

Expand All @@ -36,14 +36,14 @@ filegroup(
go_sdk(
name = "go_sdk",
srcs = [":srcs"],
experiments = {experiments},
go = "bin/go{exe}",
goarch = "{goarch}",
goos = "{goos}",
headers = [":headers"],
libs = [":libs"],
package_list = ":package_list",
root_file = "ROOT",
experiments = {experiments},
tools = [":tools"],
version = "{version}",
)
Expand All @@ -56,7 +56,7 @@ go_tool_binary(

non_go_reset_target(
name = "builder_reset",
dep = ":builder"
dep = ":builder",
)

# TODO(jayconrod): Gazelle depends on this file directly. This dependency
Expand Down
4 changes: 2 additions & 2 deletions go/private/BUILD.toolchains.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ selects.config_setting_group(
)

declare_bazel_toolchains(
host_goos = "{goos}",
host_goarch = "{goarch}",
toolchain_prefix = "@{sdk_repo}//",
host_goos = "{goos}",
sdk_version_setting = ":sdk_version_setting",
toolchain_prefix = "@{sdk_repo}//",
)
2 changes: 1 addition & 1 deletion go/private/actions/stdlib.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def emit_stdlib(go):
source = go.library_to_source(go, {}, library, False)
return [source, library]

def _stdlib_library_to_source(go, attr, source, merge):
def _stdlib_library_to_source(go, _attr, source, _merge):
if _should_use_sdk_stdlib(go):
source["stdlib"] = _sdk_stdlib(go)
else:
Expand Down
1 change: 0 additions & 1 deletion go/private/context.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,6 @@ def _go_context_data_impl(ctx):
print("WARNING: --features=race is no longer supported. Use --@io_bazel_rules_go//go/config:race instead.")
if "msan" in ctx.features:
print("WARNING: --features=msan is no longer supported. Use --@io_bazel_rules_go//go/config:msan instead.")
coverdata = ctx.attr.coverdata[GoArchive]
nogo = ctx.files.nogo[0] if ctx.files.nogo else None
providers = [
GoContextInfo(
Expand Down
2 changes: 1 addition & 1 deletion go/private/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ go_sdk = module_extension(
},
)

def _non_module_dependencies_impl(ctx):
def _non_module_dependencies_impl(_ctx):
go_rules_dependencies(force = True)

non_module_dependencies = module_extension(
Expand Down
4 changes: 2 additions & 2 deletions go/private/rules/nogo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ def _nogo_impl(ctx):
embed = [ctx.attr._nogo_srcs],
deps = analyzer_archives,
), nogo_library, False)
nogo_archive, executable, runfiles = go.binary(
_, executable, runfiles = go.binary(
go,
name = ctx.label.name,
source = nogo_source,
)
return [DefaultInfo(
files = depset([executable]),
runfiles = nogo_archive.runfiles,
runfiles = runfiles,
executable = executable,
)]

Expand Down
4 changes: 0 additions & 4 deletions go/private/rules/test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ def _go_test_impl(ctx):
), external_library, ctx.coverage_instrumented())
external_source, internal_archive = _recompile_external_deps(go, external_source, internal_archive, [t.label for t in ctx.attr.embed])
external_archive = go.archive(go, external_source)
external_srcs = split_srcs(external_source.srcs).go

# now generate the main function
if ctx.attr.rundir:
Expand Down Expand Up @@ -524,13 +523,10 @@ def _recompile_external_deps(go, external_source, internal_archive, library_labe
# deps_pushed tracks the status of each target.
# DEPS_UNPROCESSED means the target is on the stack, but its dependencies
# are not.
# ON_DEP_LIST means the target and its dependencies have been added to
# dep_list.
# Non-negative integers are the number of dependencies on the stack that
# still need to be processed.
# A target is on the stack if its status is DEPS_UNPROCESSED or 0.
DEPS_UNPROCESSED = -1
ON_DEP_LIST = -2
deps_pushed = {l: DEPS_UNPROCESSED for l in stack}

# dependents maps labels to lists of known dependents. When a target is
Expand Down
10 changes: 5 additions & 5 deletions go/private/rules/transition.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def _go_transition_impl(settings, attr):

return settings

def _request_nogo_transition(settings, attr):
def _request_nogo_transition(settings, _attr):
"""Indicates that we want the project configured nogo instead of a noop.
This does not guarantee that the project configured nogo will be used (if
Expand Down Expand Up @@ -227,7 +227,7 @@ _stdlib_keep_keys = sorted([
"@io_bazel_rules_go//go/config:linkmode",
])

def _go_tool_transition_impl(settings, attr):
def _go_tool_transition_impl(settings, _attr):
"""Sets most Go settings to default values (use for external Go tools).
go_tool_transition sets all of the //go/config settings to their default
Expand All @@ -250,7 +250,7 @@ go_tool_transition = transition(
outputs = _reset_transition_keys,
)

def _non_go_tool_transition_impl(settings, attr):
def _non_go_tool_transition_impl(settings, _attr):
"""Sets all Go settings to default values (use for external non-Go tools).
non_go_tool_transition sets all of the //go/config settings as well as the
Expand All @@ -274,7 +274,7 @@ non_go_tool_transition = transition(
outputs = _reset_transition_keys,
)

def _go_stdlib_transition_impl(settings, attr):
def _go_stdlib_transition_impl(settings, _attr):
"""Sets all Go settings to their default values, except for those affecting the Go SDK.
This transition is similar to _non_go_tool_transition except that it keeps the
Expand Down Expand Up @@ -376,7 +376,7 @@ go_transition.
""",
)

def _non_go_transition_impl(settings, attr):
def _non_go_transition_impl(settings, _attr):
"""Sets all Go settings to the values they had before the last go_transition.
non_go_transition sets all of the //go/config settings to the value they had
Expand Down
1 change: 1 addition & 0 deletions go/private/tools/files_equal_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,5 @@ eof""",
"$(location %s)" % actual,
error_message,
],
**kwargs
)
2 changes: 1 addition & 1 deletion go/private/tools/path.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def _merge_pkg(x, y):
x_data = {f.path: None for f in x.data}
x_embedsrcs = {f.path: None for f in x.embedsrcs}
x.srcs.extend([f for f in y.srcs if f.path not in x_srcs])
x.data.extend([f for f in y.data if f.path not in x_srcs])
x.data.extend([f for f in y.data if f.path not in x_data])
x.embedsrcs.extend([f for f in y.embedsrcs if f.path not in x_embedsrcs])
x.pkgs.update(y.pkgs)

Expand Down
11 changes: 7 additions & 4 deletions go/tools/gopackagesdriver/aspect.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,19 @@ def _go_archive_to_pkg(archive):
ExportFile = file_path(archive.data.export_file),
GoFiles = [
file_path(src)
for src in archive.data.orig_srcs if src.path.endswith(".go")
for src in archive.data.orig_srcs
if src.path.endswith(".go")
],
CompiledGoFiles = [
file_path(src)
for src in archive.data.srcs if src.path.endswith(".go")
for src in archive.data.srcs
if src.path.endswith(".go")
],
OtherFiles = [
file_path(src)
for src in archive.data.orig_srcs if not src.path.endswith(".go")
]
for src in archive.data.orig_srcs
if not src.path.endswith(".go")
],
)

def make_pkg_json(ctx, name, pkg_info):
Expand Down
4 changes: 2 additions & 2 deletions proto/def.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def get_imports(attr):
]
return depset(direct = direct.keys(), transitive = transitive)

def _go_proto_aspect_impl(target, ctx):
def _go_proto_aspect_impl(_target, ctx):
imports = get_imports(ctx.rule.attr)
return [GoProtoImports(imports = imports)]

Expand All @@ -82,7 +82,7 @@ _go_proto_aspect = aspect(
],
)

def _proto_library_to_source(go, attr, source, merge):
def _proto_library_to_source(_go, attr, source, merge):
if attr.compiler:
compilers = [attr.compiler]
else:
Expand Down
2 changes: 1 addition & 1 deletion proto/wkt/well_known_types.bzl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
load("//go:def.bzl", "GoArchive", "GoLibrary", "GoSource")
load("//proto:compiler.bzl", "GoProtoCompiler")

_proto_library_suffix = "proto"
_go_proto_library_suffix = "go_proto"

# NOTE: since protobuf 3.14, the WKTs no longer use these paths. They're only
Expand Down Expand Up @@ -67,6 +66,7 @@ WELL_KNOWN_TYPES_APIV2 = [
"@org_golang_google_protobuf//types/pluginpb",
]

# buildifier: disable=unused-variable
def _go_proto_wrapper_compile(go, compiler, protos, imports, importpath):
return []

Expand Down
8 changes: 6 additions & 2 deletions tests/bcr/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ local_path_override(
module_name = "rules_go",
path = "../..",
)

bazel_dep(name = "gazelle", version = "0.26.0")
bazel_dep(name = "protobuf", version = "3.19.6")
bazel_dep(name = "other_module", version = "")
Expand All @@ -18,13 +19,16 @@ local_path_override(

# Test that this correctly downloads the SDK by requesting it from the commandline (see presubmit.yml).
go_sdk = use_extension("@my_rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(name = "go_sdk", version = "1.17.5")
go_sdk.download(
name = "go_sdk",
version = "1.17.5",
)
use_repo(go_sdk, "go_sdk")

go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
go_deps.module(
path = "google.golang.org/grpc",
version = "v1.50.0",
sum = "h1:fPVVDxY9w++VjTZsYvXWqEf9Rqar/e+9zYfxKK+W+YU=",
version = "v1.50.0",
)
use_repo(go_deps, "org_golang_google_grpc")
2 changes: 1 addition & 1 deletion tests/core/go_path/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ go_test(
":archive_path",
":copy_path",
":link_path",
":transition_path",
":nodata_path",
":notransitive_path",
":transition_path",
],
rundir = ".",
deps = ["//go/tools/bazel:go_default_library"],
Expand Down
Loading

0 comments on commit 7929f65

Please sign in to comment.