mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-12-23 14:39:40 -05:00
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:
parent
d0bab9eb08
commit
8796edc9ad
6
.bazelrc
6
.bazelrc
@ -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
|
||||
|
@ -1,5 +1,5 @@
|
||||
exports_files([
|
||||
"WORKSPACE.bazel",
|
||||
"WORKSPACE.bzlmod",
|
||||
])
|
||||
|
||||
alias(
|
||||
|
1
MODULE.bazel
Normal file
1
MODULE.bazel
Normal file
@ -0,0 +1 @@
|
||||
module(name = "constellation")
|
@ -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
|
||||
|
@ -54,7 +54,7 @@ buildifier_test(
|
||||
no_sandbox = True,
|
||||
tags = ["no-remote-exec"],
|
||||
verbose = True,
|
||||
workspace = "//:WORKSPACE.bazel",
|
||||
workspace = "//:WORKSPACE.bzlmod",
|
||||
)
|
||||
|
||||
buildifier(
|
||||
|
@ -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`."""
|
||||
|
@ -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")
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user