Skip to content

Commit 702f179

Browse files
author
Jay Conrod
authored
go: remove deprecated features (bazel-contrib#2671)
* Remove go_rule. * Remove go_archive_aspect and GoAspectProvider. * Error when go_{binary,test} depends on go_{binary,test}. * Ignore ctx.features and report warnings if they're used.
1 parent 4e4ef6c commit 702f179

File tree

13 files changed

+47
-188
lines changed

13 files changed

+47
-188
lines changed

extras/bindata.bzl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ load(
1818
"@io_bazel_rules_go//go:def.bzl",
1919
"go_context",
2020
)
21-
load(
22-
"@io_bazel_rules_go//go/private:rules/rule.bzl",
23-
"go_rule",
24-
)
2521

2622
def _bindata_impl(ctx):
2723
go = go_context(ctx)
@@ -62,8 +58,8 @@ def _bindata_impl(ctx):
6258
),
6359
]
6460

65-
bindata = go_rule(
66-
_bindata_impl,
61+
bindata = rule(
62+
implementation = _bindata_impl,
6763
attrs = {
6864
"srcs": attr.label_list(allow_files = True),
6965
"package": attr.string(mandatory = True),
@@ -78,5 +74,9 @@ bindata = go_rule(
7874
cfg = "host",
7975
default = "@com_github_kevinburke_go_bindata//go-bindata:go-bindata",
8076
),
77+
"_go_context_data": attr.label(
78+
default = "//:go_context_data",
79+
),
8180
},
81+
toolchains = ["@io_bazel_rules_go//go:toolchain"],
8282
)

extras/embed_data.bzl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ load(
1818
"@io_bazel_rules_go//go/private:context.bzl", #TODO: This ought to be def
1919
"go_context",
2020
)
21-
load(
22-
"@io_bazel_rules_go//go/private:rules/rule.bzl",
23-
"go_rule",
24-
)
2521

2622
def _go_embed_data_impl(ctx):
2723
go = go_context(ctx)
@@ -82,7 +78,7 @@ def _go_embed_data_impl(ctx):
8278
source,
8379
]
8480

