diff --git a/cue/load/config.go b/cue/load/config.go index 073ae5c4a..d79e9fa3e 100644 --- a/cue/load/config.go +++ b/cue/load/config.go @@ -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 @@ -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:] diff --git a/cue/load/import.go b/cue/load/import.go index e074c2b6e..8524e2249 100644 --- a/cue/load/import.go +++ b/cue/load/import.go @@ -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 } @@ -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 +}