Move bzl ext (#265)

* Move Gazelle extension to //gazelle/bzl and change package name

This fixes an issue with importing bazel-skylib into
google3. Currently, Glaze (internal Go build file generator) attempts
to generate a target (//gazelle:gazelle) that conflicts with one
that's already declared here.

I think the right solution is actually to move the package into a
subdirectory. In the future (bazelbuild/bazel-gazelle#5), Gazelle's Go
extension will generate target names similar to what Glaze does, so
the same conflict will happen in open source. I think it's also
logical to have a directory of packages in case more need to be added
in the future, and for the extension to have a package name matching
the language it works with.

This is an incompatible change, but the //gazelle directory isn't part
of a tagged release yet, so hopefully it won't break anyone.

* fix runfiles access in test

* Fix gazelle package names.

Co-authored-by: Jay Conrod <jayconrod@google.com>
This commit is contained in:
Ivo List 2020-08-20 19:14:55 +02:00 committed by GitHub
parent 68acaa5d6a
commit bc97abb33e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
49 changed files with 12 additions and 9 deletions

View File

@ -4,7 +4,7 @@ load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary")
# gazelle:exclude testdata
go_library(
name = "go_default_library",
name = "bzl",
srcs = ["gazelle.go"],
importpath = "github.com/bazelbuild/bazel-skylib/gazelle",
visibility = ["//visibility:public"],
@ -21,14 +21,14 @@ go_library(
)
go_test(
name = "go_default_test",
name = "bzl_test",
srcs = ["gazelle_test.go"],
data = [
":gazelle-skylib",
] + glob([
"testdata/**",
]),
embed = [":go_default_library"],
embed = [":bzl"],
deps = [
"@bazel_gazelle//testtools:go_default_library",
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
@ -39,7 +39,7 @@ go_test(
# extension and thus only has the skylib language installed.
gazelle_binary(
name = "gazelle-skylib",
languages = [":go_default_library"],
languages = [":bzl"],
visibility = [
# Also make the binary available in the root of the repo for use, but
# not externally.

View File

@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
// Package gazelle generates a `bzl_library` target for every `.bzl` file in
// Package bzl generates a `bzl_library` target for every `.bzl` file in
// each package.
//
// The `bzl_library` rule is provided by
@ -21,7 +21,7 @@ limitations under the License.
//
// This extension is experimental and subject to change. It is not included
// in the default Gazelle binary.
package gazelle
package bzl
import (
"flag"

View File

@ -1,4 +1,4 @@
package gazelle
package bzl
/* Copyright 2020 The Bazel Authors. All rights reserved.
@ -29,7 +29,7 @@ import (
var gazellePath = findGazelle()
const testDataPath = "gazelle/testdata/"
const testDataPath = "gazelle/bzl/testdata/"
// TestGazelleBinary runs a gazelle binary with starlib installed on each
// directory in `testdata/*`. Please see `testdata/README.md` for more
@ -54,6 +54,9 @@ func TestGazelleBinary(t *testing.T) {
tests[parts[0]] = append(tests[parts[0]], f)
}
}
if len(tests) == 0 {
t.Fatal("no tests found")
}
for testName, files := range tests {
testPath(t, testName, files)
@ -132,7 +135,7 @@ func testPath(t *testing.T, name string, files []bazel.RunfileEntry) {
}
func findGazelle() string {
gazellePath, ok := bazel.FindBinary("gazelle", "gazelle-skylib")
gazellePath, ok := bazel.FindBinary("gazelle/bzl", "gazelle-skylib")
if !ok {
panic("could not find gazelle binary")
}