Skip to content

Commit

Permalink
Add support for *.MODULE.bazel files (#1266)
Browse files Browse the repository at this point in the history
After bazelbuild/bazel#22075, these are the
files that can be `include()`ed into `MODULE.bazel` files and should be
formatted and edited just like them.
  • Loading branch information
fmeum authored Apr 22, 2024
1 parent fa8c825 commit 1429e15
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions build/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const (
TypeWorkspace
// TypeBzl represents .bzl files
TypeBzl
//TypeModule represents MODULE.bazel files
//TypeModule represents MODULE.bazel and *.MODULE.bazel files
TypeModule
)

Expand Down Expand Up @@ -130,7 +130,7 @@ func getFileType(filename string) FileType {
if strings.HasSuffix(basename, ".oss") {
basename = basename[:len(basename)-4]
}
if basename == "module.bazel" {
if basename == "module.bazel" || strings.HasSuffix(basename, ".module.bazel") {
return TypeModule
}
ext := filepath.Ext(basename)
Expand Down
30 changes: 30 additions & 0 deletions buildozer/buildozer_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2038,6 +2038,36 @@ EOF
diff -u MODULE.bazel.expected MODULE.bazel || fail "Output didn't match"
}

function test_module_bazel_segment() {
cat > go.MODULE.bazel <<EOF
module(
name = "foo",
version = "0.27.0",
)
bazel_dep(name = "gazelle", version = "0.30.0")
go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")
use_repo(go_deps, "com_example_foo")
EOF

cat > go.MODULE.bazel.expected <<EOF
module(
name = "foo",
version = "0.27.0",
)
bazel_dep(name = "gazelle", version = "0.30.0")
go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")
EOF

$buildozer 'delete' //go.MODULE.bazel:%10
diff -u go.MODULE.bazel.expected go.MODULE.bazel || fail "Output didn't match"
}

function test_module_bazel_new() {
cat > MODULE.bazel <<EOF
bazel_dep(name = "gazelle", version = "0.30.0")
Expand Down

0 comments on commit 1429e15

Please sign in to comment.