Skip to content

Commit

Permalink
Enable buildifier for CI (#440)
Browse files Browse the repository at this point in the history
  • Loading branch information
UebelAndre committed Oct 15, 2020
1 parent fb90a74 commit 9279938
Show file tree
Hide file tree
Showing 22 changed files with 37 additions and 16 deletions.
3 changes: 1 addition & 2 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,4 @@ tasks:
shell_commands:
- ./test/clippy/clippy_failure_test.sh

# TODO: Fix all buildifier defects then enable buildifier in CI
# buildifier: latest
buildifier: latest
1 change: 1 addition & 0 deletions bindgen/bindgen.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# buildifier: disable=module-docstring
load("@io_bazel_rules_rust//rust:private/legacy_cc_starlark_api_shim.bzl", "get_libs_for_static_executable")
load("@io_bazel_rules_rust//rust:private/utils.bzl", "find_toolchain")
load("@io_bazel_rules_rust//rust:rust.bzl", "rust_library")
Expand Down
1 change: 1 addition & 0 deletions bindgen/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# buildifier: disable=module-docstring
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("//bindgen/raze:crates.bzl", "rules_rust_bindgen_fetch_remote_crates")
Expand Down
1 change: 1 addition & 0 deletions cargo/cargo_build_script.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# buildifier: disable=module-docstring
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
load("@io_bazel_rules_rust//rust:private/rustc.bzl", "BuildInfo", "DepInfo", "get_cc_compile_env", "get_cc_toolchain", "get_compilation_mode_opts", "get_linker_and_args")
load("@io_bazel_rules_rust//rust:private/utils.bzl", "find_toolchain")
Expand Down
1 change: 0 additions & 1 deletion docs/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ PAGES = {
],
"rust_workspace": [
"rust_workspace",
"bazel_version",
],
}

