mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-10-01 01:36:09 -04: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 bazelrc presets
|
||||||
import %workspace%/bazel/bazelrc/bazel7.bazelrc
|
import %workspace%/bazel/bazelrc/bazel7.bazelrc
|
||||||
import %workspace%/bazel/bazelrc/convenience.bazelrc
|
import %workspace%/bazel/bazelrc/convenience.bazelrc
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
exports_files([
|
exports_files([
|
||||||
"WORKSPACE.bazel",
|
"WORKSPACE.bzlmod",
|
||||||
])
|
])
|
||||||
|
|
||||||
alias(
|
alias(
|
||||||
|
1
MODULE.bazel
Normal file
1
MODULE.bazel
Normal file
@ -0,0 +1 @@
|
|||||||
|
module(name = "constellation")
|
@ -1,5 +1,10 @@
|
|||||||
workspace(name = "constellation")
|
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")
|
load("//bazel/toolchains:skylib_deps.bzl", "skylib_deps")
|
||||||
|
|
||||||
skylib_deps()
|
skylib_deps()
|
||||||
@ -179,7 +184,7 @@ go_register_toolchains()
|
|||||||
|
|
||||||
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
|
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
|
# gazelle:repo bazel_gazelle
|
||||||
|
|
@ -54,7 +54,7 @@ buildifier_test(
|
|||||||
no_sandbox = True,
|
no_sandbox = True,
|
||||||
tags = ["no-remote-exec"],
|
tags = ["no-remote-exec"],
|
||||||
verbose = True,
|
verbose = True,
|
||||||
workspace = "//:WORKSPACE.bazel",
|
workspace = "//:WORKSPACE.bzlmod",
|
||||||
)
|
)
|
||||||
|
|
||||||
buildifier(
|
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
|
## 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
|
```starlark
|
||||||
load("@io_bazel_rules_go//go:deps.bzl", "go_download_sdk", "go_register_toolchains", "go_rules_dependencies")
|
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/`.
|
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:
|
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
|
- 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
|
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) {
|
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{
|
return BazelFile{
|
||||||
RelPath: "WORKSPACE.bazel",
|
RelPath: "WORKSPACE.bzlmod",
|
||||||
AbsPath: filepath.Join(h.workspaceRoot, "WORKSPACE.bazel"),
|
AbsPath: filepath.Join(h.workspaceRoot, "WORKSPACE.bzlmod"),
|
||||||
Type: BazelFileTypeWorkspace,
|
Type: BazelFileTypeWorkspace,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@ -151,7 +151,7 @@ type BazelFileType int
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
BazelFileTypeBzl = iota // BazelFileTypeBzl is a .bzl file
|
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.
|
// 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": {
|
"only WORKSPACE.bzlmod file": {
|
||||||
files: []string{"WORKSPACE.bazel"},
|
files: []string{"WORKSPACE.bzlmod"},
|
||||||
wantFiles: []BazelFile{
|
wantFiles: []BazelFile{
|
||||||
{
|
{
|
||||||
RelPath: "WORKSPACE.bazel",
|
RelPath: "WORKSPACE.bzlmod",
|
||||||
AbsPath: "/WORKSPACE.bazel",
|
AbsPath: "/WORKSPACE.bzlmod",
|
||||||
Type: BazelFileTypeWorkspace,
|
Type: BazelFileTypeWorkspace,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"both WORKSPACE and WORKSPACE.bazel files": {
|
"both WORKSPACE and WORKSPACE.bzlmod files": {
|
||||||
files: []string{"WORKSPACE", "WORKSPACE.bazel"},
|
files: []string{"WORKSPACE", "WORKSPACE.bzlmod"},
|
||||||
wantFiles: []BazelFile{
|
wantFiles: []BazelFile{
|
||||||
{
|
{
|
||||||
RelPath: "WORKSPACE.bazel",
|
RelPath: "WORKSPACE.bzlmod",
|
||||||
AbsPath: "/WORKSPACE.bazel",
|
AbsPath: "/WORKSPACE.bzlmod",
|
||||||
Type: BazelFileTypeWorkspace,
|
Type: BazelFileTypeWorkspace,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -67,11 +67,11 @@ func TestFindFiles(t *testing.T) {
|
|||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
"all kinds": {
|
"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{
|
wantFiles: []BazelFile{
|
||||||
{
|
{
|
||||||
RelPath: "WORKSPACE.bazel",
|
RelPath: "WORKSPACE.bzlmod",
|
||||||
AbsPath: "/WORKSPACE.bazel",
|
AbsPath: "/WORKSPACE.bzlmod",
|
||||||
Type: BazelFileTypeWorkspace,
|
Type: BazelFileTypeWorkspace,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -216,15 +216,15 @@ func TestDiff(t *testing.T) {
|
|||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
require := require.New(t)
|
require := require.New(t)
|
||||||
fs := afero.NewMemMapFs()
|
fs := afero.NewMemMapFs()
|
||||||
err := afero.WriteFile(fs, "WORKSPACE.bazel", []byte(""), 0o644)
|
err := afero.WriteFile(fs, "WORKSPACE.bzlmod", []byte(""), 0o644)
|
||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
helper := Helper{
|
helper := Helper{
|
||||||
fs: fs,
|
fs: fs,
|
||||||
workspaceRoot: "/",
|
workspaceRoot: "/",
|
||||||
}
|
}
|
||||||
fileRef := BazelFile{
|
fileRef := BazelFile{
|
||||||
RelPath: "WORKSPACE.bazel",
|
RelPath: "WORKSPACE.bzlmod",
|
||||||
AbsPath: "/WORKSPACE.bazel",
|
AbsPath: "/WORKSPACE.bzlmod",
|
||||||
Type: BazelFileTypeWorkspace,
|
Type: BazelFileTypeWorkspace,
|
||||||
}
|
}
|
||||||
bf, err := helper.LoadFile(fileRef)
|
bf, err := helper.LoadFile(fileRef)
|
||||||
@ -247,10 +247,10 @@ func TestDiff(t *testing.T) {
|
|||||||
)
|
)
|
||||||
diff, err = helper.Diff(fileRef, bf)
|
diff, err = helper.Diff(fileRef, bf)
|
||||||
require.NoError(err)
|
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)
|
err = helper.WriteFile(fileRef, bf)
|
||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
contents, err := afero.ReadFile(fs, "WORKSPACE.bazel")
|
contents, err := afero.ReadFile(fs, "WORKSPACE.bzlmod")
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.Equal("workspace(name = \"foo\")\n", string(contents))
|
assert.Equal("workspace(name = \"foo\")\n", string(contents))
|
||||||
diff, err = helper.Diff(fileRef, bf)
|
diff, err = helper.Diff(fileRef, bf)
|
||||||
|
Loading…
Reference in New Issue
Block a user