Skip to content

Commit c134a45

Browse files
Addressed some new buildifier defects (#1132)
* Addressed some new buildifier defects * Update rust/private/utils.bzl Co-authored-by: Daniel Wagner-Hall <[email protected]> Co-authored-by: Daniel Wagner-Hall <[email protected]>
1 parent 4499358 commit c134a45

File tree

20 files changed

+25
-65
lines changed

20 files changed

+25
-65
lines changed

cargo/cargo_bootstrap.bzl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ def _cargo_bootstrap_repository_impl(repository_ctx):
188188
rustc_template = repository_ctx.attr.rust_toolchain_rustc_template
189189

190190
tools = get_rust_tools(
191-
repository_ctx = repository_ctx,
192191
cargo_template = cargo_template,
193192
rustc_template = rustc_template,
194193
host_triple = host_triple,

cargo/private/cargo_utils.bzl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,10 @@ def _resolve_repository_template(
151151

152152
return template
153153

154-
def get_rust_tools(repository_ctx, cargo_template, rustc_template, host_triple, version):
154+
def get_rust_tools(cargo_template, rustc_template, host_triple, version):
155155
"""Retrieve `cargo` and `rustc` labels based on the host triple.
156156
157157
Args:
158-
repository_ctx (repository_ctx): The rule's context object
159158
cargo_template (str): A template used to identify the label of the host `cargo` binary.
160159
rustc_template (str): A template used to identify the label of the host `rustc` binary.
161160
host_triple (struct): The host's triple. See `@rules_rust//rust/platform:triple.bzl`.

crate_universe/defs.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ def _override(
377377
if not type(dep_val) == "dict":
378378
fail("The {} attribute should be a dictionary".format(dep_key))
379379

380-
for target, deps in dep_val.items():
380+
for deps in dep_val.values():
381381
if not type(deps) == "list" or any([type(x) != "string" for x in deps]):
382382
fail("The {} values should be lists of strings".format(dep_key))
383383

crate_universe/private/util.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def get_cargo_and_rustc(repository_ctx, host_triple):
123123
version_str = repository_ctx.attr.version
124124

125125
# Get info about the current host's tool locations
126-
(host_triple, resolver_triple) = get_host_triple(repository_ctx)
126+
host_triple, _ = get_host_triple(repository_ctx)
127127
system = triple_to_system(host_triple)
128128
extension = system_to_binary_ext(system)
129129
arch = triple_to_arch(host_triple)

proto/proto.bzl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,6 @@ def _rust_proto_compile(protos, descriptor_sets, imports, crate_name, ctx, is_gr
212212
output_hash,
213213
))
214214

215-
toolchain = find_toolchain(ctx)
216-
217215
# Gather all dependencies for compilation
218216
compile_action_deps = depset(
219217
transform_deps(

rust/platform/triple_mappings.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def cpu_arch_to_constraints(cpu_arch):
172172

173173
return ["@platforms//cpu:{}".format(plat_suffix)]
174174

175-
def vendor_to_constraints(vendor):
175+
def vendor_to_constraints(_vendor):
176176
# TODO(acmcarther): Review:
177177
#
178178
# My current understanding is that vendors can't have a material impact on

rust/private/clippy.bzl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,8 @@ def _clippy_aspect_impl(target, ctx):
6161

6262
toolchain = find_toolchain(ctx)
6363
cc_toolchain, feature_configuration = find_cc_toolchain(ctx)
64-
crate_type = crate_info.type
6564

6665
dep_info, build_info, linkstamps = collect_deps(
67-
label = ctx.label,
6866
deps = crate_info.deps,
6967
proc_macro_deps = crate_info.proc_macro_deps,
7068
aliases = crate_info.aliases,

rust/private/dummy_cc_toolchain/dummy_cc_toolchain.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# buildifier: disable=module-docstring
2-
def _dummy_cc_toolchain_impl(ctx):
2+
def _dummy_cc_toolchain_impl(_ctx):
33
# The `all_files` attribute is referenced by rustc_compile_action().
44
return [platform_common.ToolchainInfo(all_files = depset([]))]
55

rust/private/rust.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ load(
2727

2828
# TODO(marco): Separate each rule into its own file.
2929

30-
def _assert_no_deprecated_attributes(ctx):
30+
def _assert_no_deprecated_attributes(_ctx):
3131
"""Forces a failure if any deprecated attributes were specified
3232
3333
Args:
34-
ctx (ctx): The current rule's context object
34+
_ctx (ctx): The current rule's context object
3535
"""
3636
pass
3737

rust/private/rust_analyzer.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ rust_analyzer_detect_sysroot = rule(
221221
"""),
222222
)
223223

224-
def _rust_analyzer_impl(ctx):
224+
def _rust_analyzer_impl(_ctx):
225225
pass
226226

227227
rust_analyzer = rule(

rust/private/rustc.bzl

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,13 @@ def _are_linkstamps_supported(feature_configuration, has_grep_includes):
118118
has_grep_includes)
119119

120120
def collect_deps(
121-
label,
122121
deps,
123122
proc_macro_deps,
124123
aliases,
125124
are_linkstamps_supported = False):
126125
"""Walks through dependencies and collects the transitive dependencies.
127126
128127
Args:
129-
label (str): Label of the current target.
130128
deps (list): The deps from ctx.attr.deps.
131129
proc_macro_deps (list): The proc_macro deps from ctx.attr.proc_macro_deps.
132130
aliases (dict): A dict mapping aliased targets to their actual Crate information.
@@ -142,7 +140,6 @@ def collect_deps(
142140
direct_crates = []
143141
transitive_crates = []
144142
transitive_noncrates = []
145-
transitive_noncrate_libs = []
146143
transitive_build_infos = []
147144
build_info = None
148145
linkstamps = []
@@ -192,7 +189,6 @@ def collect_deps(
192189
"targets.")
193190

194191
transitive_crates_depset = depset(transitive = transitive_crates)
195-
transitive_libs = depset([])
196192

197193
return (
198194
rust_common.dep_info(
@@ -301,20 +297,12 @@ def get_linker_and_args(ctx, attr, cc_toolchain, feature_configuration, rpaths):
301297
return ld, link_args, link_env
302298

303299
def _process_build_scripts(
304-
ctx,
305-
file,
306-
crate_info,
307300
build_info,
308-
dep_info,
309301
compile_inputs):
310302
"""Gathers the outputs from a target's `cargo_build_script` action.
311303
312304
Args:
313-
ctx (ctx): The rule's context object
314-
file (File): A struct containing files defined in label type attributes marked as `allow_single_file`.
315-
crate_info (CrateInfo): The Crate information of the crate to process build scripts for.
316305
build_info (BuildInfo): The target Build's dependency info.
317-
dep_info (Depinfo): The target Crate's dependency info.
318306
compile_inputs (depset): A set of all files that will participate in the build.
319307
320308
Returns:
@@ -324,7 +312,7 @@ def _process_build_scripts(
324312
- (File): An optional path to a generated environment file from a `cargo_build_script` target
325313
- (list): All direct and transitive build flags from the current build info.
326314
"""
327-
extra_inputs, out_dir, build_env_file, build_flags_files = _create_extra_input_args(ctx, file, build_info, dep_info)
315+
extra_inputs, out_dir, build_env_file, build_flags_files = _create_extra_input_args(build_info)
328316
if extra_inputs:
329317
compile_inputs = depset(extra_inputs, transitive = [compile_inputs])
330318
return compile_inputs, out_dir, build_env_file, build_flags_files
@@ -447,7 +435,7 @@ def collect_inputs(
447435
)
448436

449437
build_env_files = getattr(files, "rustc_env_files", [])
450-
compile_inputs, out_dir, build_env_file, build_flags_files = _process_build_scripts(ctx, file, crate_info, build_info, dep_info, compile_inputs)
438+
compile_inputs, out_dir, build_env_file, build_flags_files = _process_build_scripts(build_info, compile_inputs)
451439
if build_env_file:
452440
build_env_files = [f for f in build_env_files] + [build_env_file]
453441
compile_inputs = depset(build_env_files, transitive = [compile_inputs])
@@ -694,7 +682,6 @@ def rustc_compile_action(
694682
crate_info,
695683
output_hash = None,
696684
rust_flags = [],
697-
environ = {},
698685
force_all_deps_direct = False):
699686
"""Create and run a rustc compile action based on the current rule's attributes
700687
@@ -705,7 +692,6 @@ def rustc_compile_action(
705692
crate_info (CrateInfo): The CrateInfo provider for the current target.
706693
output_hash (str, optional): The hashed path of the crate root. Defaults to None.
707694
rust_flags (list, optional): Additional flags to pass to rustc. Defaults to [].
708-
environ (dict, optional): A set of makefile expandable environment variables for the action
709695
force_all_deps_direct (bool, optional): Whether to pass the transitive rlibs with --extern
710696
to the commandline as opposed to -L.
711697
@@ -718,7 +704,6 @@ def rustc_compile_action(
718704
cc_toolchain, feature_configuration = find_cc_toolchain(ctx)
719705

720706
dep_info, build_info, linkstamps = collect_deps(
721-
label = ctx.label,
722707
deps = crate_info.deps,
723708
proc_macro_deps = crate_info.proc_macro_deps,
724709
aliases = crate_info.aliases,
@@ -943,14 +928,11 @@ def add_edition_flags(args, crate):
943928
if crate.edition != "2015":
944929
args.add("--edition={}".format(crate.edition))
945930

946-
def _create_extra_input_args(ctx, file, build_info, dep_info):
931+
def _create_extra_input_args(build_info):
947932
"""Gather additional input arguments from transitive dependencies
948933
949934
Args:
950-
ctx (ctx): The rule's context object
951-
file (struct): A struct containing files defined in label type attributes marked as `allow_single_file`.
952935
build_info (BuildInfo): The BuildInfo provider from the target Crate's set of inputs.
953-
dep_info (DepInfo): The Depinfo provider form the target Crate's set of inputs.
954936
955937
Returns:
956938
tuple: A tuple of the following items:

rust/private/rustdoc.bzl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ def rustdoc_compile_action(
7474
cc_toolchain, feature_configuration = find_cc_toolchain(ctx)
7575

7676
dep_info, build_info, linkstamps = collect_deps(
77-
label = ctx.label,
7877
deps = crate_info.deps,
7978
proc_macro_deps = crate_info.proc_macro_deps,
8079
aliases = crate_info.aliases,
@@ -161,7 +160,6 @@ def _rust_doc_impl(ctx):
161160

162161
crate = ctx.attr.crate
163162
crate_info = crate[rust_common.crate_info]
164-
dep_info = crate[rust_common.dep_info]
165163

166164
output_dir = ctx.actions.declare_directory("{}.rustdoc".format(ctx.label.name))
167165

rust/private/transitions.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# buildifier: disable=module-docstring
2-
def _wasm_bindgen_transition(settings, attr):
2+
def _wasm_bindgen_transition(_settings, _attr):
33
"""The implementation of the `wasm_bindgen_transition` transition
44
55
Args:
6-
settings (dict): A dict {String:Object} of all settings declared
6+
_settings (dict): A dict {String:Object} of all settings declared
77
in the inputs parameter to `transition()`
8-
attr (dict): A dict of attributes and values of the rule to which
8+
_attr (dict): A dict of attributes and values of the rule to which
99
the transition is attached
1010
1111
Returns:

rust/private/utils.bzl

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,13 @@ def relativize(path, start):
6262
src_parts = _path_parts(start)
6363
dest_parts = _path_parts(path)
6464
n = 0
65-
done = False
6665
for src_part, dest_part in zip(src_parts, dest_parts):
6766
if src_part != dest_part:
6867
break
6968
n += 1
7069

7170
relative_path = ""
72-
for i in range(n, len(src_parts)):
71+
for _ in range(n, len(src_parts)):
7372
relative_path += "../"
7473
relative_path += "/".join(dest_parts[n:])
7574

@@ -492,13 +491,6 @@ def decode_crate_name_as_label_for_testing(crate_name):
492491
def _replace_all(string, substitutions):
493492
"""Replaces occurrences of the given patterns in `string`.
494493
495-
Args:
496-
string (string): the string in which the replacements should be performed.
497-
substitutions: the list of patterns and replacements to apply.
498-
499-
Returns:
500-
A string with the appropriate substitutions performed.
501-
502494
There are a few reasons this looks complicated:
503495
* The substitutions are performed with some priority, i.e. patterns that are
504496
listed first in `substitutions` are higher priority than patterns that are
@@ -513,11 +505,18 @@ def _replace_all(string, substitutions):
513505
pattern matches *earlier* in the string.) (E.g. "_quotedot_" encodes to
514506
"_quotequote_dot_". Note that "_quotequote_" and "_dot_" both occur in
515507
this string, and overlap.).
508+
509+
Args:
510+
string (string): the string in which the replacements should be performed.
511+
substitutions: the list of patterns and replacements to apply.
512+
513+
Returns:
514+
A string with the appropriate substitutions performed.
516515
"""
517516

518517
# Find the highest-priority pattern matches.
519518
plan = {}
520-
for subst_index, (pattern, replacement) in enumerate(substitutions):
519+
for pattern, replacement in substitutions:
521520
for pattern_start in range(len(string)):
522521
if not pattern_start in plan and string.startswith(pattern, pattern_start):
523522
plan[pattern_start] = (len(pattern), replacement)

rust/toolchain.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ def _rust_toolchain_impl(ctx):
267267

268268
# In cases where the toolchain uses the Rust standard library, calculate sysroot path
269269
sysroot_path = None
270+
rust_std_files_list = []
270271
if rust_std:
271272
# Calculate the rustc sysroot path by using a file from the rust-std bundle
272273
rust_std_files_list = rust_std.files.to_list()

test/extra_exec_rustc_flags/defs.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Test transitions to test extra_exec_rustc_flags."""
22

3-
def _extra_exec_rustc_flags_transition_impl(settings, attr):
3+
def _extra_exec_rustc_flags_transition_impl(_settings, attr):
44
return {
55
"//:extra_exec_rustc_flags": attr.extra_exec_rustc_flags,
66
}

test/unit/force_all_deps_direct/force_all_deps_direct_test.bzl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ def _force_all_deps_direct_rustc_flags_test(ctx):
99
env = analysistest.begin(ctx)
1010
tut = analysistest.target_under_test(env)
1111
action = tut.actions[1]
12-
argv = action.argv
1312
assert_action_mnemonic(env, action, "Rustc")
1413
assert_argv_contains_prefix(
1514
env,

test/unit/location_expansion/location_expansion_test.bzl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ def _location_expansion_rustc_flags_test(ctx):
88
env = analysistest.begin(ctx)
99
tut = analysistest.target_under_test(env)
1010
action = tut.actions[0]
11-
argv = action.argv
1211
assert_action_mnemonic(env, action, "Rustc")
1312
assert_argv_contains(env, action, "test/unit/location_expansion/mylibrary.rs")
1413
expected = "@${pwd}/" + ctx.bin_dir.path + "/test/unit/location_expansion/generated_flag.data"

test/unit/native_deps/native_deps_test.bzl

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,6 @@ def _native_dep_lib_name(ctx):
1919
else:
2020
return "libnative_dep.a"
2121

22-
def _lib_has_no_native_libs_test_impl(ctx):
23-
env = analysistest.begin(ctx)
24-
tut = analysistest.target_under_test(env)
25-
action = tut.actions[0]
26-
assert_argv_contains(env, action, "--crate-type=lib")
27-
assert_argv_contains_prefix_suffix(env, action, "-Lnative=", "/native_deps")
28-
assert_argv_contains_not(env, action, "-lstatic=native_dep")
29-
assert_argv_contains_not(env, action, "-ldylib=native_dep")
30-
assert_argv_contains_prefix_not(env, action, "--codegen=linker=")
31-
return analysistest.end(env)
32-
3322
def _rlib_has_no_native_libs_test_impl(ctx):
3423
env = analysistest.begin(ctx)
3524
tut = analysistest.target_under_test(env)

test/unit/use_libtest_harness/use_libtest_harness_test.bzl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ def _use_libtest_harness_rustc_flags_test_impl(ctx):
88
env = analysistest.begin(ctx)
99
tut = analysistest.target_under_test(env)
1010
action = tut.actions[0]
11-
argv = action.argv
1211
assert_action_mnemonic(env, action, "Rustc")
1312
assert_argv_contains(env, action, "test/unit/use_libtest_harness/mytest.rs")
1413
assert_argv_contains(env, action, "--test")

0 commit comments

Comments
 (0)