From bc97abb33eaacfff3c31ba64719817e7a808b20d Mon Sep 17 00:00:00 2001 From: Ivo List Date: Thu, 20 Aug 2020 19:14:55 +0200 Subject: [PATCH] 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 --- gazelle/{ => bzl}/BUILD | 8 ++++---- gazelle/{ => bzl}/README.md | 0 gazelle/{ => bzl}/gazelle.go | 4 ++-- gazelle/{ => bzl}/gazelle_test.go | 9 ++++++--- gazelle/{ => bzl}/testdata/README.md | 0 gazelle/{ => bzl}/testdata/defaultvisibility/BUILD.in | 0 gazelle/{ => bzl}/testdata/defaultvisibility/BUILD.out | 0 gazelle/{ => bzl}/testdata/defaultvisibility/WORKSPACE | 0 gazelle/{ => bzl}/testdata/defaultvisibility/foo.bzl | 0 .../testdata/defaultvisibility/nested/dir/BUILD.in | 0 .../testdata/defaultvisibility/nested/dir/BUILD.out | 0 .../testdata/defaultvisibility/nested/dir/bar.bzl | 0 gazelle/{ => bzl}/testdata/empty/BUILD.in | 0 gazelle/{ => bzl}/testdata/empty/BUILD.out | 0 gazelle/{ => bzl}/testdata/empty/WORKSPACE | 0 gazelle/{ => bzl}/testdata/empty/foo.bzl | 0 gazelle/{ => bzl}/testdata/external/BUILD.in | 0 gazelle/{ => bzl}/testdata/external/BUILD.out | 0 gazelle/{ => bzl}/testdata/external/WORKSPACE | 0 gazelle/{ => bzl}/testdata/external/foo.bzl | 0 gazelle/{ => bzl}/testdata/import/BUILD.in | 0 gazelle/{ => bzl}/testdata/import/BUILD.out | 0 gazelle/{ => bzl}/testdata/import/WORKSPACE | 0 gazelle/{ => bzl}/testdata/import/bar.bzl | 0 gazelle/{ => bzl}/testdata/import/foo.bzl | 0 gazelle/{ => bzl}/testdata/multidir/BUILD.in | 0 gazelle/{ => bzl}/testdata/multidir/BUILD.out | 0 gazelle/{ => bzl}/testdata/multidir/WORKSPACE | 0 gazelle/{ => bzl}/testdata/multidir/foo.bzl | 0 gazelle/{ => bzl}/testdata/multidir/nested/dir/BUILD.out | 0 gazelle/{ => bzl}/testdata/multidir/nested/dir/bar.bzl | 0 gazelle/{ => bzl}/testdata/nobuildfiles/BUILD.out | 0 gazelle/{ => bzl}/testdata/nobuildfiles/WORKSPACE | 0 gazelle/{ => bzl}/testdata/nobuildfiles/foo.bzl | 0 gazelle/{ => bzl}/testdata/private/BUILD.in | 0 gazelle/{ => bzl}/testdata/private/BUILD.out | 0 gazelle/{ => bzl}/testdata/private/WORKSPACE | 0 gazelle/{ => bzl}/testdata/private/foo.bzl | 0 gazelle/{ => bzl}/testdata/private/private/BUILD.out | 0 gazelle/{ => bzl}/testdata/private/private/bar.bzl | 0 gazelle/{ => bzl}/testdata/simple/BUILD.in | 0 gazelle/{ => bzl}/testdata/simple/BUILD.out | 0 gazelle/{ => bzl}/testdata/simple/WORKSPACE | 0 gazelle/{ => bzl}/testdata/simple/foo.bzl | 0 gazelle/{ => bzl}/testdata/tests/BUILD.in | 0 gazelle/{ => bzl}/testdata/tests/BUILD.out | 0 gazelle/{ => bzl}/testdata/tests/WORKSPACE | 0 gazelle/{ => bzl}/testdata/tests/foo.bzl | 0 gazelle/{ => bzl}/testdata/tests/foo_tests.bzl | 0 49 files changed, 12 insertions(+), 9 deletions(-) rename gazelle/{ => bzl}/BUILD (91%) rename gazelle/{ => bzl}/README.md (100%) rename gazelle/{ => bzl}/gazelle.go (99%) rename gazelle/{ => bzl}/gazelle_test.go (95%) rename gazelle/{ => bzl}/testdata/README.md (100%) rename gazelle/{ => bzl}/testdata/defaultvisibility/BUILD.in (100%) rename gazelle/{ => bzl}/testdata/defaultvisibility/BUILD.out (100%) rename gazelle/{ => bzl}/testdata/defaultvisibility/WORKSPACE (100%) rename gazelle/{ => bzl}/testdata/defaultvisibility/foo.bzl (100%) rename gazelle/{ => bzl}/testdata/defaultvisibility/nested/dir/BUILD.in (100%) rename gazelle/{ => bzl}/testdata/defaultvisibility/nested/dir/BUILD.out (100%) rename gazelle/{ => bzl}/testdata/defaultvisibility/nested/dir/bar.bzl (100%) rename gazelle/{ => bzl}/testdata/empty/BUILD.in (100%) rename gazelle/{ => bzl}/testdata/empty/BUILD.out (100%) rename gazelle/{ => bzl}/testdata/empty/WORKSPACE (100%) rename gazelle/{ => bzl}/testdata/empty/foo.bzl (100%) rename gazelle/{ => bzl}/testdata/external/BUILD.in (100%) rename gazelle/{ => bzl}/testdata/external/BUILD.out (100%) rename gazelle/{ => bzl}/testdata/external/WORKSPACE (100%) rename gazelle/{ => bzl}/testdata/external/foo.bzl (100%) rename gazelle/{ => bzl}/testdata/import/BUILD.in (100%) rename gazelle/{ => bzl}/testdata/import/BUILD.out (100%) rename gazelle/{ => bzl}/testdata/import/WORKSPACE (100%) rename gazelle/{ => bzl}/testdata/import/bar.bzl (100%) rename gazelle/{ => bzl}/testdata/import/foo.bzl (100%) rename gazelle/{ => bzl}/testdata/multidir/BUILD.in (100%) rename gazelle/{ => bzl}/testdata/multidir/BUILD.out (100%) rename gazelle/{ => bzl}/testdata/multidir/WORKSPACE (100%) rename gazelle/{ => bzl}/testdata/multidir/foo.bzl (100%) rename gazelle/{ => bzl}/testdata/multidir/nested/dir/BUILD.out (100%) rename gazelle/{ => bzl}/testdata/multidir/nested/dir/bar.bzl (100%) rename gazelle/{ => bzl}/testdata/nobuildfiles/BUILD.out (100%) rename gazelle/{ => bzl}/testdata/nobuildfiles/WORKSPACE (100%) rename gazelle/{ => bzl}/testdata/nobuildfiles/foo.bzl (100%) rename gazelle/{ => bzl}/testdata/private/BUILD.in (100%) rename gazelle/{ => bzl}/testdata/private/BUILD.out (100%) rename gazelle/{ => bzl}/testdata/private/WORKSPACE (100%) rename gazelle/{ => bzl}/testdata/private/foo.bzl (100%) rename gazelle/{ => bzl}/testdata/private/private/BUILD.out (100%) rename gazelle/{ => bzl}/testdata/private/private/bar.bzl (100%) rename gazelle/{ => bzl}/testdata/simple/BUILD.in (100%) rename gazelle/{ => bzl}/testdata/simple/BUILD.out (100%) rename gazelle/{ => bzl}/testdata/simple/WORKSPACE (100%) rename gazelle/{ => bzl}/testdata/simple/foo.bzl (100%) rename gazelle/{ => bzl}/testdata/tests/BUILD.in (100%) rename gazelle/{ => bzl}/testdata/tests/BUILD.out (100%) rename gazelle/{ => bzl}/testdata/tests/WORKSPACE (100%) rename gazelle/{ => bzl}/testdata/tests/foo.bzl (100%) rename gazelle/{ => bzl}/testdata/tests/foo_tests.bzl (100%) diff --git a/gazelle/BUILD b/gazelle/bzl/BUILD similarity index 91% rename from gazelle/BUILD rename to gazelle/bzl/BUILD index d20212c..fea1d51 100644 --- a/gazelle/BUILD +++ b/gazelle/bzl/BUILD @@ -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. diff --git a/gazelle/README.md b/gazelle/bzl/README.md similarity index 100% rename from gazelle/README.md rename to gazelle/bzl/README.md diff --git a/gazelle/gazelle.go b/gazelle/bzl/gazelle.go similarity index 99% rename from gazelle/gazelle.go rename to gazelle/bzl/gazelle.go index b45ef3d..f948390 100644 --- a/gazelle/gazelle.go +++ b/gazelle/bzl/gazelle.go @@ -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" diff --git a/gazelle/gazelle_test.go b/gazelle/bzl/gazelle_test.go similarity index 95% rename from gazelle/gazelle_test.go rename to gazelle/bzl/gazelle_test.go index a22f7f6..e4f59e8 100644 --- a/gazelle/gazelle_test.go +++ b/gazelle/bzl/gazelle_test.go @@ -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") } diff --git a/gazelle/testdata/README.md b/gazelle/bzl/testdata/README.md similarity index 100% rename from gazelle/testdata/README.md rename to gazelle/bzl/testdata/README.md diff --git a/gazelle/testdata/defaultvisibility/BUILD.in b/gazelle/bzl/testdata/defaultvisibility/BUILD.in similarity index 100% rename from gazelle/testdata/defaultvisibility/BUILD.in rename to gazelle/bzl/testdata/defaultvisibility/BUILD.in diff --git a/gazelle/testdata/defaultvisibility/BUILD.out b/gazelle/bzl/testdata/defaultvisibility/BUILD.out similarity index 100% rename from gazelle/testdata/defaultvisibility/BUILD.out rename to gazelle/bzl/testdata/defaultvisibility/BUILD.out diff --git a/gazelle/testdata/defaultvisibility/WORKSPACE b/gazelle/bzl/testdata/defaultvisibility/WORKSPACE similarity index 100% rename from gazelle/testdata/defaultvisibility/WORKSPACE rename to gazelle/bzl/testdata/defaultvisibility/WORKSPACE diff --git a/gazelle/testdata/defaultvisibility/foo.bzl b/gazelle/bzl/testdata/defaultvisibility/foo.bzl similarity index 100% rename from gazelle/testdata/defaultvisibility/foo.bzl rename to gazelle/bzl/testdata/defaultvisibility/foo.bzl diff --git a/gazelle/testdata/defaultvisibility/nested/dir/BUILD.in b/gazelle/bzl/testdata/defaultvisibility/nested/dir/BUILD.in similarity index 100% rename from gazelle/testdata/defaultvisibility/nested/dir/BUILD.in rename to gazelle/bzl/testdata/defaultvisibility/nested/dir/BUILD.in diff --git a/gazelle/testdata/defaultvisibility/nested/dir/BUILD.out b/gazelle/bzl/testdata/defaultvisibility/nested/dir/BUILD.out similarity index 100% rename from gazelle/testdata/defaultvisibility/nested/dir/BUILD.out rename to gazelle/bzl/testdata/defaultvisibility/nested/dir/BUILD.out diff --git a/gazelle/testdata/defaultvisibility/nested/dir/bar.bzl b/gazelle/bzl/testdata/defaultvisibility/nested/dir/bar.bzl similarity index 100% rename from gazelle/testdata/defaultvisibility/nested/dir/bar.bzl rename to gazelle/bzl/testdata/defaultvisibility/nested/dir/bar.bzl diff --git a/gazelle/testdata/empty/BUILD.in b/gazelle/bzl/testdata/empty/BUILD.in similarity index 100% rename from gazelle/testdata/empty/BUILD.in rename to gazelle/bzl/testdata/empty/BUILD.in diff --git a/gazelle/testdata/empty/BUILD.out b/gazelle/bzl/testdata/empty/BUILD.out similarity index 100% rename from gazelle/testdata/empty/BUILD.out rename to gazelle/bzl/testdata/empty/BUILD.out diff --git a/gazelle/testdata/empty/WORKSPACE b/gazelle/bzl/testdata/empty/WORKSPACE similarity index 100% rename from gazelle/testdata/empty/WORKSPACE rename to gazelle/bzl/testdata/empty/WORKSPACE diff --git a/gazelle/testdata/empty/foo.bzl b/gazelle/bzl/testdata/empty/foo.bzl similarity index 100% rename from gazelle/testdata/empty/foo.bzl rename to gazelle/bzl/testdata/empty/foo.bzl diff --git a/gazelle/testdata/external/BUILD.in b/gazelle/bzl/testdata/external/BUILD.in similarity index 100% rename from gazelle/testdata/external/BUILD.in rename to gazelle/bzl/testdata/external/BUILD.in diff --git a/gazelle/testdata/external/BUILD.out b/gazelle/bzl/testdata/external/BUILD.out similarity index 100% rename from gazelle/testdata/external/BUILD.out rename to gazelle/bzl/testdata/external/BUILD.out diff --git a/gazelle/testdata/external/WORKSPACE b/gazelle/bzl/testdata/external/WORKSPACE similarity index 100% rename from gazelle/testdata/external/WORKSPACE rename to gazelle/bzl/testdata/external/WORKSPACE diff --git a/gazelle/testdata/external/foo.bzl b/gazelle/bzl/testdata/external/foo.bzl similarity index 100% rename from gazelle/testdata/external/foo.bzl rename to gazelle/bzl/testdata/external/foo.bzl diff --git a/gazelle/testdata/import/BUILD.in b/gazelle/bzl/testdata/import/BUILD.in similarity index 100% rename from gazelle/testdata/import/BUILD.in rename to gazelle/bzl/testdata/import/BUILD.in diff --git a/gazelle/testdata/import/BUILD.out b/gazelle/bzl/testdata/import/BUILD.out similarity index 100% rename from gazelle/testdata/import/BUILD.out rename to gazelle/bzl/testdata/import/BUILD.out diff --git a/gazelle/testdata/import/WORKSPACE b/gazelle/bzl/testdata/import/WORKSPACE similarity index 100% rename from gazelle/testdata/import/WORKSPACE rename to gazelle/bzl/testdata/import/WORKSPACE diff --git a/gazelle/testdata/import/bar.bzl b/gazelle/bzl/testdata/import/bar.bzl similarity index 100% rename from gazelle/testdata/import/bar.bzl rename to gazelle/bzl/testdata/import/bar.bzl diff --git a/gazelle/testdata/import/foo.bzl b/gazelle/bzl/testdata/import/foo.bzl similarity index 100% rename from gazelle/testdata/import/foo.bzl rename to gazelle/bzl/testdata/import/foo.bzl diff --git a/gazelle/testdata/multidir/BUILD.in b/gazelle/bzl/testdata/multidir/BUILD.in similarity index 100% rename from gazelle/testdata/multidir/BUILD.in rename to gazelle/bzl/testdata/multidir/BUILD.in diff --git a/gazelle/testdata/multidir/BUILD.out b/gazelle/bzl/testdata/multidir/BUILD.out similarity index 100% rename from gazelle/testdata/multidir/BUILD.out rename to gazelle/bzl/testdata/multidir/BUILD.out diff --git a/gazelle/testdata/multidir/WORKSPACE b/gazelle/bzl/testdata/multidir/WORKSPACE similarity index 100% rename from gazelle/testdata/multidir/WORKSPACE rename to gazelle/bzl/testdata/multidir/WORKSPACE diff --git a/gazelle/testdata/multidir/foo.bzl b/gazelle/bzl/testdata/multidir/foo.bzl similarity index 100% rename from gazelle/testdata/multidir/foo.bzl rename to gazelle/bzl/testdata/multidir/foo.bzl diff --git a/gazelle/testdata/multidir/nested/dir/BUILD.out b/gazelle/bzl/testdata/multidir/nested/dir/BUILD.out similarity index 100% rename from gazelle/testdata/multidir/nested/dir/BUILD.out rename to gazelle/bzl/testdata/multidir/nested/dir/BUILD.out diff --git a/gazelle/testdata/multidir/nested/dir/bar.bzl b/gazelle/bzl/testdata/multidir/nested/dir/bar.bzl similarity index 100% rename from gazelle/testdata/multidir/nested/dir/bar.bzl rename to gazelle/bzl/testdata/multidir/nested/dir/bar.bzl diff --git a/gazelle/testdata/nobuildfiles/BUILD.out b/gazelle/bzl/testdata/nobuildfiles/BUILD.out similarity index 100% rename from gazelle/testdata/nobuildfiles/BUILD.out rename to gazelle/bzl/testdata/nobuildfiles/BUILD.out diff --git a/gazelle/testdata/nobuildfiles/WORKSPACE b/gazelle/bzl/testdata/nobuildfiles/WORKSPACE similarity index 100% rename from gazelle/testdata/nobuildfiles/WORKSPACE rename to gazelle/bzl/testdata/nobuildfiles/WORKSPACE diff --git a/gazelle/testdata/nobuildfiles/foo.bzl b/gazelle/bzl/testdata/nobuildfiles/foo.bzl similarity index 100% rename from gazelle/testdata/nobuildfiles/foo.bzl rename to gazelle/bzl/testdata/nobuildfiles/foo.bzl diff --git a/gazelle/testdata/private/BUILD.in b/gazelle/bzl/testdata/private/BUILD.in similarity index 100% rename from gazelle/testdata/private/BUILD.in rename to gazelle/bzl/testdata/private/BUILD.in diff --git a/gazelle/testdata/private/BUILD.out b/gazelle/bzl/testdata/private/BUILD.out similarity index 100% rename from gazelle/testdata/private/BUILD.out rename to gazelle/bzl/testdata/private/BUILD.out diff --git a/gazelle/testdata/private/WORKSPACE b/gazelle/bzl/testdata/private/WORKSPACE similarity index 100% rename from gazelle/testdata/private/WORKSPACE rename to gazelle/bzl/testdata/private/WORKSPACE diff --git a/gazelle/testdata/private/foo.bzl b/gazelle/bzl/testdata/private/foo.bzl similarity index 100% rename from gazelle/testdata/private/foo.bzl rename to gazelle/bzl/testdata/private/foo.bzl diff --git a/gazelle/testdata/private/private/BUILD.out b/gazelle/bzl/testdata/private/private/BUILD.out similarity index 100% rename from gazelle/testdata/private/private/BUILD.out rename to gazelle/bzl/testdata/private/private/BUILD.out diff --git a/gazelle/testdata/private/private/bar.bzl b/gazelle/bzl/testdata/private/private/bar.bzl similarity index 100% rename from gazelle/testdata/private/private/bar.bzl rename to gazelle/bzl/testdata/private/private/bar.bzl diff --git a/gazelle/testdata/simple/BUILD.in b/gazelle/bzl/testdata/simple/BUILD.in similarity index 100% rename from gazelle/testdata/simple/BUILD.in rename to gazelle/bzl/testdata/simple/BUILD.in diff --git a/gazelle/testdata/simple/BUILD.out b/gazelle/bzl/testdata/simple/BUILD.out similarity index 100% rename from gazelle/testdata/simple/BUILD.out rename to gazelle/bzl/testdata/simple/BUILD.out diff --git a/gazelle/testdata/simple/WORKSPACE b/gazelle/bzl/testdata/simple/WORKSPACE similarity index 100% rename from gazelle/testdata/simple/WORKSPACE rename to gazelle/bzl/testdata/simple/WORKSPACE diff --git a/gazelle/testdata/simple/foo.bzl b/gazelle/bzl/testdata/simple/foo.bzl similarity index 100% rename from gazelle/testdata/simple/foo.bzl rename to gazelle/bzl/testdata/simple/foo.bzl diff --git a/gazelle/testdata/tests/BUILD.in b/gazelle/bzl/testdata/tests/BUILD.in similarity index 100% rename from gazelle/testdata/tests/BUILD.in rename to gazelle/bzl/testdata/tests/BUILD.in diff --git a/gazelle/testdata/tests/BUILD.out b/gazelle/bzl/testdata/tests/BUILD.out similarity index 100% rename from gazelle/testdata/tests/BUILD.out rename to gazelle/bzl/testdata/tests/BUILD.out diff --git a/gazelle/testdata/tests/WORKSPACE b/gazelle/bzl/testdata/tests/WORKSPACE similarity index 100% rename from gazelle/testdata/tests/WORKSPACE rename to gazelle/bzl/testdata/tests/WORKSPACE diff --git a/gazelle/testdata/tests/foo.bzl b/gazelle/bzl/testdata/tests/foo.bzl similarity index 100% rename from gazelle/testdata/tests/foo.bzl rename to gazelle/bzl/testdata/tests/foo.bzl diff --git a/gazelle/testdata/tests/foo_tests.bzl b/gazelle/bzl/testdata/tests/foo_tests.bzl similarity index 100% rename from gazelle/testdata/tests/foo_tests.bzl rename to gazelle/bzl/testdata/tests/foo_tests.bzl