Skip to content

Commit

Permalink
all: sunset CUE_EXPERIMENT=modules
Browse files Browse the repository at this point in the history
The experiment was introduced in late 2023, and enabled by default
in v0.9.0 released in June 2024. Given that there were no more known
regressions or issues with the new modules implementation,
v0.11.0 was released in November 2024 with CUE_EXPERIMENT=modules=0
being deprecated and no longer allowed.

The upcoming v0.12 release can then remove all the code supporting
the modules experiment, as we can now start assuming that the new
modules implementation will always be used.

This first change removes all direct uses of the experiment flag.
A follow-up change will do some cleanups in cue/load.
We don't remove the flag definition itself yet, as lots of CUE users
were (and still may be) setting CUE_EXPERIMENT=modules,
so there's no hurry to break them. Moreover, using tools like
`git bisect` is easier if the same env var can be used across a wider
range of CUE versions.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I4083977be6433b91a17a66705ac28749d262a14e
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1205858
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
  • Loading branch information
mvdan committed Dec 16, 2024
1 parent 950f7fb commit c8033e9
Show file tree
Hide file tree
Showing 16 changed files with 16 additions and 107 deletions.
10 changes: 2 additions & 8 deletions cmd/cue/cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,17 @@ inside $CUE_CONFIG_DIR; see 'cue help environment'.
Args: cobra.MaximumNArgs(1),
RunE: mkRunE(c, func(cmd *Command, args []string) error {
var locResolver modresolve.LocationResolver
var err error
if len(args) > 0 {
var err error
locResolver, err = modresolve.ParseCUERegistry(args[0], "")
if err != nil {
return err
}
} else {
resolver, err := getRegistryResolver()
locResolver, err = getRegistryResolver()
if err != nil {
return err
}
// We need to do this nil check before we assign to locResolver,
// otherwise the interface gets filled with a typed nil, which is not nil.
if resolver == nil {
return fmt.Errorf("cannot log in when modules are not enabled")
}
locResolver = resolver
}
registryHosts := locResolver.AllHosts()
if len(registryHosts) > 1 {
Expand Down
3 changes: 0 additions & 3 deletions cmd/cue/cmd/modget.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ func runModGet(cmd *Command, args []string) error {
if err != nil {
return err
}
if reg == nil {
return fmt.Errorf("modules experiment not enabled (enable with CUE_EXPERIMENT=modules)")
}
ctx := backgroundContext()
modRoot, err := findModuleRoot()
if err != nil {
Expand Down
3 changes: 0 additions & 3 deletions cmd/cue/cmd/modpublish.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ func runModUpload(cmd *Command, args []string) error {
if err != nil {
return err
}
if resolver0 == nil {
return fmt.Errorf("modules experiment not enabled (enable with CUE_EXPERIMENT=modules)")
}
dryRun := flagDryRun.Bool(cmd)
outDir := flagOut.String(cmd)
useJSON := flagJSON.Bool(cmd)
Expand Down
3 changes: 0 additions & 3 deletions cmd/cue/cmd/modresolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ func runModResolve(cmd *Command, args []string) error {
if err != nil {
return err
}
if resolver == nil {
return fmt.Errorf("modules experiment not enabled (enable with CUE_EXPERIMENT=modules)")
}
var mf *modfile.File
if len(args) == 0 {
// Use the current module if no arguments are provided.
Expand Down
3 changes: 0 additions & 3 deletions cmd/cue/cmd/modtidy.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ func runModTidy(cmd *Command, args []string) error {
if err != nil {
return err
}
if reg == nil {
return fmt.Errorf("modules experiment not enabled (enable with CUE_EXPERIMENT=modules)")
}
ctx := backgroundContext()
modRoot, err := findModuleRoot()
if err != nil {
Expand Down
27 changes: 0 additions & 27 deletions cmd/cue/cmd/registry.go
Original file line number Diff line number Diff line change
@@ -1,37 +1,23 @@
package cmd

import (
"fmt"
"log/slog"
"net/http"
"os"
"sync"

"cuelang.org/go/internal/cuedebug"
"cuelang.org/go/internal/cueexperiment"
"cuelang.org/go/internal/httplog"
"cuelang.org/go/internal/mod/modload"
"cuelang.org/go/mod/modconfig"
)

var ignoringCUERegistryOnce sync.Once

// getRegistryResolver returns an implementation of [modregistry.Resolver]
// that resolves to registries as specified in the configuration.
//
// If external modules are disabled and there's no other issue,
// it returns (nil, nil).
func getRegistryResolver() (*modconfig.Resolver, error) {
if !modulesExperimentEnabled() {
return nil, nil
}
return modconfig.NewResolver(newModConfig())
}

func getCachedRegistry() (modload.Registry, error) {
if !modulesExperimentEnabled() {
return nil, nil
}
return modconfig.NewRegistry(newModConfig())
}

Expand All @@ -55,16 +41,3 @@ func httpTransport() http.RoundTripper {
},
})
}

func modulesExperimentEnabled() bool {
if cueexperiment.Flags.Modules {
return true
}
if os.Getenv("CUE_REGISTRY") != "" {
ignoringCUERegistryOnce.Do(func() {
fmt.Fprintf(os.Stderr, "warning: ignoring CUE_REGISTRY because modules experiment is not enabled. Set CUE_EXPERIMENT=modules to enable it.\n")
})
}
return false

}
1 change: 0 additions & 1 deletion cmd/cue/cmd/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ func TestScript(t *testing.T) {
if err != nil {
return fmt.Errorf("cannot read workdir: %v", err)
}
// As modules are enabled by default, we always want a cache directory.
// Since os.UserCacheDir relies on OS-specific env vars that we don't set,
// explicitly set up the cache directory somewhere predictable.
e.Vars = append(e.Vars, "CUE_CACHE_DIR="+filepath.Join(e.WorkDir, ".tmp/cache"))
Expand Down
7 changes: 0 additions & 7 deletions cmd/cue/cmd/testdata/script/modinit_majorversion.txtar
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
env-fill want-module.cue
env-fill want-module-experiment.cue

# No way of disabling the modules experiment.
env CUE_EXPERIMENT=modules=0
! exec cue mod init foo.com/bar@v1
stderr 'cannot change default value of deprecated flag "modules"'

# With the experiment, it works as expected.
env CUE_EXPERIMENT=modules
rm cue.mod
exec cue mod init foo.com/bar@v1
cmp cue.mod/module.cue want-module-experiment.cue
Expand Down
11 changes: 2 additions & 9 deletions cmd/cue/cmd/testdata/script/modinit_nomajorversion.txtar
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
env-fill want-module.cue
env-fill want-module-experiment.cue

# No way of disabling the modules experiment.
env CUE_EXPERIMENT=modules=0
! exec cue mod init foo.com/bar
stderr 'cannot change default value of deprecated flag "modules"'

# With the experiment, although the major version will be implied
# as v0, it's still omitted so that there's a possibility of compatibility
# Although the major version will be implied as v0,
# it's still omitted so that there's a possibility of compatibility
# with earlier cue versions.
env CUE_EXPERIMENT=modules
rm cue.mod
exec cue mod init foo.com/bar
cmp cue.mod/module.cue want-module-experiment.cue
exists cue.mod/usr
Expand Down

This file was deleted.

5 changes: 0 additions & 5 deletions cmd/cue/cmd/testdata/script/registry_modules_disabled.txtar

This file was deleted.

26 changes: 10 additions & 16 deletions cue/load/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"cuelang.org/go/cue/errors"
"cuelang.org/go/cue/token"
"cuelang.org/go/internal"
"cuelang.org/go/internal/cueexperiment"
"cuelang.org/go/mod/modconfig"
"cuelang.org/go/mod/modfile"
"cuelang.org/go/mod/module"
Expand Down Expand Up @@ -371,22 +370,17 @@ func (c Config) complete() (cfg *Config, err error) {
// We should never use the registry in SkipImports mode
// but nil it out to be sure.
c.Registry = nil
} else {
// Note: if cueexperiment.Flags.Modules _isn't_ set but c.Registry
// is, we consider that a good enough hint that modules support
// should be enabled and hence don't return an error in that case.
if cueexperiment.Flags.Modules && c.Registry == nil {
registry, err := modconfig.NewRegistry(&modconfig.Config{
Env: c.Env,
})
if err != nil {
// If there's an error in the registry configuration,
// don't error immediately, but only when we actually
// need to resolve modules.
registry = errorRegistry{err}
}
c.Registry = registry
} else if c.Registry == nil {
registry, err := modconfig.NewRegistry(&modconfig.Config{
Env: c.Env,
})
if err != nil {
// If there's an error in the registry configuration,
// don't error immediately, but only when we actually
// need to resolve modules.
registry = errorRegistry{err}
}
c.Registry = registry
}
if err := c.loadModule(); err != nil {
return nil, err
Expand Down
6 changes: 0 additions & 6 deletions cue/load/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (

"cuelang.org/go/cue/ast"
"cuelang.org/go/cue/build"
"cuelang.org/go/internal/cueexperiment"
"cuelang.org/go/internal/filetypes"
"cuelang.org/go/internal/mod/modimports"
"cuelang.org/go/internal/mod/modpkgload"
Expand All @@ -42,11 +41,6 @@ func Instances(args []string, c *Config) []*build.Instance {
if c == nil {
c = &Config{}
}
// We want to consult the CUE_EXPERIMENT flag to see whether
// consult external registries by default.
if err := cueexperiment.Init(); err != nil {
return []*build.Instance{c.newErrInstance(err)}
}
newC, err := c.complete()
if err != nil {
return []*build.Instance{c.newErrInstance(err)}
Expand Down
9 changes: 0 additions & 9 deletions cue/load/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,10 @@ import (
"cuelang.org/go/cue/cuecontext"
"cuelang.org/go/cue/errors"
"cuelang.org/go/cue/format"
"cuelang.org/go/internal/cueexperiment"
"cuelang.org/go/internal/tdtest"
)

func init() {
// Ignore the value of CUE_EXPERIMENT for the purposes of these tests,
// as we want them to start off with the default experiment values.
os.Setenv("CUE_EXPERIMENT", "")

// Once we've called cueexperiment.Init, cueexperiment.Vars
// will not be touched again, so we can set fields in it for the tests.
cueexperiment.Init()

// The user running `go test` might have a broken environment,
// such as an invalid $CUE_REGISTRY like the one below,
// or a broken $DOCKER_CONFIG/config.json due to syntax errors.
Expand Down
2 changes: 0 additions & 2 deletions cue/load/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ func TestModuleFetch(t *testing.T) {
qt.Assert(t, qt.IsNil(err))
defer r.Close()

// We're testing that the default modconfig-based behavour works
// as expected when the modules experiment is enabled.
tmpDir := t.TempDir()
t.LoadConfig.Env = []string{
"CUE_CACHE_DIR=" + filepath.Join(tmpDir, "cache"),
Expand Down
2 changes: 2 additions & 0 deletions internal/cueexperiment/exp.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
// When adding, deleting, or modifying entries below,
// update cmd/cue/cmd/help.go as well for `cue help environment`.
var Flags struct {
// TODO(mvdan): remove in December 2025; leaving it around for now
// so that we delay breaking any users enabling this experiment.
Modules bool `envflag:"deprecated,default:true"`

// EvalV3 enables the new evaluator. The new evaluator addresses various
Expand Down

0 comments on commit c8033e9

Please sign in to comment.