Skip to content

Commit

Permalink
Update deprecated single_file -> allow_single_file attribute (bazel-c…
Browse files Browse the repository at this point in the history
…ontrib#1628)

Also remove allow_files where it conflicts with allow_single_file (not
allowed).
Also remove both allow_files and allow_single_file in private attributes
where executable is set to True (a file cannot be specified anyway -
private attribute).
  • Loading branch information
ash2k authored and jayconrod committed Aug 6, 2018
1 parent 1d380b3 commit 185de7f
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 46 deletions.
4 changes: 1 addition & 3 deletions extras/bindata.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def _bindata_impl(ctx):
inputs = ctx.files.srcs,
outputs = [out],
mnemonic = "GoBindata",
executable = ctx.file._bindata,
executable = ctx.executable._bindata,
arguments = [arguments],
)
return [
Expand All @@ -71,8 +71,6 @@ bindata = go_rule(
"modtime": attr.bool(default = False),
"extra_args": attr.string_list(),
"_bindata": attr.label(
allow_files = True,
single_file = True,
executable = True,
cfg = "host",
default = "@com_github_kevinburke_go_bindata//go-bindata:go-bindata",
Expand Down
14 changes: 0 additions & 14 deletions go/private/rules/builders.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -42,50 +42,36 @@ builders = rule(
_builders_impl,
attrs = {
"_asm": attr.label(
allow_files = True,
single_file = True,
executable = True,
cfg = "host",
default = "//go/tools/builders:asm",
),
"_compile": attr.label(
allow_files = True,
single_file = True,
executable = True,
cfg = "host",
default = "//go/tools/builders:compile",
),
"_pack": attr.label(
allow_files = True,
single_file = True,
executable = True,
cfg = "host",
default = "//go/tools/builders:pack",
),
"_link": attr.label(
allow_files = True,
single_file = True,
executable = True,
cfg = "host",
default = "//go/tools/builders:link",
),
"_cgo": attr.label(
allow_files = True,
single_file = True,
executable = True,
cfg = "host",
default = "//go/tools/builders:cgo",
),
"_test_generator": attr.label(
allow_files = True,
single_file = True,
executable = True,
cfg = "host",
default = "//go/tools/builders:generate_test_main",
),
"_cover": attr.label(
allow_files = True,
single_file = True,
executable = True,
cfg = "host",
default = "//go/tools/builders:cover",
Expand Down
3 changes: 1 addition & 2 deletions go/private/rules/cgo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,7 @@ _cgo_import = go_rule(
_cgo_import_impl,
attrs = {
"cgo_o": attr.label(
allow_files = True,
single_file = True,
allow_single_file = True,
),
"sample_go_srcs": attr.label_list(allow_files = True),
},
Expand Down
1 change: 0 additions & 1 deletion go/private/rules/info.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ _go_info = go_rule(
_go_info_impl,
attrs = {
"_go_info": attr.label(
single_file = True,
executable = True,
cfg = "host",
default = "@io_bazel_rules_go//go/tools/builders:info",
Expand Down
2 changes: 1 addition & 1 deletion go/private/rules/sdk.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def _go_sdk_impl(ctx):
headers = ctx.files.headers,
srcs = ctx.files.srcs,
tools = ctx.files.tools,
go = ctx.file.go,
go = ctx.executable.go,
)]

go_sdk = rule(
Expand Down
6 changes: 2 additions & 4 deletions go/private/tools/files_equal_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,11 @@ files_equal_test = rule(
attrs = {
"golden": attr.label(
mandatory = True,
allow_files = True,
single_file = True,
allow_single_file = True,
),
"actual": attr.label(
mandatory = True,
allow_files = True,
single_file = True,
allow_single_file = True,
),
"error_message": attr.string(
default = "FILES DO NOT HAVE EQUAL CONTENTS",
Expand Down
7 changes: 3 additions & 4 deletions go/private/tools/gazelle.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ $BASE/{gazelle} {args} $@

def _gazelle_script_impl(ctx):
print("DEPRECATED: %s: load gazelle rule from @bazel_gazelle//:def.bzl instead of @io_bazel_rules_go//go:def.bzl" % ctx.label)

# TODO(jayconrod): add a fix to Gazelle to replace invocations of this rule
# with the new one in @bazel_gazelle. Once in place, fail here.
go = go_context(ctx)
Expand All @@ -47,12 +48,12 @@ def _gazelle_script_impl(ctx):
if ctx.attr.build_tags:
args += ["-build_tags", ",".join(ctx.attr.build_tags)]
args += ctx.attr.args
script_content = _script_content.format(gazelle = ctx.file._gazelle.short_path, args = " ".join(args))
script_content = _script_content.format(gazelle = ctx.executable._gazelle.short_path, args = " ".join(args))
script_file = go.declare_file(go, ext = ".bash")
ctx.actions.write(output = script_file, is_executable = True, content = script_content)
return struct(
files = depset([script_file]),
runfiles = ctx.runfiles([ctx.file._gazelle]),
runfiles = ctx.runfiles([ctx.executable._gazelle]),
)

_gazelle_script = go_rule(
Expand Down Expand Up @@ -85,8 +86,6 @@ _gazelle_script = go_rule(
"prefix": attr.string(),
"_gazelle": attr.label(
default = "@bazel_gazelle//cmd/gazelle",
allow_files = True,
single_file = True,
executable = True,
cfg = "host",
),
Expand Down
13 changes: 4 additions & 9 deletions proto/compiler.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ def _go_proto_compiler_impl(ctx):
compile = go_proto_compile,
options = ctx.attr.options,
suffix = ctx.attr.suffix,
go_protoc = ctx.file._go_protoc,
protoc = ctx.file._protoc,
plugin = ctx.file.plugin,
go_protoc = ctx.executable._go_protoc,
protoc = ctx.executable._protoc,
plugin = ctx.executable.plugin,
valid_archive = ctx.attr.valid_archive,
import_path_option = ctx.attr.import_path_option,
),
Expand All @@ -117,22 +117,17 @@ go_proto_compiler = go_rule(
"valid_archive": attr.bool(default = True),
"import_path_option": attr.bool(default = True),
"plugin": attr.label(
allow_files = True,
single_file = True,
allow_single_file = True,
executable = True,
cfg = "host",
default = "@com_github_golang_protobuf//protoc-gen-go",
),
"_go_protoc": attr.label(
allow_files = True,
single_file = True,
executable = True,
cfg = "host",
default = "@io_bazel_rules_go//go/tools/builders:go-protoc",
),
"_protoc": attr.label(
allow_files = True,
single_file = True,
executable = True,
cfg = "host",
default = "@com_google_protobuf//:protoc",
Expand Down
2 changes: 1 addition & 1 deletion proto/gogo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ proto_library(
gogo_special_proto = repository_rule(
_gogo_special_proto_impl,
attrs = {
"proto": attr.label(single_file = True),
"proto": attr.label(allow_single_file = True),
},
)
9 changes: 4 additions & 5 deletions tests/bazel_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ _bazel_test_script = go_rule(
),
"clean_build": attr.bool(default = False),
"bazelrc": attr.label(
allow_files = True,
single_file = True,
allow_single_file = True,
default = "@bazel_test//:standalone_bazelrc",
),
"_settings": attr.label(default = "@bazel_test//:settings"),
Expand Down Expand Up @@ -289,7 +288,7 @@ def _md5_sum_impl(ctx):
inputs = ctx.files.srcs,
outputs = [out],
mnemonic = "GoMd5sum",
executable = ctx.file._md5sum,
executable = ctx.executable._md5sum,
arguments = [arguments],
)
return struct(files = depset([out]))
Expand All @@ -299,9 +298,9 @@ md5_sum = go_rule(
attrs = {
"srcs": attr.label_list(allow_files = True),
"_md5sum": attr.label(
allow_files = True,
single_file = True,
executable = True,
default = "@io_bazel_rules_go//go/tools/builders:md5sum",
cfg = "host",
),
},
)
Expand Down
3 changes: 1 addition & 2 deletions tests/legacy/examples/cgo/example_command/generate_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ generate_script = rule(
_generate_script_impl,
attrs = {
"binary": attr.label(
allow_files = True,
single_file = True,
allow_single_file = True,
),
},
)

0 comments on commit 185de7f

Please sign in to comment.