bazelbuild / buildtools

A bazel BUILD file formatter and editor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

buildifier set up via Bazel uses much older buildifier binary

tetsuok opened this issue · comments

Buildifier's README.md documents how to setup the latest buildifier via Bazel, but it seems that's not true. When buildifier is invoked via the Bazel rule, it warns the use of native rules where the warnings were disabled in #952. If the latest version is used, the tool should not report the warning.

Below is a BUILD file and the output of buildifier via the Bazel rule:

$ bazel --version
bazel 4.2.1
$ cat BUILD
load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier")

buildifier(
    name = "buildifier",
    lint_mode = "warn",
)

cc_binary(
    name = "hello",
    srcs = ["hello.cc"],
)
$ bazel run //:buildifier
INFO: Analyzed target //:buildifier (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //:buildifier up-to-date:
  bazel-bin/buildifier.bash
INFO: Elapsed time: 0.106s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Build completed successfully, 1 total action
./BUILD:8: native-cc: Function "cc_binary" is not global anymore and needs to be loaded from "@rules_cc//cc:defs.bzl". (https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#native-cc)

I created a sample git repo to demonstrate the issue. Here are repro steps:

git clone https://github.com/tetsuok/buildifier-test.git
cd buildifier-test
bazel run //:buildifier

I suspect that this is due to the naming collision regarding com_github_bazelbuild_buildtools between http_archive in the sample project created according to Buildifier's README.md and bazel-gazelle's deps.bzl (i.e., both projects depend on different versions of com_github_bazelbuild_buildtools).