bazel: enable bzlmod

This change enables bzlmod without migrating any dependencies.
Instead, WORKSPACE dependencies can be migrated one by one.
This commit is contained in:
Malte Poll 2024-05-22 13:25:35 +02:00
parent d0bab9eb08
commit 8796edc9ad
10 changed files with 33 additions and 33 deletions

View File

@ -1,9 +1,3 @@
# Sadly, some Bazel rules we depend on have no support for bzlmod yet
# Here is an (incomplete) list of rules known to not support bzlmod.
# Please extend this list as you find more.
# - rules_nixpkgs: https://github.com/tweag/rules_nixpkgs/issues/181
common --noenable_bzlmod
# Import bazelrc presets
import %workspace%/bazel/bazelrc/bazel7.bazelrc
import %workspace%/bazel/bazelrc/convenience.bazelrc

View File

@ -1,5 +1,5 @@
exports_files([
"WORKSPACE.bazel",
"WORKSPACE.bzlmod",
])
alias(

1
MODULE.bazel Normal file
View File

@ -0,0 +1 @@
module(name = "constellation")

View File

@ -1,5 +1,10 @@
workspace(name = "constellation")
# Sadly, some Bazel rules we depend on have no support for bzlmod yet
# Here is an (incomplete) list of rules known to not support bzlmod.
# Please extend this list as you find more.
# - rules_nixpkgs: https://github.com/tweag/rules_nixpkgs/issues/181
load("//bazel/toolchains:skylib_deps.bzl", "skylib_deps")
skylib_deps()
@ -179,7 +184,7 @@ go_register_toolchains()
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
gazelle_dependencies(go_repository_default_config = "//:WORKSPACE.bazel")
gazelle_dependencies(go_repository_default_config = "//:WORKSPACE.bzlmod")
# gazelle:repo bazel_gazelle

View File

@ -54,7 +54,7 @@ buildifier_test(
no_sandbox = True,
tags = ["no-remote-exec"],
verbose = True,
workspace = "//:WORKSPACE.bazel",
workspace = "//:WORKSPACE.bzlmod",
)
buildifier(

View File

@ -1 +1 @@
"""This folder contains toolchain dependencies for the project. They are loaded by `WORKSPACE.bazel`."""
"""This folder contains toolchain dependencies for the project. They are loaded by `WORKSPACE.bzlmod`."""

View File

@ -4,7 +4,7 @@
## Steps
Replace "1.xx.x" with the new version in [WORKSPACE.bazel](/WORKSPACE.bazel):
Replace "1.xx.x" with the new version in [WORKSPACE.bzlmod](/WORKSPACE.bzlmod):
```starlark
load("@io_bazel_rules_go//go:deps.bzl", "go_download_sdk", "go_register_toolchains", "go_rules_dependencies")

View File

@ -2,7 +2,7 @@
This directory contains tooling to automatically mirror the dependencies of a Bazel project into the Constellation CDN at `https://cdn.confidential.cloud/`.
The tool searches for various rules in the WORKSPACE.bazel file and all loaded .bzl files.
The tool searches for various rules in the WORKSPACE.bzlmod file and all loaded .bzl files.
It has the following commands:
- check: checks if the dependencies all have a mirror URL and optionally checks if the mirror really returns the expected file

View File

@ -53,12 +53,12 @@ func (h *Helper) FindFiles() ([]BazelFile, error) {
return append(bzlFiles, workspaceFile), nil
}
// findWorkspaceFile returns the path to the Bazel WORKSPACE.bazel file (or WORKSPACE if the former doesn't exist).
// findWorkspaceFile returns the path to the Bazel WORKSPACE.bzlmod file (or WORKSPACE if the former doesn't exist).
func (h *Helper) findWorkspaceFile() (BazelFile, error) {
if _, err := h.fs.Stat("WORKSPACE.bazel"); err == nil {
if _, err := h.fs.Stat("WORKSPACE.bzlmod"); err == nil {
return BazelFile{
RelPath: "WORKSPACE.bazel",
AbsPath: filepath.Join(h.workspaceRoot, "WORKSPACE.bazel"),
RelPath: "WORKSPACE.bzlmod",
AbsPath: filepath.Join(h.workspaceRoot, "WORKSPACE.bzlmod"),
Type: BazelFileTypeWorkspace,
}, nil
}
@ -151,7 +151,7 @@ type BazelFileType int
const (
BazelFileTypeBzl = iota // BazelFileTypeBzl is a .bzl file
BazelFileTypeWorkspace // BazelFileTypeWorkspace is a WORKSPACE or WORKSPACE.bazel file
BazelFileTypeWorkspace // BazelFileTypeWorkspace is a WORKSPACE or WORKSPACE.bzlmod file
)
// LookupEnv can be the real os.LookupEnv or a mock for testing.

View File

@ -42,22 +42,22 @@ func TestFindFiles(t *testing.T) {
},
},
},
"only WORKSPACE.bazel file": {
files: []string{"WORKSPACE.bazel"},
"only WORKSPACE.bzlmod file": {
files: []string{"WORKSPACE.bzlmod"},
wantFiles: []BazelFile{
{
RelPath: "WORKSPACE.bazel",
AbsPath: "/WORKSPACE.bazel",
RelPath: "WORKSPACE.bzlmod",
AbsPath: "/WORKSPACE.bzlmod",
Type: BazelFileTypeWorkspace,
},
},
},
"both WORKSPACE and WORKSPACE.bazel files": {
files: []string{"WORKSPACE", "WORKSPACE.bazel"},
"both WORKSPACE and WORKSPACE.bzlmod files": {
files: []string{"WORKSPACE", "WORKSPACE.bzlmod"},
wantFiles: []BazelFile{
{
RelPath: "WORKSPACE.bazel",
AbsPath: "/WORKSPACE.bazel",
RelPath: "WORKSPACE.bzlmod",
AbsPath: "/WORKSPACE.bzlmod",
Type: BazelFileTypeWorkspace,
},
},
@ -67,11 +67,11 @@ func TestFindFiles(t *testing.T) {
wantErr: true,
},
"all kinds": {
files: []string{"WORKSPACE", "WORKSPACE.bazel", "foo.bzl", "bar.bzl", "unused.txt", "folder/baz.bzl"},
files: []string{"WORKSPACE", "WORKSPACE.bzlmod", "foo.bzl", "bar.bzl", "unused.txt", "folder/baz.bzl"},
wantFiles: []BazelFile{
{
RelPath: "WORKSPACE.bazel",
AbsPath: "/WORKSPACE.bazel",
RelPath: "WORKSPACE.bzlmod",
AbsPath: "/WORKSPACE.bzlmod",
Type: BazelFileTypeWorkspace,
},
{
@ -216,15 +216,15 @@ func TestDiff(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
fs := afero.NewMemMapFs()
err := afero.WriteFile(fs, "WORKSPACE.bazel", []byte(""), 0o644)
err := afero.WriteFile(fs, "WORKSPACE.bzlmod", []byte(""), 0o644)
require.NoError(err)
helper := Helper{
fs: fs,
workspaceRoot: "/",
}
fileRef := BazelFile{
RelPath: "WORKSPACE.bazel",
AbsPath: "/WORKSPACE.bazel",
RelPath: "WORKSPACE.bzlmod",
AbsPath: "/WORKSPACE.bzlmod",
Type: BazelFileTypeWorkspace,
}
bf, err := helper.LoadFile(fileRef)
@ -247,10 +247,10 @@ func TestDiff(t *testing.T) {
)
diff, err = helper.Diff(fileRef, bf)
require.NoError(err)
assert.Equal("--- a/WORKSPACE.bazel\n+++ b/WORKSPACE.bazel\n@@ -1 +1 @@\n+workspace(name = \"foo\")\n", diff)
assert.Equal("--- a/WORKSPACE.bzlmod\n+++ b/WORKSPACE.bzlmod\n@@ -1 +1 @@\n+workspace(name = \"foo\")\n", diff)
err = helper.WriteFile(fileRef, bf)
require.NoError(err)
contents, err := afero.ReadFile(fs, "WORKSPACE.bazel")
contents, err := afero.ReadFile(fs, "WORKSPACE.bzlmod")
assert.NoError(err)
assert.Equal("workspace(name = \"foo\")\n", string(contents))
diff, err = helper.Diff(fileRef, bf)