Skip to content

Commit

Permalink
internal/cueexperiment: prevent disabling modules experiment
Browse files Browse the repository at this point in the history
This change deprecates the modules experiment flag, meaning
that modules will always be enabled. We do not yet remove the code to
deal with disabled modules, meaning that it will be straightforward
to revert this change if it turns out to be necessary.

Signed-off-by: Roger Peppe <[email protected]>
Change-Id: I846ea4cdbe15c871c3cd92d40cbc5b8809b7b67d
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1200580
Reviewed-by: Daniel Martí <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
  • Loading branch information
rogpeppe committed Sep 3, 2024
1 parent a7ccc0a commit a51a98f
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 70 deletions.
4 changes: 0 additions & 4 deletions cmd/cue/cmd/testdata/script/def_proto.txtar
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
env CUE_EXPERIMENT=modules=0
exec cue def policy.proto -p api -I include
cmp stdout expect-stdout

env CUE_EXPERIMENT=modules
exec cue def policy.proto -p api -I include
cmp stdout expect-stdout
Expand Down
10 changes: 3 additions & 7 deletions cmd/cue/cmd/testdata/script/modinit_majorversion.txtar
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
env-fill want-module.cue
env-fill want-module-experiment.cue

# Without the experiment, the major version is allowed,
# even though it's not particularly useful.
# It feels unnecessary to ask the user to re-run with the experiment.
# No way of disabling the modules experiment.
env CUE_EXPERIMENT=modules=0
exec cue mod init foo.com/bar@v1
cmp cue.mod/module.cue want-module.cue
exists cue.mod/usr
exists cue.mod/pkg
! 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
Expand Down
10 changes: 4 additions & 6 deletions cmd/cue/cmd/testdata/script/modinit_nomajorversion.txtar
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
env-fill want-module.cue
env-fill want-module-experiment.cue

# Without the experiment, we use the module path as-is.
env CUE_EXPERIMENT=modules=false
exec cue mod init foo.com/bar
cmp cue.mod/module.cue want-module.cue
exists cue.mod/usr
exists cue.mod/pkg
# 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ env CUE_EXPERIMENT=modules=false
! exec cue mod publish v1.0.0
cmp stderr want-stderr
-- want-stderr --
modules experiment not enabled (enable with CUE_EXPERIMENT=modules)
cannot parse CUE_EXPERIMENT: cannot change default value of deprecated flag "modules"
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ env CUE_EXPERIMENT=modules=0
! exec cue mod tidy
cmp stderr want-stderr
-- want-stderr --
modules experiment not enabled (enable with CUE_EXPERIMENT=modules)
cannot parse CUE_EXPERIMENT: cannot change default value of deprecated flag "modules"
36 changes: 3 additions & 33 deletions cmd/cue/cmd/testdata/script/registry_modules_disabled.txtar
Original file line number Diff line number Diff line change
@@ -1,35 +1,5 @@
# When CUE_EXPERIMENT is disabled, the CUE_REGISTRY
# variable is ignored, as are the new fields in module.cue
# When CUE_EXPERIMENT is disabled, we cannot use the cue command.

env CUE_EXPERIMENT=modules=false
exec cue export .
cmp stdout expect-stdout

-- expect-stdout --
"cue.mod/pkg source"
-- main.cue --
package main
import "example.com/e"

e.foo

-- cue.mod/module.cue --
module: "test.org"
language: version: "v0.9.0"
// This should be ignored.
deps: "example.com/e": v: "v0.0.1"
-- cue.mod/pkg/example.com/e/cue.mod/module.cue --
module: "example.com/e"
language: version: "v0.8.0"
-- cue.mod/pkg/example.com/e/main.cue --
package e
foo: "cue.mod/pkg source"

-- _registry/example.com_e_v0.0.1/cue.mod/module.cue --
module: "example.com/e@v0"
language: version: "v0.8.0"

-- _registry/example.com_e_v0.0.1/main.cue --
package e

foo: "registry source"
! exec cue export .
stderr 'cannot change default value of deprecated flag "modules"'

This file was deleted.

2 changes: 1 addition & 1 deletion internal/cueexperiment/exp.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
// When adding, deleting, or modifying entries below,
// update cmd/cue/cmd/help.go as well for `cue help environment`.
var Flags struct {
Modules bool `envflag:"default:true"`
Modules bool `envflag:"deprecated,default:true"`

// YAMLV3Decoder swaps the old internal/third_party/yaml decoder with the new
// decoder implemented in internal/encoding/yaml on top of yaml.v3.
Expand Down
11 changes: 8 additions & 3 deletions internal/cueexperiment/exp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@ func TestInit(t *testing.T) {
qt.Assert(t, qt.IsTrue(Flags.Modules))
qt.Assert(t, qt.IsTrue(Flags.YAMLV3Decoder))

// Check that we can disable all experiments.
t.Setenv("CUE_EXPERIMENT", "modules=0,yamlv3decoder=0")
// Check that we can disable the YAML v3 experiment.
t.Setenv("CUE_EXPERIMENT", "yamlv3decoder=0")
err = initAlways()
qt.Assert(t, qt.IsNil(err))
qt.Assert(t, qt.IsFalse(Flags.Modules))
qt.Assert(t, qt.IsTrue(Flags.Modules))
qt.Assert(t, qt.IsFalse(Flags.YAMLV3Decoder))

// Check that we cannot disable the modules experiment.
t.Setenv("CUE_EXPERIMENT", "modules=0")
err = initAlways()
qt.Assert(t, qt.ErrorMatches(err, `cannot parse CUE_EXPERIMENT: cannot change default value of deprecated flag "modules"`))
}

0 comments on commit a51a98f

Please sign in to comment.