mirror of
https://github.com/bazelbuild/bazel-skylib
synced 2024-11-27 05:43:25 +00:00
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:
parent
68acaa5d6a
commit
bc97abb33e
|
@ -4,7 +4,7 @@ load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary")
|
||||||
# gazelle:exclude testdata
|
# gazelle:exclude testdata
|
||||||
|
|
||||||
go_library(
|
go_library(
|
||||||
name = "go_default_library",
|
name = "bzl",
|
||||||
srcs = ["gazelle.go"],
|
srcs = ["gazelle.go"],
|
||||||
importpath = "github.com/bazelbuild/bazel-skylib/gazelle",
|
importpath = "github.com/bazelbuild/bazel-skylib/gazelle",
|
||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
|
@ -21,14 +21,14 @@ go_library(
|
||||||
)
|
)
|
||||||
|
|
||||||
go_test(
|
go_test(
|
||||||
name = "go_default_test",
|
name = "bzl_test",
|
||||||
srcs = ["gazelle_test.go"],
|
srcs = ["gazelle_test.go"],
|
||||||
data = [
|
data = [
|
||||||
":gazelle-skylib",
|
":gazelle-skylib",
|
||||||
] + glob([
|
] + glob([
|
||||||
"testdata/**",
|
"testdata/**",
|
||||||
]),
|
]),
|
||||||
embed = [":go_default_library"],
|
embed = [":bzl"],
|
||||||
deps = [
|
deps = [
|
||||||
"@bazel_gazelle//testtools:go_default_library",
|
"@bazel_gazelle//testtools:go_default_library",
|
||||||
"@io_bazel_rules_go//go/tools/bazel: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.
|
# extension and thus only has the skylib language installed.
|
||||||
gazelle_binary(
|
gazelle_binary(
|
||||||
name = "gazelle-skylib",
|
name = "gazelle-skylib",
|
||||||
languages = [":go_default_library"],
|
languages = [":bzl"],
|
||||||
visibility = [
|
visibility = [
|
||||||
# Also make the binary available in the root of the repo for use, but
|
# Also make the binary available in the root of the repo for use, but
|
||||||
# not externally.
|
# not externally.
|
|
@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
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.
|
// each package.
|
||||||
//
|
//
|
||||||
// The `bzl_library` rule is provided by
|
// 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
|
// This extension is experimental and subject to change. It is not included
|
||||||
// in the default Gazelle binary.
|
// in the default Gazelle binary.
|
||||||
package gazelle
|
package bzl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
|
@ -1,4 +1,4 @@
|
||||||
package gazelle
|
package bzl
|
||||||
|
|
||||||
/* Copyright 2020 The Bazel Authors. All rights reserved.
|
/* Copyright 2020 The Bazel Authors. All rights reserved.
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ import (
|
||||||
|
|
||||||
var gazellePath = findGazelle()
|
var gazellePath = findGazelle()
|
||||||
|
|
||||||
const testDataPath = "gazelle/testdata/"
|
const testDataPath = "gazelle/bzl/testdata/"
|
||||||
|
|
||||||
// TestGazelleBinary runs a gazelle binary with starlib installed on each
|
// TestGazelleBinary runs a gazelle binary with starlib installed on each
|
||||||
// directory in `testdata/*`. Please see `testdata/README.md` for more
|
// 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)
|
tests[parts[0]] = append(tests[parts[0]], f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(tests) == 0 {
|
||||||
|
t.Fatal("no tests found")
|
||||||
|
}
|
||||||
|
|
||||||
for testName, files := range tests {
|
for testName, files := range tests {
|
||||||
testPath(t, testName, files)
|
testPath(t, testName, files)
|
||||||
|
@ -132,7 +135,7 @@ func testPath(t *testing.T, name string, files []bazel.RunfileEntry) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func findGazelle() string {
|
func findGazelle() string {
|
||||||
gazellePath, ok := bazel.FindBinary("gazelle", "gazelle-skylib")
|
gazellePath, ok := bazel.FindBinary("gazelle/bzl", "gazelle-skylib")
|
||||||
if !ok {
|
if !ok {
|
||||||
panic("could not find gazelle binary")
|
panic("could not find gazelle binary")
|
||||||
}
|
}
|
Loading…
Reference in a new issue