Skip to content

Commit 7668f20

Browse files
David Freeseyagehu
David Freese
authored andcommitted
Move assert out of compile actions (bazelbuild#666)
Was trying to remove uses of to_list() where possible. While this change doesn't have any serious effect, the hope is it sets up future changes that do start to remove more of them.
1 parent f72a5e4 commit 7668f20

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

rust/private/rust.bzl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,32 @@ def _assert_no_deprecated_attributes(ctx):
3131
"instead. If you used `cargo raze`, please use version 0.3.3 or later.",
3232
]))
3333

34+
def _assert_correct_dep_mapping(ctx):
35+
"""Forces a failure if proc_macro_deps and deps are mixed inappropriately
36+
37+
Args:
38+
ctx (ctx): The current rule's context object
39+
"""
40+
for dep in ctx.attr.deps:
41+
if rust_common.crate_info in dep:
42+
if dep[rust_common.crate_info].type == "proc-macro":
43+
fail(
44+
"{} listed {} in its deps, but it is a proc-macro. It should instead be in the bazel property proc_macro_deps.".format(
45+
ctx.label,
46+
dep.label,
47+
),
48+
)
49+
for dep in ctx.attr.proc_macro_deps:
50+
type = dep[rust_common.crate_info].type
51+
if type != "proc-macro":
52+
fail(
53+
"{} listed {} in its proc_macro_deps, but it is not proc-macro, it is a {}. It should probably instead be listed in deps.".format(
54+
ctx.label,
55+
dep.label,
56+
type,
57+
),
58+
)
59+
3460
def _determine_lib_name(name, crate_type, toolchain, lib_hash = ""):
3561
"""See https://github.com/bazelbuild/rules_rust/issues/405
3662
@@ -203,6 +229,7 @@ def _rust_library_common(ctx, crate_type):
203229
# Find lib.rs
204230
crate_root = crate_root_src(ctx.attr, ctx.files.srcs, "lib")
205231
_assert_no_deprecated_attributes(ctx)
232+
_assert_correct_dep_mapping(ctx)
206233

207234
toolchain = find_toolchain(ctx)
208235

@@ -249,6 +276,7 @@ def _rust_binary_impl(ctx):
249276
"""
250277
toolchain = find_toolchain(ctx)
251278
crate_name = name_to_crate_name(ctx.label.name)
279+
_assert_correct_dep_mapping(ctx)
252280

253281
output = ctx.actions.declare_file(ctx.label.name + toolchain.binary_ext)
254282

@@ -363,6 +391,7 @@ def _rust_test_common(ctx, toolchain, output):
363391
list: The list of providers. See `rustc_compile_action`
364392
"""
365393
_assert_no_deprecated_attributes(ctx)
394+
_assert_correct_dep_mapping(ctx)
366395

367396
crate_name = name_to_crate_name(ctx.label.name)
368397
crate_type = "bin"

rust/private/rustc.bzl

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -115,27 +115,6 @@ def collect_deps(label, deps, proc_macro_deps, aliases, toolchain):
115115
Returns:
116116
tuple: Returns a tuple (DepInfo, BuildInfo) of providers.
117117
"""
118-
119-
for dep in deps.to_list():
120-
if rust_common.crate_info in dep:
121-
if dep[rust_common.crate_info].type == "proc-macro":
122-
fail(
123-
"{} listed {} in its deps, but it is a proc-macro. It should instead be in the bazel property proc_macro_deps.".format(
124-
label,
125-
dep.label,
126-
),
127-
)
128-
for dep in proc_macro_deps.to_list():
129-
type = dep[rust_common.crate_info].type
130-
if type != "proc-macro":
131-
fail(
132-
"{} listed {} in its proc_macro_deps, but it is not proc-macro, it is a {}. It should probably instead be listed in deps.".format(
133-
label,
134-
dep.label,
135-
type,
136-
),
137-
)
138-
139118
direct_crates = []
140119
transitive_crates = []
141120
transitive_noncrates = []

0 commit comments

Comments
 (0)