Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/cue: add version to module.cue file
We build on https://cuelang.org/cl/1173894 by providing the version when available. We now support the `$CUE_VERSION_OVERRIDE` environment variable mainly for testing, but also because it might potentially be useful in the future. Signed-off-by: Roger Peppe <rogpeppe@gmail.com> Change-Id: I081a056864a28456b3a8f63fdbdb14482649ac4d Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1176194 Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com> TryBot-Result: CUEcueckoo <cueckoo@cuelang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
- Loading branch information
Showing
6 changed files
with
214 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
cmd/cue/cmd/testdata/script/modtidy_with_existing_version.txtar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Check that cue mod tidy won't change the language | ||
# version when the field is already present in the module.cue file. | ||
|
||
env CUE_VERSION_OVERRIDE=v0.9.9 | ||
exec cue mod tidy | ||
cmp cue.mod/module.cue want-module | ||
|
||
|
||
# Check that the resulting module evaluates as expected. | ||
exec cue export . | ||
cmp stdout want-stdout | ||
-- want-stdout -- | ||
{ | ||
"x": 1 | ||
} | ||
-- want-module -- | ||
module: "main.org@v0" | ||
language: { | ||
version: "v0.1.2" | ||
} | ||
-- cue.mod/module.cue -- | ||
module: "main.org@v0" | ||
language: { | ||
version: "v0.1.2" | ||
} | ||
|
||
-- main.cue -- | ||
package main | ||
x: 1 | ||
|
||
-- _registry/example.com_v0.0.1/cue.mod/module.cue -- | ||
module: "example.com@v0" | ||
|
||
-- _registry/example.com_v0.0.1/top.cue -- | ||
package main |
31 changes: 31 additions & 0 deletions
31
cmd/cue/cmd/testdata/script/modtidy_with_pseudoversion.txtar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Check that cue mod tidy 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 | ||
cmp cue.mod/module.cue want-module | ||
|
||
# Check that the resulting module evaluates as expected. | ||
exec cue export . | ||
cmp stdout want-stdout | ||
-- want-stdout -- | ||
{ | ||
"x": 1 | ||
} | ||
-- want-module -- | ||
module: "main.org@v0" | ||
language: { | ||
version: "v0.7.0" | ||
} | ||
-- 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" | ||
|
||
-- _registry/example.com_v0.0.1/top.cue -- | ||
package main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Check that cue mod tidy does not add the language version | ||
# to the module.cue file when it's a dev version created | ||
# by cue-internal logic. | ||
|
||
env CUE_VERSION_TEST_CFG='[{"Key":"vcs","Value":"git"},{"Key":"vcs.revision","Value":"47b7032385cb490fab7d47b89fca36835cf13d39"},{"Key":"vcs.time","Value":"2022-05-10T04:58:46Z"},{"Key":"vcs.modified","Value":"true"}]' | ||
exec cue mod tidy | ||
cmp cue.mod/module.cue want-module | ||
|
||
# Check that the resulting module evaluates as expected. | ||
exec cue export . | ||
cmp stdout want-stdout | ||
-- want-stdout -- | ||
{ | ||
"x": 1 | ||
} | ||
-- want-module -- | ||
module: "main.org@v0" | ||
-- 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" | ||
|
||
-- _registry/example.com_v0.0.1/top.cue -- | ||
package main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Check that cue mod tidy adds the language version to the | ||
# module.cue file when there is one. Note that because | ||
# the version is taken from the build info, we need to use | ||
# the CUE_VERSION_OVERRIDE environment variable. | ||
# We get confidence in the actual buildinfo logic because exactly | ||
# the same code is used behind the scenes for the `cue version` | ||
# implementation too. | ||
|
||
env CUE_VERSION_OVERRIDE=v0.1.2 | ||
exec cue mod tidy | ||
cmp cue.mod/module.cue want-module | ||
|
||
# Check that the resulting module evaluates as expected. | ||
exec cue export . | ||
cmp stdout want-stdout | ||
-- want-stdout -- | ||
{ | ||
"x": 1 | ||
} | ||
-- want-module -- | ||
module: "main.org@v0" | ||
language: { | ||
version: "v0.1.2" | ||
} | ||
-- 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" | ||
|
||
-- _registry/example.com_v0.0.1/top.cue -- | ||
package main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters