Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update buildifier #998

Merged
merged 1 commit into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bazelci/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions examples/third_party/cares/cares_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 0 additions & 7 deletions foreign_cc/configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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):
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion foreign_cc/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
76 changes: 1 addition & 75 deletions foreign_cc/private/cc_toolchain_util.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
2 changes: 0 additions & 2 deletions foreign_cc/private/configure_script.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 0 additions & 11 deletions foreign_cc/private/framework.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions foreign_cc/private/framework/helpers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions foreign_cc/private/framework/toolchains/freebsd_commands.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions foreign_cc/private/framework/toolchains/linux_commands.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions foreign_cc/private/framework/toolchains/macos_commands.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions foreign_cc/private/framework/toolchains/windows_commands.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
Loading