diff --git a/.bazelci/config.yaml b/.bazelci/config.yaml index 58bcbd4f5..caf80f5e7 100644 --- a/.bazelci/config.yaml +++ b/.bazelci/config.yaml @@ -215,6 +215,6 @@ tasks: - "--experimental_enable_aggregating_middleman=False" buildifier: - version: "4.2.5" + version: "5.1.0" # keep this argument in sync with .pre-commit-config.yaml warnings: "all" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 34dbc89f0..46ed92d2b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/keith/pre-commit-buildifier - rev: 4.2.3 + rev: 5.1.0.2 hooks: - id: buildifier args: &args diff --git a/examples/third_party/cares/cares_repositories.bzl b/examples/third_party/cares/cares_repositories.bzl index 4ad5a55ee..76db1765f 100644 --- a/examples/third_party/cares/cares_repositories.bzl +++ b/examples/third_party/cares/cares_repositories.bzl @@ -2,14 +2,6 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") -_ALL_CONTENT = """\ -filegroup( - name = "all", - srcs = glob(["**"]), - visibility = ["//visibility:public"], -) -""" - def cares_repositories(): """Load all repositories needed for cares""" maybe( diff --git a/foreign_cc/configure.bzl b/foreign_cc/configure.bzl index 47dd5c659..a9d32b5bc 100644 --- a/foreign_cc/configure.bzl +++ b/foreign_cc/configure.bzl @@ -6,7 +6,6 @@ load( "//foreign_cc/private:cc_toolchain_util.bzl", "get_flags_info", "get_tools_info", - "is_debug_mode", ) load("//foreign_cc/private:configure_script.bzl", "create_configure_script") load("//foreign_cc/private:detect_root.bzl", "detect_root") @@ -19,7 +18,6 @@ load( "expand_locations_and_make_variables", ) load("//foreign_cc/private:transitions.bzl", "foreign_cc_rule_variant") -load("//foreign_cc/private/framework:platform.bzl", "os_name") load("//toolchains/native_tools:tool_access.bzl", "get_make_data", "get_pkgconfig_data") def _configure_make(ctx): @@ -60,8 +58,6 @@ def _create_configure_script(configureParameters): attrs = configureParameters.attrs inputs = configureParameters.inputs - install_prefix = _get_install_prefix(ctx) - tools = get_tools_info(ctx) flags = get_flags_info(ctx) @@ -92,13 +88,10 @@ def _create_configure_script(configureParameters): configure = create_configure_script( workspace_name = ctx.workspace_name, - # as default, pass execution OS as target OS - target_os = os_name(ctx), tools = tools, flags = flags, root = detect_root(ctx.attr.lib_source), user_options = ctx.attr.configure_options, - is_debug = is_debug_mode(ctx), configure_prefix = configure_prefix, configure_command = ctx.attr.configure_command, deps = ctx.attr.deps, diff --git a/foreign_cc/extensions.bzl b/foreign_cc/extensions.bzl index 85af827b5..c189f7848 100644 --- a/foreign_cc/extensions.bzl +++ b/foreign_cc/extensions.bzl @@ -2,7 +2,7 @@ load("//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies") -def _init(module_ctx): +def _init(_): rules_foreign_cc_dependencies(register_toolchains = False, register_preinstalled_tools = False) ext = module_extension(implementation = _init) diff --git a/foreign_cc/private/cc_toolchain_util.bzl b/foreign_cc/private/cc_toolchain_util.bzl index fd7fa4d1f..788c67d70 100644 --- a/foreign_cc/private/cc_toolchain_util.bzl +++ b/foreign_cc/private/cc_toolchain_util.bzl @@ -46,17 +46,6 @@ FOREIGN_CC_DISABLED_FEATURES = [ "thin_lto", ] -def _to_list(element): - if element == None: - return [] - else: - return [element] - -def _to_depset(element): - if element == None: - return depset() - return depset(element) - def _configure_features(ctx, cc_toolchain): return cc_common.configure_features( ctx = ctx, @@ -120,69 +109,6 @@ def _files_map(files_list): def _defines_from_deps(ctx): return depset(transitive = [dep[CcInfo].compilation_context.defines for dep in getattr(ctx.attr, "deps", [])]) -def _build_cc_link_params( - ctx, - user_link_flags, - static_libraries, - dynamic_libraries, - runtime_artifacts): - static_shared = None - static_no_shared = None - if static_libraries != None and len(static_libraries) > 0: - static_shared = cc_common.create_cc_link_params( - ctx = ctx, - user_link_flags = user_link_flags, - libraries_to_link = _to_depset(static_libraries), - ) - static_no_shared = cc_common.create_cc_link_params( - ctx = ctx, - libraries_to_link = _to_depset(static_libraries), - ) - else: - static_shared = cc_common.create_cc_link_params( - ctx = ctx, - user_link_flags = user_link_flags, - libraries_to_link = _to_depset(dynamic_libraries), - dynamic_libraries_for_runtime = _to_depset(runtime_artifacts), - ) - static_no_shared = cc_common.create_cc_link_params( - ctx = ctx, - libraries_to_link = _to_depset(dynamic_libraries), - dynamic_libraries_for_runtime = _to_depset(runtime_artifacts), - ) - - no_static_shared = None - no_static_no_shared = None - if dynamic_libraries != None and len(dynamic_libraries) > 0: - no_static_shared = cc_common.create_cc_link_params( - ctx = ctx, - user_link_flags = user_link_flags, - libraries_to_link = _to_depset(dynamic_libraries), - dynamic_libraries_for_runtime = _to_depset(runtime_artifacts), - ) - no_static_no_shared = cc_common.create_cc_link_params( - ctx = ctx, - libraries_to_link = _to_depset(dynamic_libraries), - dynamic_libraries_for_runtime = _to_depset(runtime_artifacts), - ) - else: - no_static_shared = cc_common.create_cc_link_params( - ctx = ctx, - user_link_flags = user_link_flags, - libraries_to_link = _to_depset(static_libraries), - ) - no_static_no_shared = cc_common.create_cc_link_params( - ctx = ctx, - libraries_to_link = _to_depset(static_libraries), - ) - - return { - "dynamic_mode_params_for_dynamic_library": no_static_shared, - "dynamic_mode_params_for_executable": no_static_no_shared, - "static_mode_params_for_dynamic_library": static_shared, - "static_mode_params_for_executable": static_no_shared, - } - def targets_windows(ctx, cc_toolchain): """Returns true if build is targeting Windows @@ -443,5 +369,5 @@ def _prefix(text, from_str, prefix): return before + prefix + middle + after def _file_name_no_ext(basename): - (before, separator, after) = basename.rpartition(".") + (before, _separator, _after) = basename.rpartition(".") return before diff --git a/foreign_cc/private/configure_script.bzl b/foreign_cc/private/configure_script.bzl index 81b276320..06c516ea5 100644 --- a/foreign_cc/private/configure_script.bzl +++ b/foreign_cc/private/configure_script.bzl @@ -5,12 +5,10 @@ load(":make_script.bzl", "pkgconfig_script") # buildifier: disable=function-docstring def create_configure_script( workspace_name, - target_os, tools, flags, root, user_options, - is_debug, configure_prefix, configure_command, deps, diff --git a/foreign_cc/private/framework.bzl b/foreign_cc/private/framework.bzl index bf37804ef..cf403a932 100644 --- a/foreign_cc/private/framework.bzl +++ b/foreign_cc/private/framework.bzl @@ -671,11 +671,6 @@ def _correct_path_variable(env): env["PATH"] = "$PATH:" + value return env -def _depset(item): - if item == None: - return depset() - return depset([item]) - def _list(item): if item: return [item] @@ -958,12 +953,6 @@ def _collect_libs(cc_linking): libs.append(library) return collections.uniq(libs) -def _expand_command_path(binary, path, command): - if command == binary or command.startswith(binary + " "): - return command.replace(binary, path, 1) - else: - return command - def expand_locations_and_make_variables(ctx, unexpanded, attr_name, data): """Expand locations and make variables while ensuring that `execpath` is always set to an absolute path diff --git a/foreign_cc/private/framework/helpers.bzl b/foreign_cc/private/framework/helpers.bzl index badb84243..479681339 100644 --- a/foreign_cc/private/framework/helpers.bzl +++ b/foreign_cc/private/framework/helpers.bzl @@ -97,7 +97,7 @@ def convert_shell_script_by_context(shell_context, script): # and 4 times is enough for our toolchain. # Example of such function: 'symlink_contents_to_dir'. processed_prelude = {} - for i in range(1, 4): + for _ in range(1, 4): for key in shell_context.prelude.keys(): text = shell_context.prelude[key] lines = text.splitlines() @@ -123,7 +123,7 @@ def replace_var_ref(text, shell_context): parts = [] current = text - for i in range(2147483647): + for _ in range(2147483647): (before, varname, after) = extract_wrapped(current, "$$") if not varname: parts.append(current) @@ -156,7 +156,7 @@ def replace_exports(text, shell_context): # buildifier: disable=function-docstring def get_function_name(text): - (funname, separator, after) = text.partition(" ") + (funname, _, after) = text.partition(" ") if funname == "export": return (funname, after) @@ -198,7 +198,7 @@ def split_arguments(text): parts = [] current = text.strip(" ") - for i in range(1, 2147483647): + for _ in range(1, 2147483647): if not current: break diff --git a/foreign_cc/private/framework/toolchains/freebsd_commands.bzl b/foreign_cc/private/framework/toolchains/freebsd_commands.bzl index 4672b9495..99cc3e589 100644 --- a/foreign_cc/private/framework/toolchains/freebsd_commands.bzl +++ b/foreign_cc/private/framework/toolchains/freebsd_commands.bzl @@ -71,7 +71,7 @@ def define_function(name, text): lines.append("}") return "\n".join(lines) -def replace_in_files(dir, from_, to_): +def replace_in_files(_dir, _from, _to): return FunctionAndCallInfo( text = """\ if [ -d "$1" ]; then @@ -109,7 +109,7 @@ find "{target}" -type f -exec touch -r "{source}" "{{}}" \\; target = target, ) -def symlink_contents_to_dir(source, target, replace_in_files): +def symlink_contents_to_dir(_source, _target, _replace_in_files): text = """\ if [[ -z "$1" ]]; then echo "arg 1 to symlink_contents_to_dir is unexpectedly empty" @@ -139,7 +139,7 @@ fi """ return FunctionAndCallInfo(text = text) -def symlink_to_dir(source, target, replace_in_files): +def symlink_to_dir(_source, _target, _replace_in_files): text = """\ if [[ -z "$1" ]]; then echo "arg 1 to symlink_to_dir is unexpectedly empty" @@ -191,7 +191,7 @@ fi def script_prelude(): return "set -euo pipefail" -def increment_pkg_config_path(source): +def increment_pkg_config_path(_source): text = """\ local children=$(find "$1/" -mindepth 1 -name '*.pc') # assume there is only one directory with pkg config diff --git a/foreign_cc/private/framework/toolchains/linux_commands.bzl b/foreign_cc/private/framework/toolchains/linux_commands.bzl index 138c3f92d..9352d7e68 100644 --- a/foreign_cc/private/framework/toolchains/linux_commands.bzl +++ b/foreign_cc/private/framework/toolchains/linux_commands.bzl @@ -62,7 +62,7 @@ def define_function(name, text): lines.append("}") return "\n".join(lines) -def replace_in_files(dir, from_, to_): +def replace_in_files(_dir, _from, _to): return FunctionAndCallInfo( text = """\ if [ -d "$1" ]; then @@ -91,7 +91,7 @@ def copy_dir_contents_to_dir(source, target): target = target, ) -def symlink_contents_to_dir(source, target, replace_in_files): +def symlink_contents_to_dir(_source, _target, _replace_in_files): text = """\ if [[ -z "$1" ]]; then echo "arg 1 to symlink_contents_to_dir is unexpectedly empty" @@ -121,7 +121,7 @@ fi """ return FunctionAndCallInfo(text = text) -def symlink_to_dir(source, target, replace_in_files): +def symlink_to_dir(_source, _target, _replace_in_files): text = """\ if [[ -z "$1" ]]; then echo "arg 1 to symlink_to_dir is unexpectedly empty" @@ -173,7 +173,7 @@ fi def script_prelude(): return "set -euo pipefail" -def increment_pkg_config_path(source): +def increment_pkg_config_path(_source): text = """\ local children=$(find "$1" -mindepth 1 -name '*.pc') # assume there is only one directory with pkg config diff --git a/foreign_cc/private/framework/toolchains/macos_commands.bzl b/foreign_cc/private/framework/toolchains/macos_commands.bzl index 9138009e1..2fc4b6478 100644 --- a/foreign_cc/private/framework/toolchains/macos_commands.bzl +++ b/foreign_cc/private/framework/toolchains/macos_commands.bzl @@ -62,7 +62,7 @@ def define_function(name, text): lines.append("}") return "\n".join(lines) -def replace_in_files(dir, from_, to_): +def replace_in_files(_dir, _from, _to): return FunctionAndCallInfo( text = """\ if [ -d "$1" ]; then @@ -100,7 +100,7 @@ find "{target}" -type f -exec touch -r "{source}" "{{}}" \\; target = target, ) -def symlink_contents_to_dir(source, target, replace_in_files): +def symlink_contents_to_dir(_source, _target, _replace_in_files): text = """\ if [[ -z "$1" ]]; then echo "arg 1 to symlink_contents_to_dir is unexpectedly empty" @@ -130,7 +130,7 @@ fi """ return FunctionAndCallInfo(text = text) -def symlink_to_dir(source, target, replace_in_files): +def symlink_to_dir(_source, _target, _replace_in_files): text = """\ if [[ -z "$1" ]]; then echo "arg 1 to symlink_to_dir is unexpectedly empty" @@ -182,7 +182,7 @@ fi def script_prelude(): return "set -euo pipefail" -def increment_pkg_config_path(source): +def increment_pkg_config_path(_source): text = """\ local children=$(find "$1/" -mindepth 1 -name '*.pc') # assume there is only one directory with pkg config diff --git a/foreign_cc/private/framework/toolchains/windows_commands.bzl b/foreign_cc/private/framework/toolchains/windows_commands.bzl index 6ca1e02cd..8c8d3515e 100644 --- a/foreign_cc/private/framework/toolchains/windows_commands.bzl +++ b/foreign_cc/private/framework/toolchains/windows_commands.bzl @@ -62,7 +62,7 @@ def define_function(name, text): lines.append("}") return "\n".join(lines) -def replace_in_files(dir, from_, to_): +def replace_in_files(_dir, _from, _to): return FunctionAndCallInfo( text = """\ if [ -d "$1" ]; then @@ -95,7 +95,7 @@ def copy_dir_contents_to_dir(source, target): target = target, ) -def symlink_contents_to_dir(source, target, replace_in_files): +def symlink_contents_to_dir(_source, _target, _replace_in_files): text = """\ if [[ -z "$1" ]]; then echo "arg 1 to symlink_contents_to_dir is unexpectedly empty" @@ -125,7 +125,7 @@ fi """ return FunctionAndCallInfo(text = text) -def symlink_to_dir(source, target, replace_in_files): +def symlink_to_dir(_source, _target, _replace_in_files): text = """\ if [[ -z "$1" ]]; then echo "arg 1 to symlink_to_dir is unexpectedly empty" @@ -187,7 +187,7 @@ export MSYS2_ARG_CONV_EXCL="*" export SYSTEMDRIVE="C:" """ -def increment_pkg_config_path(source): +def increment_pkg_config_path(_source): text = """\ local children=$($REAL_FIND "$1" -mindepth 1 -name '*.pc') # assume there is only one directory with pkg config diff --git a/test/convert_shell_script_test.bzl b/test/convert_shell_script_test.bzl index 4a03701ab..88ff647fd 100644 --- a/test/convert_shell_script_test.bzl +++ b/test/convert_shell_script_test.bzl @@ -131,7 +131,7 @@ def _do_function_call_test(ctx): return unittest.end(env) -def _touch(path): +def _touch(_path): text = "call_touch $1" return FunctionAndCallInfo(text = text) @@ -196,7 +196,7 @@ fi return unittest.end(env) -def _symlink_contents_to_dir(source, target, replace_in_files): +def _symlink_contents_to_dir(_source, _target, _replace_in_files): text = """local target="$2" mkdir -p $target local replace_in_files="${3:-}" @@ -212,7 +212,7 @@ done """ return FunctionAndCallInfo(text = text) -def _symlink_to_dir(source, target, replace_in_files): +def _symlink_to_dir(_source, _target, _replace_in_files): text = """local target="$2" mkdir -p ${target} diff --git a/toolchains/prebuilt_toolchains.bzl b/toolchains/prebuilt_toolchains.bzl index dabfb957a..547468ef7 100644 --- a/toolchains/prebuilt_toolchains.bzl +++ b/toolchains/prebuilt_toolchains.bzl @@ -4636,6 +4636,6 @@ def _ninja_toolchains(version, register_toolchains): fail("Unsupported version: " + str(version)) -def _make_toolchains(register_toolchains): +def _make_toolchains(_): # There are currently no prebuilt make binaries pass