Skip to content

Commit

Permalink
cue/load: deprecate Config.StdRoot
Browse files Browse the repository at this point in the history
This field has not had the intended effect ever since
commit 96ef9aa,
and it seems dubious in principle anyway, so deprecate it.

Also factor out the "is standard library" functionality
to its own function and add a TODO in passing.

Signed-off-by: Roger Peppe <[email protected]>
Change-Id: Idf055a8139393908acdaf35820a005d8241ec4a0
Dispatch-Trailer: {"type":"trybot","CL":1185361,"patchset":4,"ref":"refs/changes/61/1185361/4","targetBranch":"master"}
  • Loading branch information
rogpeppe authored and cueckoo committed Mar 25, 2024
1 parent d564b9b commit 300a63c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
3 changes: 2 additions & 1 deletion cue/load/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ type Config struct {
DataFiles bool

// StdRoot specifies an alternative directory for standard libraries.
// This is mostly used for bootstrapping.
// Deprecated: this has no effect.
StdRoot string

// ParseFile is called to read and parse each file when preparing a
Expand Down Expand Up @@ -310,6 +310,7 @@ type fsPath string

func addImportQualifier(pkg importPath, name string) (importPath, errors.Error) {
if name != "" {
// TODO use module.ParseImportPath
s := string(pkg)
if i := strings.LastIndexByte(s, '/'); i >= 0 {
s = s[i+1:]
Expand Down
16 changes: 9 additions & 7 deletions cue/load/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,8 @@ func (l *loader) _loadFunc(pos token.Pos, path string) *build.Instance {
return l.cfg.newErrInstance(errors.Newf(pos, "relative import paths not allowed (%q)", path))
}

// is it a builtin?
if strings.IndexByte(strings.Split(path, "/")[0], '.') == -1 {
if l.cfg.StdRoot != "" {
p := l.newInstance(pos, impPath)
_ = l.importPkg(pos, p)
return p
}
if isStdlibPackage(path) {
// It looks like a builtin.
return nil
}

Expand Down Expand Up @@ -408,3 +403,10 @@ func absPathForSourceLoc(loc module.SourceLoc) (string, error) {
}
return filepath.Join(osPath, loc.Dir), nil
}

// isStdlibPackage reports whether pkgPath looks like
// an import from the standard library.
func isStdlibPackage(pkgPath string) bool {
firstElem, _, _ := strings.Cut(pkgPath, "/")
return strings.IndexByte(firstElem, '.') == -1
}

0 comments on commit 300a63c

Please sign in to comment.