85-
go_embed_data = go_rule(
81+
go_embed_data = rule(
8682
implementation = _go_embed_data_impl,
8783
attrs = {
8884
"package": attr.string(),
@@ -97,6 +93,10 @@ go_embed_data = go_rule(
9793
executable = True,
9894
cfg = "host",
9995
),
96+
"_go_context_data": attr.label(
97+
default = "//:go_context_data",
98+
),
10099
},
100+
toolchains = ["@io_bazel_rules_go//go:toolchain"],
101101
)
102102
# See go/extras.rst#go_embed_data for full documentation.

go/def.bzl

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ load(
6262
"@io_bazel_rules_go//go/private:tools/path.bzl",
6363
_go_path = "go_path",
6464
)
65-
load(
66-
"@io_bazel_rules_go//go/private:rules/rule.bzl",
67-
_go_rule = "go_rule",
68-
)
6965
load(
7066
"@io_bazel_rules_go//go/private:rules/library.bzl",
7167
_go_tool_library = "go_tool_library",
@@ -160,15 +156,15 @@ go_test = _go_test_macro
160156
# See go/core.rst#go_test for full documentation.
161157
go_source = _go_source
162158

163-
# See go/core.rst#go_rule for full documentation.
164-
go_rule = _go_rule
165-
166159
# See go/core.rst#go_path for full documentation.
167160
go_path = _go_path
168161

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

165+
def go_rule(**kwargs):
166+
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")
167+
172168
def go_rules_dependencies():
173169
_moved("go_rules_dependencies")
174170

go/private/context.bzl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,17 +276,16 @@ def _collect_runfiles(go, data, deps):
276276
def _check_binary_dep(go, dep, edge):
277277
"""Checks that this rule doesn't depend on a go_binary or go_test.
278278
279-
go_binary and go_test apply an aspect to their deps and embeds. If a
280-
go_binary / go_test depends on another go_binary / go_test in different
281-
modes, the aspect is applied twice, and Bazel emits an opaque error
282-
message.
279+
go_binary and go_test may return provides with useful information for other
280+
rules (like go_path), but go_binary and go_test may not depend on other
281+
go_binary and go_binary targets. Their dependencies may be built in
282+
different modes, resulting in conflicts and opaque errors.
283283
"""
284284
if (type(dep) == "Target" and
285285
DefaultInfo in dep and
286286
getattr(dep[DefaultInfo], "files_to_run", None) and
287287
dep[DefaultInfo].files_to_run.executable):
288-
# TODO(#1735): make this an error after 0.16 is released.
289-
print("WARNING: rule {rule} depends on executable {dep} via {edge}. This is not safe for cross-compilation. Depend on go_library instead. This will be an error in the future.".format(
288+
fail("rule {rule} depends on executable {dep} via {edge}. This is not safe for cross-compilation. Depend on go_library instead.".format(
290289
rule = str(go._ctx.label),
291290
dep = str(dep.label),
292291
edge = edge,
@@ -496,6 +495,10 @@ def go_context(ctx, attr = None):
496495
)
497496

498497
def _go_context_data_impl(ctx):
498+
if "race" in ctx.features:
499+
print("WARNING: --features=race is no longer supported. Use --@io_bazel_rules_go//go/config:race instead.")
500+
if "msan" in ctx.features:
501+
print("WARNING: --features=msan is no longer supported. Use --@io_bazel_rules_go//go/config:msan instead.")
499502
coverdata = ctx.attr.coverdata[GoArchive]
500503
nogo = ctx.files.nogo[0] if ctx.files.nogo else None
501504
providers = [

go/private/mode.bzl

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,13 @@ def _ternary(*values):
6565
fail("_ternary failed to produce a final result from {}".format(values))
6666

6767
def get_mode(ctx, go_toolchain, cgo_context_info, go_config_info):
68-
static = _ternary(
69-
"on" if "static" in ctx.features else "auto",
70-
go_config_info.static if go_config_info else "off",
71-
)
68+
static = _ternary(go_config_info.static if go_config_info else "off")
7269
pure = _ternary(
7370
"on" if not cgo_context_info else "auto",
7471
go_config_info.pure if go_config_info else "off",
7572
)
76-
race = _ternary(
77-
"on" if ("race" in ctx.features and not pure) else "auto",
78-
go_config_info.race if go_config_info else "off",
79-
)
80-
msan = _ternary(
81-
"on" if ("msan" in ctx.features and not pure) else "auto",
82-
go_config_info.msan if go_config_info else "off",
83-
)
73+
race = _ternary(go_config_info.race if go_config_info else "off")
74+
msan = _ternary(go_config_info.msan if go_config_info else "off")
8475
strip = go_config_info.strip if go_config_info else False
8576
stamp = go_config_info.stamp if go_config_info else False
8677
debug = go_config_info.debug if go_config_info else False

go/private/providers.bzl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ GoArchiveData = provider()
3434
# See go/providers.rst#GoArchive for full documentation.
3535
GoArchive = provider()
3636

37-
GoAspectProviders = provider()
38-
3937
GoPath = provider()
4038

4139
GoSDK = provider(
@@ -76,15 +74,11 @@ EXPORT_PATH = "export"
7674
def get_source(dep):
7775
if type(dep) == "struct":
7876
return dep
79-
if GoAspectProviders in dep:
80-
return dep[GoAspectProviders].source
8177
return dep[GoSource]
8278

8379
def get_archive(dep):
8480
if type(dep) == "struct":
8581
return dep
86-
if GoAspectProviders in dep:
87-
return dep[GoAspectProviders].archive
8882
return dep[GoArchive]
8983

9084
def effective_importpath_pkgpath(lib):

go/private/rules/aspect.bzl

Lines changed: 0 additions & 101 deletions
This file was deleted.

go/private/rules/info.bzl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,9 @@
1313
# limitations under the License.
1414

1515
load(
16-
"@io_bazel_rules_go//go/private:context.bzl",
16+
"//go/private:context.bzl",
1717
"go_context",
1818
)
19-
load(
20-
"@io_bazel_rules_go//go/private:rules/rule.bzl",
21-
"go_rule",
22-
)
2319

2420
def _go_info_impl(ctx):
2521
go = go_context(ctx)
@@ -38,15 +34,19 @@ def _go_info_impl(ctx):
3834
runfiles = ctx.runfiles([report]),
3935
)]
4036

41-
_go_info = go_rule(
42-
_go_info_impl,
37+
_go_info = rule(
38+
implementation = _go_info_impl,
4339
attrs = {
4440
"_go_info": attr.label(
4541
executable = True,
4642
cfg = "exec",
47-
default = "@io_bazel_rules_go//go/tools/builders:info",
43+
default = "//go/tools/builders:info",
44+
),
45+
"_go_context_data": attr.label(
46+
default = "//:go_context_data",
4847
),
4948
},
49+
toolchains = ["@io_bazel_rules_go//go:toolchain"],
5050
)
5151

5252
def go_info():

go/private/rules/rule.bzl

Lines changed: 0 additions & 27 deletions
This file was deleted.

proto/def.bzl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ load(
2323
"GoProtoCompiler",
2424
"proto_path",
2525
)
26-
load(
27-
"@io_bazel_rules_go//go/private:rules/rule.bzl",
28-
"go_rule",
29-
)
3026
load(
3127
"@io_bazel_rules_go//go/private:providers.bzl",
3228
"INFERRED_PATH",
@@ -138,8 +134,8 @@ def _go_proto_library_impl(ctx):
138134
])
139135
return providers + [OutputGroupInfo(**output_groups)]
140136

141-
go_proto_library = go_rule(
142-
_go_proto_library_impl,
137+
go_proto_library = rule(
138+
implementation = _go_proto_library_impl,
143139
attrs = {
144140
"proto": attr.label(providers = [ProtoInfo]),
145141
"protos": attr.label_list(
@@ -160,7 +156,11 @@ go_proto_library = go_rule(
160156
providers = [GoProtoCompiler],
161157
default = ["@io_bazel_rules_go//proto:go_proto"],
162158
),
159+
"_go_context_data": attr.label(
160+
default = "//:go_context_data",
161+
),
163162
},
163+
toolchains = ["@io_bazel_rules_go//go:toolchain"],
164164
)
165165
# go_proto_library is a rule that takes a proto_library (in the proto
166166
# attribute) and produces a go library for it.

0 commit comments

Comments
 (0)