Skip to content

Commit a51a98f

Browse files
committed
internal/cueexperiment: prevent disabling modules experiment
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]>
1 parent a7ccc0a commit a51a98f

9 files changed

+21
-70
lines changed

cmd/cue/cmd/testdata/script/def_proto.txtar

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
env CUE_EXPERIMENT=modules=0
2-
exec cue def policy.proto -p api -I include
3-
cmp stdout expect-stdout
4-
51
env CUE_EXPERIMENT=modules
62
exec cue def policy.proto -p api -I include
73
cmp stdout expect-stdout

cmd/cue/cmd/testdata/script/modinit_majorversion.txtar

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
env-fill want-module.cue
22
env-fill want-module-experiment.cue
33

4-
# Without the experiment, the major version is allowed,
5-
# even though it's not particularly useful.
6-
# It feels unnecessary to ask the user to re-run with the experiment.
4+
# No way of disabling the modules experiment.
75
env CUE_EXPERIMENT=modules=0
8-
exec cue mod init foo.com/bar@v1
9-
cmp cue.mod/module.cue want-module.cue
10-
exists cue.mod/usr
11-
exists cue.mod/pkg
6+
! exec cue mod init foo.com/bar@v1
7+
stderr 'cannot change default value of deprecated flag "modules"'
128

139
# With the experiment, it works as expected.
1410
env CUE_EXPERIMENT=modules

cmd/cue/cmd/testdata/script/modinit_nomajorversion.txtar

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
env-fill want-module.cue
22
env-fill want-module-experiment.cue
33

4-
# Without the experiment, we use the module path as-is.
5-
env CUE_EXPERIMENT=modules=false
6-
exec cue mod init foo.com/bar
7-
cmp cue.mod/module.cue want-module.cue
8-
exists cue.mod/usr
9-
exists cue.mod/pkg
4+
# No way of disabling the modules experiment.
5+
env CUE_EXPERIMENT=modules=0
6+
! exec cue mod init foo.com/bar
7+
stderr 'cannot change default value of deprecated flag "modules"'
108

119
# With the experiment, although the major version will be implied
1210
# as v0, it's still omitted so that there's a possibility of compatibility

cmd/cue/cmd/testdata/script/modpublish_registry_not_enabled.txtar

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ env CUE_EXPERIMENT=modules=false
22
! exec cue mod publish v1.0.0
33
cmp stderr want-stderr
44
-- want-stderr --
5-
modules experiment not enabled (enable with CUE_EXPERIMENT=modules)
5+
cannot parse CUE_EXPERIMENT: cannot change default value of deprecated flag "modules"

cmd/cue/cmd/testdata/script/modtidy_registry_not_enabled.txtar

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ env CUE_EXPERIMENT=modules=0
33
! exec cue mod tidy
44
cmp stderr want-stderr
55
-- want-stderr --
6-
modules experiment not enabled (enable with CUE_EXPERIMENT=modules)
6+
cannot parse CUE_EXPERIMENT: cannot change default value of deprecated flag "modules"
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,5 @@
1-
# When CUE_EXPERIMENT is disabled, the CUE_REGISTRY
2-
# variable is ignored, as are the new fields in module.cue
1+
# When CUE_EXPERIMENT is disabled, we cannot use the cue command.
32

43
env CUE_EXPERIMENT=modules=false
5-
exec cue export .
6-
cmp stdout expect-stdout
7-
8-
-- expect-stdout --
9-
"cue.mod/pkg source"
10-
-- main.cue --
11-
package main
12-
import "example.com/e"
13-
14-
e.foo
15-
16-
-- cue.mod/module.cue --
17-
module: "test.org"
18-
language: version: "v0.9.0"
19-
// This should be ignored.
20-
deps: "example.com/e": v: "v0.0.1"
21-
-- cue.mod/pkg/example.com/e/cue.mod/module.cue --
22-
module: "example.com/e"
23-
language: version: "v0.8.0"
24-
-- cue.mod/pkg/example.com/e/main.cue --
25-
package e
26-
foo: "cue.mod/pkg source"
27-
28-
-- _registry/example.com_e_v0.0.1/cue.mod/module.cue --
29-
module: "example.com/e@v0"
30-
language: version: "v0.8.0"
31-
32-
-- _registry/example.com_e_v0.0.1/main.cue --
33-
package e
34-
35-
foo: "registry source"
4+
! exec cue export .
5+
stderr 'cannot change default value of deprecated flag "modules"'

cmd/cue/cmd/testdata/script/registry_modules_disabled_warning.txtar

-14
This file was deleted.

internal/cueexperiment/exp.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
// When adding, deleting, or modifying entries below,
1212
// update cmd/cue/cmd/help.go as well for `cue help environment`.
1313
var Flags struct {
14-
Modules bool `envflag:"default:true"`
14+
Modules bool `envflag:"deprecated,default:true"`
1515

1616
// YAMLV3Decoder swaps the old internal/third_party/yaml decoder with the new
1717
// decoder implemented in internal/encoding/yaml on top of yaml.v3.

internal/cueexperiment/exp_test.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,15 @@ func TestInit(t *testing.T) {
2323
qt.Assert(t, qt.IsTrue(Flags.Modules))
2424
qt.Assert(t, qt.IsTrue(Flags.YAMLV3Decoder))
2525

26-
// Check that we can disable all experiments.
27-
t.Setenv("CUE_EXPERIMENT", "modules=0,yamlv3decoder=0")
26+
// Check that we can disable the YAML v3 experiment.
27+
t.Setenv("CUE_EXPERIMENT", "yamlv3decoder=0")
2828
err = initAlways()
2929
qt.Assert(t, qt.IsNil(err))
30-
qt.Assert(t, qt.IsFalse(Flags.Modules))
30+
qt.Assert(t, qt.IsTrue(Flags.Modules))
3131
qt.Assert(t, qt.IsFalse(Flags.YAMLV3Decoder))
32+
33+
// Check that we cannot disable the modules experiment.
34+
t.Setenv("CUE_EXPERIMENT", "modules=0")
35+
err = initAlways()
36+
qt.Assert(t, qt.ErrorMatches(err, `cannot parse CUE_EXPERIMENT: cannot change default value of deprecated flag "modules"`))
3237
}

0 commit comments

Comments
 (0)