From a1002829b4dbe58e349d19d91e481bff76b6891f Mon Sep 17 00:00:00 2001 From: Roger Peppe Date: Wed, 20 Mar 2024 16:21:53 +0000 Subject: [PATCH] cue/load: deprecate Config.StdRoot This field has not had the intended effect ever since commit 96ef9aad2385bdf9282e35e0f304dcae9bda266e, 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 Change-Id: Idf055a8139393908acdaf35820a005d8241ec4a0 Dispatch-Trailer: {"type":"trybot","CL":1185361,"patchset":3,"ref":"refs/changes/61/1185361/3","targetBranch":"master"} --- cue/load/config.go | 3 ++- cue/load/import.go | 15 ++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) 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..831dc66a8 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,9 @@ 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 { + return strings.IndexByte(strings.Split(pkgPath, "/")[0], '.') == -1 +}