Skip to content

Commit

Permalink
mod/modfile: parse module.cue according to language.version
Browse files Browse the repository at this point in the history
This change makes it possible to make changes to the
module.cue schema while still using a closed schema
for earlier versions. We refuse module.cue files that
declare a version newer than the current CUE version.

The language.version field is now mandatory in modules
mode because otherwise we cannot tell which schema
we should be using.

Also remove the unimplemented features from the schema
for now: they're always there in the history and the proposal
when we come to implement them, but they complicate
the schema for no good reason.

One unfortunate thing is that the error message when a field
is defined that's explicitly unimplemented is not good.
In the absence of an `error` CUE builtin, we should be able to
fix that in a subsequent CL by inspecting the error to see
whether any of the lines include the `unimplemented`
identifier.

Signed-off-by: Roger Peppe <[email protected]>
Change-Id: I7bfef3b37e5b66bdbd8fe0614c1b815c7d9f1285
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1193275
TryBot-Result: CUEcueckoo <[email protected]>
Reviewed-by: Daniel Martí <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
  • Loading branch information
rogpeppe committed Apr 18, 2024
1 parent b7c1a0d commit 73b3df2
Show file tree
Hide file tree
Showing 81 changed files with 594 additions and 273 deletions.
3 changes: 2 additions & 1 deletion cmd/cue/cmd/testdata/script/cmd_modules.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ command: print: {
}
-- cue.mod/module.cue --
module: "main.example"

