Skip to content

Commit

Permalink
cue/load: remove some unused code
Browse files Browse the repository at this point in the history
As found by staticcheck; these seem to have never been used.

Change-Id: I698aa9db61a17ed5addcae20e7e8dfd69c436157
Signed-off-by: Daniel Martí <[email protected]>
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/536098
Reviewed-by: Roger Peppe <[email protected]>
Unity-Result: CUEcueckoo <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
  • Loading branch information
mvdan committed Apr 12, 2022
1 parent e74624b commit 6b138e4
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 89 deletions.
11 changes: 0 additions & 11 deletions cue/load/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"os"
pathpkg "path"
"path/filepath"
goruntime "runtime"
"strings"

"cuelang.org/go/cue/ast"
Expand Down Expand Up @@ -629,13 +628,3 @@ func (c Config) findRoot(dir string) string {
abs = d
}
}

func home() string {
env := "HOME"
if goruntime.GOOS == "windows" {
env = "USERPROFILE"
} else if goruntime.GOOS == "plan9" {
env = "home"
}
return os.Getenv(env)
}
17 changes: 0 additions & 17 deletions cue/load/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,6 @@ import (
"cuelang.org/go/cue/token"
)

func lastError(p *build.Instance) *PackageError {
if p == nil {
return nil
}
switch v := p.Err.(type) {
case *PackageError:
return v
}
return nil
}

func report(p *build.Instance, err *PackageError) {
if err != nil {
p.ReportError(err)
}
}

// A PackageError describes an error loading information about a package.
type PackageError struct {
ImportStack []string // shortest path from package named on command line to this one
Expand Down
61 changes: 0 additions & 61 deletions cue/load/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
pathpkg "path"
"path/filepath"
"strings"
"unicode"

"cuelang.org/go/cue/ast"
"cuelang.org/go/cue/build"
Expand Down Expand Up @@ -257,63 +256,3 @@ func (s *importStack) Pop() {
func (s *importStack) Copy() []string {
return append([]string{}, *s...)
}

// shorterThan reports whether sp is shorter than t.
// We use this to record the shortest import sequences
// that leads to a particular package.
func (sp *importStack) shorterThan(t []string) bool {
s := *sp
if len(s) != len(t) {
return len(s) < len(t)
}
// If they are the same length, settle ties using string ordering.
for i := range s {
if s[i] != t[i] {
return s[i] < t[i]
}
}
return false // they are equal
}

// reusePackage reuses package p to satisfy the import at the top
// of the import stack stk. If this use causes an import loop,
// reusePackage updates p's error information to record the loop.
func (l *loader) reusePackage(p *build.Instance) *build.Instance {
// We use p.Internal.Imports==nil to detect a package that
// is in the midst of its own loadPackage call
// (all the recursion below happens before p.Internal.Imports gets set).
if p.ImportPaths == nil {
if err := lastError(p); err == nil {
err = l.errPkgf(nil, "import cycle not allowed")
err.IsImportCycle = true
report(p, err)
}
p.Incomplete = true
}
// Don't rewrite the import stack in the error if we have an import cycle.
// If we do, we'll lose the path that describes the cycle.
if err := lastError(p); err != nil && !err.IsImportCycle && l.stk.shorterThan(err.ImportStack) {
err.ImportStack = l.stk.Copy()
}
return p
}

// dirToImportPath returns the pseudo-import path we use for a package
// outside the CUE path. It begins with _/ and then contains the full path
// to the directory. If the package lives in c:\home\gopher\my\pkg then
// the pseudo-import path is _/c_/home/gopher/my/pkg.
// Using a pseudo-import path like this makes the ./ imports no longer
// a special case, so that all the code to deal with ordinary imports works
// automatically.
func dirToImportPath(dir string) string {
return pathpkg.Join("_", strings.Map(makeImportValid, filepath.ToSlash(dir)))
}

func makeImportValid(r rune) rune {
// Should match Go spec, compilers, and ../../go/parser/parser.go:/isValidImport.
const illegalChars = `!"#$%&'()*,:;<=>?[\]^{|}` + "`\uFFFD"
if !unicode.IsGraphic(r) || unicode.IsSpace(r) || strings.ContainsRune(illegalChars, r) {
return '_'
}
return r
}

0 comments on commit 6b138e4

Please sign in to comment.