Skip to content

Commit

Permalink
Move bzl ext (#265)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
comius and Jay Conrod committed Aug 20, 2020
1 parent 68acaa5 commit bc97abb
Show file tree
Hide file tree
Showing 49 changed files with 12 additions and 9 deletions.
8 changes: 4 additions & 4 deletions gazelle/BUILD → gazelle/bzl/BUILD
Expand Up @@ -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"],
Expand All @@ -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",
Expand All @@ -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.
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions gazelle/gazelle.go → gazelle/bzl/gazelle.go
Expand Up @@ -13,15 +13,15 @@ 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
// https://github.com/bazelbuild/bazel-skylib.
//
// This extension is experimental and subject to change. It is not included
// in the default Gazelle binary.
package gazelle
package bzl

import (
"flag"
Expand Down
9 changes: 6 additions & 3 deletions gazelle/gazelle_test.go → gazelle/bzl/gazelle_test.go
@@ -1,4 +1,4 @@
package gazelle
package bzl

/* Copyright 2020 The Bazel Authors. All rights reserved.
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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")
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit bc97abb

Please sign in to comment.