Skip to content

Commit

Permalink
cue/load: remove unused code from the modules refactors
Browse files Browse the repository at this point in the history
Recent commits have added support for fetching, caching, and loading
CUE modules via the cue/load API. Moreover, there were refactors
such as https://cuelang.org/cl/1175995 which taught cue/load
how to reuse the same packages as cmd/cue such as mod/modpkgload.

After these changes, we had left a number of types and funcs behind.
Remove them, and since module.go would now have just one Config method,
move that into config.go as it is still under 500 lines of code.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I0b9ea0ef535ef19d0a4ffb736580fd3f70ab5ee7
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1177663
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@gmail.com>
  • Loading branch information
mvdan committed Mar 4, 2024
1 parent 77936ec commit c5e67f2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 191 deletions.
45 changes: 45 additions & 0 deletions cue/load/config.go
Expand Up @@ -388,6 +388,51 @@ func (c Config) complete() (cfg *Config, err error) {
return &c, nil
}

// loadModule loads the module file, resolves and downloads module
// dependencies. It sets c.Module if it's empty or checks it for
// consistency with the module file otherwise.
func (c *Config) loadModule() error {
// TODO: also make this work if run from outside the module?
mod := filepath.Join(c.ModuleRoot, modDir)
info, cerr := c.fileSystem.stat(mod)
if cerr != nil {
return nil
}
// TODO remove support for legacy non-directory module.cue file
// by returning an error if info.IsDir is false.
if info.IsDir() {
mod = filepath.Join(mod, moduleFile)
}
f, cerr := c.fileSystem.openFile(mod)
if cerr != nil {
return nil
}
defer f.Close()
data, err := io.ReadAll(f)
if err != nil {
return err
}
parseModFile := modfile.ParseNonStrict
if c.Registry == nil {
parseModFile = modfile.ParseLegacy
}
mf, err := parseModFile(data, mod)
if err != nil {
return err
}
c.modFile = mf
if mf.Module == "" {
// Backward compatibility: allow empty module.cue file.
// TODO maybe check that the rest of the fields are empty too?
return nil
}
if c.Module != "" && c.Module != mf.Module {
return errors.Newf(token.NoPos, "inconsistent modules: got %q, want %q", mf.Module, c.Module)
}
c.Module = mf.Module
return nil
}

func (c Config) isRoot(dir string) bool {
fs := &c.fileSystem
// Note: cue.mod used to be a file. We still allow both to match.
Expand Down
191 changes: 0 additions & 191 deletions cue/load/module.go

This file was deleted.

0 comments on commit c5e67f2

Please sign in to comment.