diff options
32 files changed, 68 insertions, 86 deletions
diff --git a/buildifier_hook.sh b/buildifier_hook.sh index 0e75abe1..95742724 100755 --- a/buildifier_hook.sh +++ b/buildifier_hook.sh @@ -1,2 +1,2 @@ #!/bin/bash -[[ ! $(command -v buildifier) ]] || buildifier -mode=check -lint=warn -warnings="out-of-order-load,load-on-top,load" `printf "%s\n" $@ | grep -E "^(BUILD|BUILD.bazel|bazel.WORKSPACE|.*\\.bzl)$"` < /dev/null +[[ ! $(command -v buildifier) ]] || buildifier -mode=check -lint=warn -warnings="out-of-order-load,load-on-top,load,unused-variable,list-append" `printf "%s\n" $@ | grep -E "^(BUILD|BUILD.bazel|bazel.WORKSPACE|.*\\.bzl)$"` < /dev/null diff --git a/platforms/arch/variants/constants.bzl b/platforms/arch/variants/constants.bzl index 2207fc56..6b096323 100644 --- a/platforms/arch/variants/constants.bzl +++ b/platforms/arch/variants/constants.bzl @@ -52,7 +52,7 @@ def power_set(items, *, include_empty = True): def _exp(x, y): result = 1 - for i in range(y): + for _ in range(y): result *= x return result diff --git a/platforms/platform_utils.bzl b/platforms/platform_utils.bzl index 8f8ba447..556aa75f 100644 --- a/platforms/platform_utils.bzl +++ b/platforms/platform_utils.bzl @@ -137,6 +137,7 @@ def _get_target_arch(utils): platforms = struct( is_target_linux = _is_target_linux, is_target_android = _is_target_android, + is_target_bionic = _is_target_bionic, is_target_darwin = _is_target_darwin, is_target_linux_or_android = _is_target_linux_or_android, is_target_x86 = _is_target_x86, diff --git a/rules/abi/abi_dump.bzl b/rules/abi/abi_dump.bzl index 1dddd05d..745a9c0b 100644 --- a/rules/abi/abi_dump.bzl +++ b/rules/abi/abi_dump.bzl @@ -46,8 +46,6 @@ def _abi_dump_aspect_impl(target, ctx): transitive_dumps = [] direct_dumps = [] - transitive_paths = [] - direct_paths = [] if CcStaticLibraryInfo in target: direct_dumps.extend(_create_abi_dumps( @@ -220,7 +218,7 @@ def create_linked_abi_dump(ctx, dump_files): return output -def find_abi_config(ctx): +def find_abi_config(_ctx): sdk_version = str(product_vars["Platform_sdk_version"]) prev_version = int(parse_apex_sdk_version(sdk_version)) version = "current" diff --git a/rules/abi/abi_dump_test.bzl b/rules/abi/abi_dump_test.bzl index d13cd66f..87874331 100644 --- a/rules/abi/abi_dump_test.bzl +++ b/rules/abi/abi_dump_test.bzl @@ -230,8 +230,6 @@ def _test_abi_linker_action(): def _abi_linker_action_run_test_impl(ctx): env = analysistest.begin(ctx) - bin_home = analysistest.target_bin_dir_path(env) - bazel_out_base = paths.join(bin_home, ctx.label.package) actions = analysistest.target_actions(env) link_actions = [a for a in actions if a.mnemonic == "AbiLink"] @@ -276,8 +274,6 @@ def _test_abi_linker_action_run_for_enabled(): def _abi_linker_action_not_run_test_impl(ctx): env = analysistest.begin(ctx) - bin_home = analysistest.target_bin_dir_path(env) - bazel_out_base = paths.join(bin_home, ctx.label.package) actions = analysistest.target_actions(env) link_actions = [a for a in actions if a.mnemonic == "AbiLink"] diff --git a/rules/android/android_library.bzl b/rules/android/android_library.bzl index d8239c7c..7c1049bb 100644 --- a/rules/android/android_library.bzl +++ b/rules/android/android_library.bzl @@ -141,10 +141,17 @@ ATTRS = _attrs.add( KT_COMPILER_ATTRS, ) -def _validations_processor(ctx, **unused_sub_ctxs): +def _validations_processor(ctx, **_unused_sub_ctxs): utils.check_for_failures(ctx.label, ctx.attr.deps, ctx.attr.exports) -def _process_jvm(ctx, java_package, exceptions_ctx, resources_ctx, idl_ctx, db_ctx, **unused_sub_ctxs): +def _process_jvm( + ctx, + java_package, # @unused + exceptions_ctx, # @unused + resources_ctx, + idl_ctx, + db_ctx, + **_unused_sub_ctxs): # Filter out disallowed sources. srcs = ctx.files.srcs + idl_ctx.idl_java_srcs + db_ctx.java_srcs diff --git a/rules/apex/apex.bzl b/rules/apex/apex.bzl index 0391800e..e2b233b9 100644 --- a/rules/apex/apex.bzl +++ b/rules/apex/apex.bzl @@ -299,7 +299,7 @@ def _generate_installed_files_list(ctx, file_mapping): return installed_files def _generate_notices(ctx, apex_toolchain): - licensees = license_map(ctx, ctx.attr.binaries + ctx.attr.prebuilts + ctx.attr.native_shared_libs_32 + ctx.attr.native_shared_libs_64) + licensees = license_map(ctx.attr.binaries + ctx.attr.prebuilts + ctx.attr.native_shared_libs_32 + ctx.attr.native_shared_libs_64) licenses_file = ctx.actions.declare_file(ctx.attr.name + "_licenses.json") ctx.actions.write(licenses_file, "[\n%s\n]\n" % ",\n".join(license_map_to_json(licensees))) diff --git a/rules/apex/apex_aab.bzl b/rules/apex/apex_aab.bzl index cd3bf996..8550c937 100644 --- a/rules/apex/apex_aab.bzl +++ b/rules/apex/apex_aab.bzl @@ -23,7 +23,6 @@ def _arch_transition_impl(settings, _attr): Six arch products are included for mainline modules: x86, x86_64, x86_64only, arm, arm64, arm64only. """ old_platform = str(settings["//command_line_option:platforms"][0]) - device_secondary_arch = settings["//build/bazel/rules/apex:device_secondary_arch"] # We can't use platforms alone to differentiate between x86_64 and x86_64 # with a secondary arch, which is significant for apex packaging that can diff --git a/rules/apis/cc_api_contribution.bzl b/rules/apis/cc_api_contribution.bzl index c729a7c5..ca5ac37a 100644 --- a/rules/apis/cc_api_contribution.bzl +++ b/rules/apis/cc_api_contribution.bzl @@ -123,7 +123,7 @@ def _header_target_name(name, include_dir): def cc_api_library_headers( name, - hdrs = [], + hdrs = [], # @unused export_includes = [], export_system_includes = [], arch = None, diff --git a/rules/cc/cc_binary.bzl b/rules/cc/cc_binary.bzl index 048f1fe0..09ccd598 100644 --- a/rules/cc/cc_binary.bzl +++ b/rules/cc/cc_binary.bzl @@ -40,8 +40,8 @@ def cc_binary( whole_archive_deps = [], system_deps = None, runtime_deps = [], - export_includes = [], - export_system_includes = [], + export_includes = [], # @unused + export_system_includes = [], # @unused local_includes = [], absolute_includes = [], linkshared = True, @@ -54,7 +54,7 @@ def cc_binary( strip = {}, features = [], target_compatible_with = [], - sdk_version = "", + sdk_version = "", # @unused min_sdk_version = "", use_version_lib = False, tags = [], @@ -80,7 +80,7 @@ def cc_binary( toolchain_features.extend(["-dynamic_executable", "-dynamic_linker", "static_executable", "static_flag"]) if not use_libcrt: - toolchain_features += ["-use_libcrt"] + toolchain_features.append("-use_libcrt") if min_sdk_version: toolchain_features += parse_sdk_version(min_sdk_version) + ["-sdk_version_default"] @@ -100,7 +100,7 @@ def cc_binary( system_static_deps = system_deps if not native_coverage: - toolchain_features += ["-coverage"] + toolchain_features.append("-coverage") else: toolchain_features += select({ "//build/bazel/rules/cc:android_coverage_lib_flag": ["android_coverage_lib"], diff --git a/rules/cc/cc_binary_test.bzl b/rules/cc/cc_binary_test.bzl index 3bae81da..eb6e31b8 100644 --- a/rules/cc/cc_binary_test.bzl +++ b/rules/cc/cc_binary_test.bzl @@ -81,25 +81,6 @@ def _cc_binary_strip_default(): return test_name -def _cc_binary_strip_none(): - name = "cc_binary_strip_none" - test_name = name + "_test" - - cc_binary( - name = name, - srcs = ["main.cc"], - tags = ["manual"], - strip = {"none": True}, - ) - - cc_binary_strip_test( - name = test_name, - target_under_test = name, - strip_flags = [], - ) - - return test_name - def _cc_binary_strip_keep_symbols(): name = "cc_binary_strip_keep_symbols" test_name = name + "_test" diff --git a/rules/cc/cc_constants.bzl b/rules/cc/cc_constants.bzl index fb3d01f8..f5605b8f 100644 --- a/rules/cc/cc_constants.bzl +++ b/rules/cc/cc_constants.bzl @@ -27,10 +27,6 @@ _HDR_EXTS_WITH_DOT = ["." + ext for ext in _HDR_EXTS] _SRC_EXTS_WITH_DOT = ["." + ext for ext in _SRC_EXTS] _ALL_EXTS_WITH_DOT = ["." + ext for ext in _ALL_EXTS] -# These are root-relative. -_GLOBAL_INCLUDE_DIRS_COPTS_ONLY_USED_FOR_SOONG_COMPATIBILITY_DO_NOT_ADD_MORE = [ - "/", -] constants = struct( hdr_exts = _HDR_EXTS, c_src_exts = _C_SRC_EXTS, diff --git a/rules/cc/cc_hidl_library_test.bzl b/rules/cc/cc_hidl_library_test.bzl index 633da714..73b69f74 100644 --- a/rules/cc/cc_hidl_library_test.bzl +++ b/rules/cc/cc_hidl_library_test.bzl @@ -47,7 +47,6 @@ INTERFACE_VERSION_1_1 = "1.1" def _cc_code_gen_test_impl(ctx): env = analysistest.begin(ctx) - target_under_test = analysistest.target_under_test(env) actions = analysistest.target_actions(env) package_root = paths.dirname(ctx.build_file_path) header_gen_actions = [a for a in actions if a.mnemonic == "HidlGenCcHeader"] diff --git a/rules/cc/cc_library_common.bzl b/rules/cc/cc_library_common.bzl index c0659266..164d6629 100644 --- a/rules/cc/cc_library_common.bzl +++ b/rules/cc/cc_library_common.bzl @@ -195,7 +195,7 @@ def create_ccinfo_for_includes( # Combine this target's compilation context with those of the deps; use only # the compilation context of the combined CcInfo. cc_infos = [dep[CcInfo] for dep in deps] - cc_infos += [CcInfo(compilation_context = compilation_context)] + cc_infos.append(CcInfo(compilation_context = compilation_context)) combined_info = cc_common.merge_cc_infos(cc_infos = cc_infos) return CcInfo(compilation_context = combined_info.compilation_context) diff --git a/rules/cc/cc_library_shared.bzl b/rules/cc/cc_library_shared.bzl index 5b8d33be..7b50eafc 100644 --- a/rules/cc/cc_library_shared.bzl +++ b/rules/cc/cc_library_shared.bzl @@ -79,11 +79,11 @@ def cc_library_shared( strip = {}, # TODO(b/202299295): Handle data attribute. - data = [], + data = [], # @unused use_version_lib = False, stubs_symbol_file = None, inject_bssl_hash = False, - sdk_version = "", + sdk_version = "", # @unused min_sdk_version = "", abi_checker_enabled = None, abi_checker_symbol_file = None, diff --git a/rules/cc/cc_library_static.bzl b/rules/cc/cc_library_static.bzl index a025fa0a..e81a1fe3 100644 --- a/rules/cc/cc_library_static.bzl +++ b/rules/cc/cc_library_static.bzl @@ -53,7 +53,7 @@ def cc_library_static( local_includes = [], absolute_includes = [], hdrs = [], - native_bridge_supported = False, # TODO: not supported yet. + native_bridge_supported = False, # TODO: not supported yet. @unused rtti = False, stl = "", cpp_std = "", @@ -74,8 +74,8 @@ def cc_library_static( alwayslink = None, target_compatible_with = [], # TODO(b/202299295): Handle data attribute. - data = [], - sdk_version = "", + data = [], # @unused + sdk_version = "", # @unused min_sdk_version = "", tags = [], tidy = None, @@ -110,7 +110,7 @@ def cc_library_static( ] if rtti: - toolchain_features += ["rtti"] + toolchain_features.append("rtti") if cpp_std: toolchain_features += [cpp_std, "-cpp_std_default"] if c_std: @@ -121,7 +121,7 @@ def cc_library_static( toolchain_features += features if not native_coverage: - toolchain_features += ["-coverage"] + toolchain_features += ["-coverage"] # buildifier: disable=list-append This could be a select, not a list if system_dynamic_deps == None: system_dynamic_deps = system_dynamic_deps_defaults diff --git a/rules/cc/cc_object.bzl b/rules/cc/cc_object.bzl index ba440b44..f5cdb8d9 100644 --- a/rules/cc/cc_object.bzl +++ b/rules/cc/cc_object.bzl @@ -48,11 +48,11 @@ def split_srcs_hdrs(files): non_headers_c = [] for f in files: if f.extension in constants.hdr_exts: - headers += [f] + headers.append(f) elif f.extension in constants.as_src_exts: - non_headers_as += [f] + non_headers_as.append(f) else: - non_headers_c += [f] + non_headers_c.append(f) return non_headers_c, non_headers_as, headers def _cc_object_impl(ctx): @@ -223,7 +223,7 @@ def cc_object( srcs_as = [], objs = [], deps = [], - native_bridge_supported = False, # TODO: not supported yet. + native_bridge_supported = False, # TODO: not supported yet. @unused stl = "", system_dynamic_deps = None, sdk_version = "", diff --git a/rules/cc/cc_prebuilt_library_static.bzl b/rules/cc/cc_prebuilt_library_static.bzl index 4276ebca..1981fbf7 100644 --- a/rules/cc/cc_prebuilt_library_static.bzl +++ b/rules/cc/cc_prebuilt_library_static.bzl @@ -15,8 +15,8 @@ def cc_prebuilt_library_static( name, static_library, - export_includes = [], - export_system_includes = [], + export_includes = [], # @unused + export_system_includes = [], # @unused **kwargs): "Bazel macro to correspond with the *_cc_prebuilt_library_static Soong module types" diff --git a/rules/cc/cc_stub_library.bzl b/rules/cc/cc_stub_library.bzl index abcd28c8..eabc1f84 100644 --- a/rules/cc/cc_stub_library.bzl +++ b/rules/cc/cc_stub_library.bzl @@ -227,7 +227,18 @@ _cc_stub_library_shared = rule( }, ) -def cc_stub_suite(name, source_library_label, versions, symbol_file, export_includes = [], soname = "", deps = [], data = [], target_compatible_with = [], features = [], tags = ["manual"]): +def cc_stub_suite( + name, + source_library_label, + versions, + symbol_file, + export_includes = [], + soname = "", + deps = [], + data = [], # @unused + target_compatible_with = [], + features = [], + tags = ["manual"]): # Implicitly add "current" to versions. This copies the behavior from Soong (aosp/1641782) if "current" not in versions: versions.append("current") diff --git a/rules/cc/cc_sysprop_library.bzl b/rules/cc/cc_sysprop_library.bzl index 1415d2ce..b400127d 100644 --- a/rules/cc/cc_sysprop_library.bzl +++ b/rules/cc/cc_sysprop_library.bzl @@ -43,7 +43,7 @@ def _cc_gen_sysprop_impl(ctx): output_src_file = ctx.actions.declare_file( "sysprop/%s.cpp" % output_subpath, ) - action_outputs += [output_src_file] + action_outputs.append(output_src_file) output_header_file = ctx.actions.declare_file( "sysprop/include/%s.h" % output_subpath, diff --git a/rules/cc/cc_test.bzl b/rules/cc/cc_test.bzl index b6a11396..4ed1d58a 100644 --- a/rules/cc/cc_test.bzl +++ b/rules/cc/cc_test.bzl @@ -54,7 +54,7 @@ def cc_test( deps = [], dynamic_deps = [], gtest = True, - isolated = True, # TODO(b/244432609): currently no-op. + isolated = True, # TODO(b/244432609): currently no-op. @unused tags = [], tidy = None, tidy_checks = None, diff --git a/rules/cc/flex.bzl b/rules/cc/flex.bzl index 28849599..636188bc 100644 --- a/rules/cc/flex.bzl +++ b/rules/cc/flex.bzl @@ -72,7 +72,7 @@ def _genlex_impl(ctx): elif src_ext == "ll": output_filename = paths.replace_extension(filename_without_ext, ".cc") output_file = ctx.actions.declare_file(output_filename) - outputs += [output_file] + outputs.append(output_file) args.add("-o", output_file.path) args.add_all(ctx.attr.lexopts) diff --git a/rules/cc/stripped_cc_common.bzl b/rules/cc/stripped_cc_common.bzl index 5d4b8668..b053330f 100644 --- a/rules/cc/stripped_cc_common.bzl +++ b/rules/cc/stripped_cc_common.bzl @@ -14,7 +14,6 @@ """A macro to handle shared library stripping.""" -load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain") load(":cc_library_common.bzl", "CcAndroidMkInfo") load(":clang_tidy.bzl", "collect_deps_clang_tidy_info") @@ -39,17 +38,17 @@ def _get_strip_args(attrs): strip_args = [] keep_mini_debug_info = False if attrs.keep_symbols: - strip_args += ["--keep-symbols"] + strip_args.append("--keep-symbols") elif attrs.keep_symbols_and_debug_frame: - strip_args += ["--keep-symbols-and-debug-frame"] + strip_args.append("--keep-symbols-and-debug-frame") elif attrs.keep_symbols_list: - strip_args += ["-k" + ",".join(attrs.keep_symbols_list)] + strip_args.append("-k" + ",".join(attrs.keep_symbols_list)) elif not attrs.all: - strip_args += ["--keep-mini-debug-info"] + strip_args.append("--keep-mini-debug-info") keep_mini_debug_info = True if not keep_mini_debug_info: - strip_args += ["--add-gnu-debuglink"] + strip_args.append("--add-gnu-debuglink") return strip_args @@ -62,7 +61,6 @@ def stripped_impl(ctx, prefix = "", suffix = "", extension = ""): target_file = ctx.files.src[0], ) return out_file - cc_toolchain = find_cpp_toolchain(ctx) d_file = ctx.actions.declare_file(ctx.attr.name + ".d") ctx.actions.run( env = { diff --git a/rules/filegroup.bzl b/rules/filegroup.bzl index 1c927e73..f1ab826e 100644 --- a/rules/filegroup.bzl +++ b/rules/filegroup.bzl @@ -26,11 +26,11 @@ def group_files_by_ext(files): # configurable selects. for f in files: if extension(f) in constants.c_src_exts: - c += [f] + c.append(f) elif extension(f) in constants.cpp_src_exts: - cpp += [f] + cpp.append(f) elif extension(f) in constants.as_src_exts: - asm += [f] + asm.append(f) else: # not C based continue diff --git a/rules/kotlin/rules.bzl b/rules/kotlin/rules.bzl index 944f6077..2a5c7c98 100644 --- a/rules/kotlin/rules.bzl +++ b/rules/kotlin/rules.bzl @@ -13,13 +13,13 @@ # limitations under the License. load( - ":kt_jvm_library.bzl", - _kt_jvm_library = "kt_jvm_library", -) -load( "@rules_kotlin//kotlin:compiler_opt.bzl", _kt_compiler_opt = "kt_compiler_opt", ) +load( + ":kt_jvm_library.bzl", + _kt_jvm_library = "kt_jvm_library", +) kt_jvm_library = _kt_jvm_library -kt_compiler_opt = _kt_jvm_library +kt_compiler_opt = _kt_compiler_opt diff --git a/rules/license/license_aspect.bzl b/rules/license/license_aspect.bzl index e6e06167..87481420 100644 --- a/rules/license/license_aspect.bzl +++ b/rules/license/license_aspect.bzl @@ -14,7 +14,7 @@ def _maybe_expand(rule, transitive_licenses): if hasattr(dep_info, "license_closure"): transitive_licenses.append(dep_info.license_closure) -def _rule_licenses_aspect_impl(rule, ctx): +def _rule_licenses_aspect_impl(_rule, ctx): if ctx.rule.kind == "_license": return RuleLicensedDependenciesInfo() @@ -66,13 +66,12 @@ def _divine_package_name(license): return license.package_name return license.rule.name.removeprefix("external_").removesuffix("_license").replace("_", " ") -def license_map(ctx, deps): +def license_map(deps): """Collects license to licensees map for the given set of rule targets. TODO(asmundak): at the moment licensees lists are all empty because collecting the licensees turned out to be too slow. Restore this later. Args: - ctx:context deps: list of rule targets Returns: dictionary mapping a license to its licensees diff --git a/rules/partitions/installable_info.bzl b/rules/partitions/installable_info.bzl index 178ef8b0..3e88e351 100644 --- a/rules/partitions/installable_info.bzl +++ b/rules/partitions/installable_info.bzl @@ -21,7 +21,7 @@ InstallableInfo = provider( }, ) -def _installable_aspect_impl(target, ctx): +def _installable_aspect_impl(target, _ctx): installed_files = {} if ApexInfo in target: apex = target[ApexInfo].signed_output diff --git a/rules/prebuilt_file.bzl b/rules/prebuilt_file.bzl index 14722aac..1e375a5c 100644 --- a/rules/prebuilt_file.bzl +++ b/rules/prebuilt_file.bzl @@ -84,7 +84,7 @@ def prebuilt_file( # TODO(b/207489266): Fully support; # data is currently dropped to prevent breakages from e.g. prebuilt_etc filename_from_src = False, - data = [], + data = [], # @unused **kwargs): "Bazel macro to correspond with the e.g. prebuilt_etc and prebuilt_usr_share Soong modules." diff --git a/rules/prebuilt_xml.bzl b/rules/prebuilt_xml.bzl index 13f7ba7e..bb627f17 100644 --- a/rules/prebuilt_xml.bzl +++ b/rules/prebuilt_xml.bzl @@ -14,8 +14,6 @@ load(":prebuilt_file.bzl", "PrebuiltFileInfo") -_handled_dir = ["etc"] - def _prebuilt_xml_impl(ctx): schema = ctx.file.schema diff --git a/tests/apex/apex_aab_test.bzl b/tests/apex/apex_aab_test.bzl index e0b8d551..f88a6df6 100644 --- a/tests/apex/apex_aab_test.bzl +++ b/tests/apex/apex_aab_test.bzl @@ -14,7 +14,7 @@ load("//build/bazel/rules/apex:apex_aab.bzl", "apex_aab") -def apex_aab_test(name, apex, golden, **kwargs): +def apex_aab_test(name, apex, golden): """Diff the .aab generated by Bazel and Soong""" aab_name = name + "_apex_aab" diff --git a/tests/apex/apex_compression_test.bzl b/tests/apex/apex_compression_test.bzl index 923a1222..4a5f1246 100644 --- a/tests/apex/apex_compression_test.bzl +++ b/tests/apex/apex_compression_test.bzl @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -def apex_compression_test(name, apex, compressed, **kwargs): +def apex_compression_test(name, apex, compressed): """This verifies APEX or compressed APEX file: 1) has the correct file extension name 2) contains the required files specified by the APEX file format diff --git a/tests/partitions/image_contents_test.bzl b/tests/partitions/image_contents_test.bzl index b050b7e5..06cf868f 100644 --- a/tests/partitions/image_contents_test.bzl +++ b/tests/partitions/image_contents_test.bzl @@ -6,7 +6,6 @@ def image_contents_test( path, expected, target_compatible_with = None, - expected_diff = None, tags = []): """A test that extracts a file from a disk image file, and then asserts that it's identical to some other file.""" |