Expand Down
1 change: 1 addition & 0 deletions docs/all.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# buildifier: disable=module-docstring
load(
"@io_bazel_rules_rust//rust:toolchain.bzl",
_rust_toolchain = "rust_toolchain",
Expand Down
2 changes: 2 additions & 0 deletions docs/rules_proto_stub/proto/defs.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# buildifier: disable=module-docstring
# buildifier: disable=provider-params
ProtoInfo = provider()

def proto_library(**args):
Expand Down
1 change: 1 addition & 0 deletions proto/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# buildifier: disable=module-docstring
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("//proto/raze:crates.bzl", "rules_rust_proto_fetch_remote_crates")
Expand Down
1 change: 1 addition & 0 deletions rust/known_shas.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# buildifier: disable=module-docstring
# This is a generated file -- see //util:fetch_shas.sh
FILE_KEY_TO_SHA = {
"2018-10-30/rust-beta-x86_64-apple-darwin": "51acc0077d6abae5beed0e7b99c39ae9b8a0ff0f66daec227caef653046144e6",
Expand Down
1 change: 1 addition & 0 deletions rust/private/clippy.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# buildifier: disable=module-docstring
load(
"@io_bazel_rules_rust//rust:private/rustc.bzl",
"CrateInfo",
Expand Down
1 change: 1 addition & 0 deletions rust/private/dummy_cc_toolchain/dummy_cc_toolchain.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# buildifier: disable=module-docstring
def _dummy_cc_toolchain_impl(ctx):
# The `all_files` attribute is referenced by rustc_compile_action().
return [platform_common.ToolchainInfo(all_files = depset([]))]
Expand Down
1 change: 1 addition & 0 deletions rust/private/rust.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# buildifier: disable=module-docstring
load("@io_bazel_rules_rust//rust:private/rustc.bzl", "CrateInfo", "rustc_compile_action")
load("@io_bazel_rules_rust//rust:private/utils.bzl", "determine_output_hash", "find_toolchain")

Expand Down
24 changes: 13 additions & 11 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# buildifier: disable=module-docstring
load("@bazel_skylib//lib:versions.bzl", "versions")
load(
"@bazel_tools//tools/build_defs/cc:action_names.bzl",
Expand Down Expand Up @@ -165,30 +166,31 @@ def collect_deps(label, deps, proc_macro_deps, aliases, toolchain):
if CrateInfo in dep:
# This dependency is a rust_library
direct_dep = dep[CrateInfo]
aliasable_dep = AliasableDepInfo(
direct_crates.append(AliasableDepInfo(
name = aliases.get(dep.label, direct_dep.name),
dep = direct_dep,
)
direct_crates.append(aliasable_dep)
transitive_crates = depset([dep[CrateInfo]], transitive = [transitive_crates])
transitive_crates = depset(transitive = [transitive_crates, dep[DepInfo].transitive_crates])
transitive_dylibs = depset(transitive = [transitive_dylibs, dep[DepInfo].transitive_dylibs])
transitive_staticlibs = depset(transitive = [transitive_staticlibs, dep[DepInfo].transitive_staticlibs])
transitive_build_infos = depset(transitive = [transitive_build_infos, dep[DepInfo].transitive_build_infos])
))

# TODO (bazelbuild/rules_rust#442): Solve for all overly-nested-depset warnings here
transitive_crates = depset([dep[CrateInfo]], transitive = [transitive_crates]) # buildifier: disable=overly-nested-depset
transitive_crates = depset(transitive = [transitive_crates, dep[DepInfo].transitive_crates]) # buildifier: disable=overly-nested-depset
transitive_dylibs = depset(transitive = [transitive_dylibs, dep[DepInfo].transitive_dylibs]) # buildifier: disable=overly-nested-depset
transitive_staticlibs = depset(transitive = [transitive_staticlibs, dep[DepInfo].transitive_staticlibs]) # buildifier: disable=overly-nested-depset
transitive_build_infos = depset(transitive = [transitive_build_infos, dep[DepInfo].transitive_build_infos]) # buildifier: disable=overly-nested-depset
elif CcInfo in dep:
# This dependency is a cc_library

# TODO: We could let the user choose how to link, instead of always preferring to link static libraries.
libs = get_libs_for_static_executable(dep)
dylibs = [lib for lib in libs.to_list() if lib.basename.endswith(toolchain.dylib_ext)]
staticlibs = [lib for lib in libs.to_list() if lib.basename.endswith(toolchain.staticlib_ext)]
transitive_dylibs = depset(transitive = [transitive_dylibs, depset(dylibs)])
transitive_staticlibs = depset(transitive = [transitive_staticlibs, depset(staticlibs)])
transitive_dylibs = depset(transitive = [transitive_dylibs, depset(dylibs)]) # buildifier: disable=overly-nested-depset
transitive_staticlibs = depset(transitive = [transitive_staticlibs, depset(staticlibs)]) # buildifier: disable=overly-nested-depset
elif BuildInfo in dep:
if build_info:
fail("Several deps are providing build information, only one is allowed in the dependencies", "deps")
build_info = dep[BuildInfo]
transitive_build_infos = depset([build_info], transitive = [transitive_build_infos])
transitive_build_infos = depset([build_info], transitive = [transitive_build_infos]) # buildifier: disable=overly-nested-depset
else:
fail("rust targets can only depend on rust_library, rust_*_library or cc_library targets." + str(dep), "deps")

Expand Down
1 change: 1 addition & 0 deletions rust/private/rustdoc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# buildifier: disable=module-docstring
load("@io_bazel_rules_rust//rust:private/rustc.bzl", "CrateInfo", "DepInfo", "add_crate_link_flags", "add_edition_flags")
load("@io_bazel_rules_rust//rust:private/utils.bzl", "find_toolchain")

Expand Down
1 change: 1 addition & 0 deletions rust/private/rustdoc_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# buildifier: disable=module-docstring
load("@io_bazel_rules_rust//rust:private/rustc.bzl", "CrateInfo", "DepInfo")
load("@io_bazel_rules_rust//rust:private/utils.bzl", "find_toolchain", "get_lib_name")

Expand Down
1 change: 1 addition & 0 deletions rust/private/transitions.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# buildifier: disable=module-docstring
def _wasm_bindgen_transition(settings, attr):
"""The implementation of the `wasm_bindgen_transition` transition
Expand Down
1 change: 1 addition & 0 deletions rust/repositories.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# buildifier: disable=module-docstring
load(":known_shas.bzl", "FILE_KEY_TO_SHA")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
Expand Down
1 change: 1 addition & 0 deletions rust/rust.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# buildifier: disable=module-docstring
load(
"@io_bazel_rules_rust//rust:private/rust.bzl",
_rust_benchmark = "rust_benchmark",
Expand Down
3 changes: 2 additions & 1 deletion test/rustfmt/rustfmt_generator.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# buildifier: disable=module-docstring
load("@io_bazel_rules_rust//rust:private/utils.bzl", "find_toolchain")

def _rustfmt_generator_impl(ctx):
Expand All @@ -23,7 +24,7 @@ def _rustfmt_generator_impl(ctx):
)

rustfmt_generator = rule(
_rustfmt_generator_impl,
implementation = _rustfmt_generator_impl,
doc = "Given an unformatted Rust source file, output the file after being run through rustfmt.",
attrs = {
"src": attr.label(
Expand Down
1 change: 1 addition & 0 deletions wasm_bindgen/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# buildifier: disable=module-docstring
load("//wasm_bindgen/raze:crates.bzl", "rules_rust_wasm_bindgen_fetch_remote_crates")

# buildifier: disable=unnamed-macro
Expand Down
4 changes: 3 additions & 1 deletion wasm_bindgen/wasm_bindgen.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# buildifier: disable=module-docstring
load("@io_bazel_rules_rust//rust:private/transitions.bzl", "wasm_bindgen_transition")

def _rust_wasm_bindgen_impl(ctx):
Expand All @@ -38,8 +39,9 @@ def _rust_wasm_bindgen_impl(ctx):
arguments = [args],
)

# TODO: Legacy provider syntax should be updated. See the following guide:
# TODO (bazelbuild/rules_rust#443): Legacy provider syntax should be updated. See the following guide:
# https://docs.bazel.build/versions/master/skylark/rules.html#migrating-from-legacy-providers
# buildifier: disable=rule-impl-return
return struct(
providers = [
DefaultInfo(
Expand Down
1 change: 1 addition & 0 deletions workspace.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# buildifier: disable=module-docstring
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
load("@bazel_skylib//lib:versions.bzl", "versions")

Expand Down

0 comments on commit 9279938

Please sign in to comment.