this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

internal/mod/modload: rip out language.version logic from Tidy

https://cuelang.org/cl/1193275 started requiring language.version
to be set when parsing cue.mod/module.cue with CUE_EXPERIMENT=modules,
now a default as of v0.9.0-rc.1.

https://cuelang.org/cl/1194780 then added `cue mod fix` which is now
responsible for adding a language.version field if not present.

Because of the first CL now making `cue mod tidy` fail if
language.version is not declared, and thanks to the second CL
introducing `cue mod fix` for this purpose, we can reomve the old code
which taught `cue mod tidy` to add language.version if missing.

While here, rename two modload txtar files for clarity to reflect
their new behavior, as tidy never adds a version anymore.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: Id357f1a04e908829ea58a2ff127869d190c2a593
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1195718
Reviewed-by: Paul Jolly <paul@myitcv.io>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>

+9 -23
+1 -2
cmd/cue/cmd/modtidy.go
··· 23 23 24 24 "github.com/spf13/cobra" 25 25 26 - "cuelang.org/go/internal/cueversion" 27 26 "cuelang.org/go/internal/mod/modload" 28 27 ) 29 28 ··· 78 77 } 79 78 return err 80 79 } 81 - mf, err := modload.Tidy(ctx, os.DirFS(modRoot), ".", reg, cueversion.LanguageVersion()) 80 + mf, err := modload.Tidy(ctx, os.DirFS(modRoot), ".", reg) 82 81 if err != nil { 83 82 return err 84 83 }
-2
internal/mod/modload/testdata/tidy/addversion.txtar internal/mod/modload/testdata/tidy/noversion.txtar
··· 1 1 # Test that it fails if a version isn't already present. 2 - -- cue-version -- 3 - v1.2.3 4 2 -- want -- 5 3 error: no language version declared in module.cue 6 4 -- tidy-check-error --
-2
internal/mod/modload/testdata/tidy/noaddversion.txtar internal/mod/modload/testdata/tidy/withversion.txtar
··· 1 1 # Test that a version is not added or changed if present 2 - -- cue-version -- 3 - v1.2.3 4 2 -- want -- 5 3 module: "main.org@v0" 6 4 language: {
-2
internal/mod/modload/testdata/tidy/withsource.txtar
··· 1 1 # Test that a version is not added or changed if present 2 - -- cue-version -- 3 - v1.2.3 4 2 -- want -- 5 3 module: "main.org@v0" 6 4 language: {
+6 -13
internal/mod/modload/tidy.go
··· 47 47 // - it includes valid modules for all of its dependencies 48 48 // - it does not include any unnecessary dependencies. 49 49 func CheckTidy(ctx context.Context, fsys fs.FS, modRoot string, reg Registry) error { 50 - _, err := tidy(ctx, fsys, modRoot, reg, "", true) 50 + _, err := tidy(ctx, fsys, modRoot, reg, true) 51 51 return err 52 52 } 53 53 54 54 // Tidy evaluates all the requirements of the given main module, using the given 55 55 // registry to download requirements and returns a resolved and tidied module file. 56 - // If there's no language version in the module file and cueVers is non-empty 57 - // it will be used to populate the language version field. 58 - func Tidy(ctx context.Context, fsys fs.FS, modRoot string, reg Registry, cueVers string) (*modfile.File, error) { 59 - return tidy(ctx, fsys, modRoot, reg, cueVers, false) 56 + func Tidy(ctx context.Context, fsys fs.FS, modRoot string, reg Registry) (*modfile.File, error) { 57 + return tidy(ctx, fsys, modRoot, reg, false) 60 58 } 61 59 62 - func tidy(ctx context.Context, fsys fs.FS, modRoot string, reg Registry, cueVers string, checkTidy bool) (*modfile.File, error) { 60 + func tidy(ctx context.Context, fsys fs.FS, modRoot string, reg Registry, checkTidy bool) (*modfile.File, error) { 63 61 mainModuleVersion, mf, err := readModuleFile(ctx, fsys, modRoot) 64 62 if err != nil { 65 63 return nil, err ··· 104 102 // TODO: provide a reason, perhaps in structured form rather than a string 105 103 return nil, &ErrModuleNotTidy{} 106 104 } 107 - return modfileFromRequirements(mf, rs, cueVers), nil 105 + return modfileFromRequirements(mf, rs), nil 108 106 } 109 107 110 108 // ErrModuleNotTidy is returned by CheckTidy when a module is not tidy, ··· 149 147 return mainModuleVersion, mf, nil 150 148 } 151 149 152 - func modfileFromRequirements(old *modfile.File, rs *modrequirements.Requirements, cueVers string) *modfile.File { 150 + func modfileFromRequirements(old *modfile.File, rs *modrequirements.Requirements) *modfile.File { 153 151 // TODO it would be nice to have some way of automatically including new 154 152 // fields by default when they're added to modfile.File, but we don't 155 153 // want to just copy the entirety of old because that includes ··· 159 157 Language: old.Language, 160 158 Deps: make(map[string]*modfile.Dep), 161 159 Source: old.Source, 162 - } 163 - if cueVers != "" && (mf.Language == nil || mf.Language.Version == "") { 164 - mf.Language = &modfile.Language{ 165 - Version: cueVers, 166 - } 167 160 } 168 161 defaults := rs.DefaultMajorVersions() 169 162 for _, v := range rs.RootModules() {
+1 -1
internal/mod/modload/tidy_test.go
··· 46 46 47 47 var out strings.Builder 48 48 var tidyFile []byte 49 - mf, err := Tidy(context.Background(), tfs, ".", reg, stringFromFile(tfs, "cue-version")) 49 + mf, err := Tidy(context.Background(), tfs, ".", reg) 50 50 if err != nil { 51 51 fmt.Fprintf(&out, "error: %v\n", err) 52 52 } else {
+1 -1
internal/mod/modload/update.go
··· 93 93 } 94 94 } 95 95 rs = modrequirements.NewRequirements(mf.Module, reg, finalVersions, mf.DefaultMajorVersions()) 96 - return modfileFromRequirements(mf, rs, ""), nil 96 + return modfileFromRequirements(mf, rs), nil 97 97 } 98 98 99 99 // resolveUpdateVersions resolves a set of version strings as accepted by [UpdateVersions]