language: version: "v0.8.0"
deps: "foo.example/text@v0": {
default: true
v: "v0.0.1"
Expand All @@ -27,6 +27,7 @@ deps: "foo.example/text@v0": {
package home
-- _registry/foo.example_text_v0.0.1/cue.mod/module.cue --
module: "foo.example/text@v0"
language: version: "v0.8.0"
-- _registry/foo.example_text_v0.0.1/text.cue --
package text
value: "world"
1 change: 1 addition & 0 deletions cmd/cue/cmd/testdata/script/issue-2945-with-modules.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ cmp stdout p.golden

-- cue.mod/module.cue --
module: "mod.example@v0"
language: version: "v0.8.0"
-- x.cue --
package x

Expand Down
2 changes: 2 additions & 0 deletions cmd/cue/cmd/testdata/script/issue2955.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ e.foo

-- cue.mod/module.cue --
module: "test.org"
language: version: "v0.8.0"
-- _registry/auth.json --
{
"useTokenServer": true,
Expand All @@ -39,6 +40,7 @@ module: "test.org"
}
-- _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
Expand Down
16 changes: 16 additions & 0 deletions cmd/cue/cmd/testdata/script/modedit_initial.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,25 @@ cmp cue.mod/module.cue want-module-5

-- cue.mod/module.cue --
module: "main.org@v0"
language: version: "v0.9.0-alpha.0"
-- want-module-1 --
module: "main.org@v0"
language: {
version: "v0.9.0-alpha.0"
}
source: {
kind: "git"
}
-- want-module-2 --
module: "main.org@v0"
language: {
version: "v0.9.0-alpha.0"
}
-- want-module-3 --
module: "main.org@v0"
language: {
version: "v0.9.0-alpha.0"
}
deps: {
"foo.bar@v0": {
v: "v0.2.3"
Expand All @@ -37,5 +47,11 @@ deps: {
invalid argument "bad-module!" for "--require" flag: invalid module path@version "bad-module!"
-- want-module-4 --
module: "main.org@v0"
language: {
version: "v0.9.0-alpha.0"
}
-- want-module-5 --
module: "othermain.org@v1"
language: {
version: "v0.9.0-alpha.0"
}
18 changes: 18 additions & 0 deletions cmd/cue/cmd/testdata/script/modget_initial.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ stderr 'other requirements prevent changing module baz.org@v0 to version v0.5.0

-- want-module-1 --
module: "main.org@v0"
language: {
version: "v0.8.0"
}
deps: {
"bar.com@v0": {
v: "v0.5.0"
Expand All @@ -70,6 +73,9 @@ deps: {
}
-- want-module-2 --
module: "main.org@v0"
language: {
version: "v0.8.0"
}
deps: {
"bar.com@v0": {
v: "v0.5.0"
Expand All @@ -95,6 +101,7 @@ deps: {
}
-- cue.mod/module.cue --
module: "main.org@v0"
language: version: "v0.8.0"
deps: {
"bar.com@v0": {
v: "v0.5.0"
Expand All @@ -119,6 +126,7 @@ main

-- _registry/example.com_v0.0.1/cue.mod/module.cue --
module: "example.com@v0"
language: version: "v0.8.0"
deps: {
"foo.com/bar/hello@v0": v: "v0.2.3"
"bar.com@v0": v: "v0.5.0"
Expand All @@ -134,6 +142,7 @@ main: "main"

-- _registry/example.com_v0.1.2/cue.mod/module.cue --
module: "example.com@v0"
language: version: "v0.8.0"

-- _registry/example.com_v0.1.2/top.cue --
package main
Expand All @@ -146,6 +155,7 @@ main: "main"

-- _registry/foo.com_bar_hello_v0.2.3/cue.mod/module.cue --
module: "foo.com/bar/hello@v0"
language: version: "v0.8.0"
deps: {
"bar.com@v0": v: "v0.0.2"
"baz.org@v0": v: "v0.10.1"
Expand All @@ -164,6 +174,7 @@ b

-- _registry/bar.com_v0.0.2/cue.mod/module.cue --
module: "bar.com@v0"
language: version: "v0.8.0"
deps: "baz.org@v0": v: "v0.0.2"

-- _registry/bar.com_v0.0.2/bar/x.cue --
Expand All @@ -175,6 +186,7 @@ a

-- _registry/bar.com_v0.5.0/cue.mod/module.cue --
module: "bar.com@v0"
language: version: "v0.8.0"
deps: "baz.org@v0": v: "v0.5.0"

-- _registry/bar.com_v0.5.0/bar/x.cue --
Expand All @@ -186,6 +198,7 @@ a

-- _registry/baz.org_v0.0.2/cue.mod/module.cue --
module: "baz.org@v0"
language: version: "v0.8.0"

-- _registry/baz.org_v0.0.2/baz.cue --
package baz
Expand All @@ -194,6 +207,7 @@ package baz

-- _registry/baz.org_v0.1.2/cue.mod/module.cue --
module: "baz.org@v0"
language: version: "v0.8.0"

-- _registry/baz.org_v0.1.2/baz.cue --
package baz
Expand All @@ -202,6 +216,7 @@ package baz

-- _registry/baz.org_v0.5.0/cue.mod/module.cue --
module: "baz.org@v0"
language: version: "v0.8.0"

-- _registry/baz.org_v0.5.0/baz.cue --
package baz
Expand All @@ -210,6 +225,7 @@ package baz

-- _registry/baz.org_v0.10.1/cue.mod/module.cue --
module: "baz.org@v0"
language: version: "v0.8.0"

-- _registry/baz.org_v0.10.1/baz.cue --
package baz
Expand All @@ -218,13 +234,15 @@ package baz

-- _registry/baz.org_v0.10.2/cue.mod/module.cue --
module: "baz.org@v0"
language: version: "v0.8.0"

-- _registry/baz.org_v0.10.2/baz.cue --
package baz
"baz.org@v0": "v0.10.2"

-- _registry/baz.org_v0.11.0-alpha/cue.mod/module.cue --
module: "baz.org@v0"
language: version: "v0.8.0"

-- _registry/baz.org_v0.11.0-alpha/baz.cue --
package baz
Expand Down
7 changes: 7 additions & 0 deletions cmd/cue/cmd/testdata/script/modget_major_version.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ cmp stdout want-stdout

-- want-module --
module: "main.example@v0"
language: {
version: "v0.8.0"
}
deps: {
"foo.org/bar@v2": {
v: "v2.0.0"
Expand All @@ -19,27 +22,31 @@ deps: {
}
-- cue.mod/module.cue --
module: "main.example"
language: version: "v0.8.0"
-- main.cue --
package main
import "foo.org/bar"
bar

-- _registry/foo.org_bar_v2.0.0/cue.mod/module.cue --
module: "foo.org/bar@v2"
language: version: "v0.8.0"

-- _registry/foo.org_bar_v2.0.0/bar.cue --
package bar
"foo.org/bar@v2": "v2.0.0"

-- _registry/foo.org_bar_v1.0.0/cue.mod/module.cue --
module: "foo.org/bar@v1"
language: version: "v0.8.0"

-- _registry/foo.org_bar_v1.0.0/bar.cue --
package bar
"foo.org/bar@v1": "v1.0.0"

-- _registry/foo.org_bar_v1.1.0/cue.mod/module.cue --
module: "foo.org/bar@v1"
language: version: "v0.8.0"

-- _registry/foo.org_bar_v1.1.0/bar.cue --
package bar
Expand Down
6 changes: 3 additions & 3 deletions cmd/cue/cmd/testdata/script/modinit_majorversion.txtar
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
env CUE_VERSION_OVERRIDE=v0.1.2
env CUE_VERSION_OVERRIDE=v0.8.100

# Without the experiment, the major version is allowed,
# even though it's not particularly useful.
Expand All @@ -19,10 +19,10 @@ exists cue.mod/pkg
-- want-module.cue --
module: "foo.com/bar@v1"
language: {
version: "v0.1.2"
version: "v0.8.100"
}
-- want-module-experiment.cue --
module: "foo.com/bar@v1"
language: {
version: "v0.1.2"
version: "v0.8.100"
}
4 changes: 2 additions & 2 deletions cmd/cue/cmd/testdata/script/modinit_noargs.txtar
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TODO we might want to deprecate or remove the ability to create
# module file with an empty module directive.
env CUE_VERSION_OVERRIDE=v0.1.2
env CUE_VERSION_OVERRIDE=v0.8.100
exec cue mod init
cmp cue.mod/module.cue want-module.cue
exists cue.mod/usr
Expand All @@ -9,5 +9,5 @@ exists cue.mod/pkg
-- want-module.cue --
module: ""
language: {
version: "v0.1.2"
version: "v0.8.100"
}
6 changes: 3 additions & 3 deletions cmd/cue/cmd/testdata/script/modinit_nomajorversion.txtar
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
env CUE_VERSION_OVERRIDE=v0.1.2
env CUE_VERSION_OVERRIDE=v0.8.0

# Without the experiment, we use the module path as-is.
exec cue mod init foo.com/bar
Expand All @@ -17,10 +17,10 @@ exists cue.mod/pkg
-- want-module.cue --
module: "foo.com/bar"
language: {
version: "v0.1.2"
version: "v0.8.0"
}
-- want-module-experiment.cue --
module: "foo.com/bar@v0"
language: {
version: "v0.1.2"
version: "v0.8.0"
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Check that cue mod tidy chooses a correct base version
# Check that cue mod init chooses a correct base version
# when provided with a pseudo-version.

env CUE_VERSION_OVERRIDE=v0.7.1-0.20240130142347-7855e15cb701
exec cue mod tidy
env CUE_VERSION_OVERRIDE=v0.8.20-0.20240130142347-7855e15cb701
exec cue mod init main.org
cmp cue.mod/module.cue want-module

# Check that the resulting module evaluates as expected.
Expand All @@ -15,17 +15,14 @@ cmp stdout want-stdout
-- want-module --
module: "main.org@v0"
language: {
version: "v0.7.0"
version: "v0.8.19"
}
-- cue.mod/module.cue --
module: "main.org@v0"

-- main.cue --
package main
x: 1

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

-- _registry/example.com_v0.0.1/top.cue --
package main
17 changes: 6 additions & 11 deletions cmd/cue/cmd/testdata/script/modinit_without_version.txtar
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
# Check that cue mod init skips the language version
# when it lacks any version information at all.
# Check that cue mod init fails when it lacks any version
# information at all.
# A zero pseudo-version is one such case, as there are no semver numbers.
env CUE_EXPERIMENT=modules
env CUE_VERSION_OVERRIDE=v0.0.0-00010101000000-000000000000
exec cue mod init foo.example
cmp cue.mod/module.cue want-module
! exec cue mod init foo.example
cmp stderr want-stderr

# cue mod tidy should be a no-op after cue mod init
env CUE_CACHE_DIR=$WORK/.tmp/cache
exec cue mod tidy
cmp cue.mod/module.cue want-module

-- want-module --
module: "foo.example@v0"
-- want-stderr --
cannot round-trip module file: no language version declared in module.cue
1 change: 1 addition & 0 deletions cmd/cue/cmd/testdata/script/modpublish_no_source.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ cmp stderr want-stderr
no source field found in cue.mod/module.cue
-- cue.mod/module.cue --
module: "x.example@v1"
language: version: "v0.9.0-alpha.0"
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ env CUE_EXPERIMENT=modules
stderr 'git VCS not found in any parent of ".+"'
-- cue.mod/module.cue --
module: "x.example@v1"
language: version: "v0.9.0-alpha.1"

source: kind: "git"
3 changes: 3 additions & 0 deletions cmd/cue/cmd/testdata/script/modtidy_ambiguous_import.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@ failed to resolve "example.com/foo/bar@v0": ambiguous import: found package exam
example.com/foo@v0 v0.1.0 (bar)
-- cue.mod/module.cue --
module: "main.org@v0"
language: version: "v0.8.0"

-- main.cue --
package main
import "example.com/foo/bar@v0"

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

-- _registry/example.com_v0.0.1/foo/bar/x.cue --
package bar

-- _registry/example.com_foo_v0.1.0/cue.mod/module.cue --
module: "example.com/foo@v0"
language: version: "v0.8.0"

-- _registry/example.com_foo_v0.1.0/bar/x.cue --
package bar
3 changes: 2 additions & 1 deletion cmd/cue/cmd/testdata/script/modtidy_check.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exec cue mod tidy --check

-- cue.mod/module.cue --
module: "main.org@v0"
language: version: "v0.99.99"
language: version: "v0.8.100"

// A comment.
deps: "example.com@v0": v: "v0.0.1"
Expand All @@ -19,6 +19,7 @@ main

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

-- _registry/example.com_v0.0.1/top.cue --
package main
Expand Down
Loading

0 comments on commit 73b3df2

Please sign in to comment.