Skip to content

Commit 4cb33de

Browse files
committed
cue/load: deduplicate handling missing files for ad-hoc packages
When loading a list of CUE files as a "files package", we would first stat the files to fail early if they were not present and regular files. However, this is unnecessary; we parse the files immediately afterwards, a process which already fails with the standard OS errors when one tries to open and read a missing file or a directory. This saves 2226 syscalls when running `go test ./...`, as there are many Go tests which use ad-hoc packages. For example, all the tests using cuetxtar with txtar archives. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I42497c70b46a77ffe2907d99c4ed8e9398e6c8be Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1218101 Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Roger Peppe <[email protected]>
1 parent c80fdaf commit 4cb33de

File tree

2 files changed

+2
-19
lines changed

2 files changed

+2
-19
lines changed

cmd/cue/cmd/testdata/script/get_crd_errors.txtar

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
! exec cue get crd
55
stderr 'must specify at least one file'
66

7-
# Test non-existent file
7+
# Test non-existent file; different errors on unix vs windows
88
! exec cue get crd nonexistent.yaml
9-
stderr 'could not find file'
9+
stderr 'no such file or directory|cannot find the file specified'
1010

1111
# Test invalid YAML
1212
! exec cue get crd invalid.yaml

cue/load/loader.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,23 +81,6 @@ func (l *loader) cueFilesPackage(files []*build.File) *build.Instance {
8181
// ModInit() // TODO: support modules
8282
pkg := l.cfg.Context.NewInstance(l.cfg.Dir, nil)
8383

84-
for _, bf := range files {
85-
f := bf.Filename
86-
if f == "-" {
87-
continue
88-
}
89-
if !filepath.IsAbs(f) {
90-
f = filepath.Join(l.cfg.Dir, f)
91-
}
92-
fi, err := l.cfg.fileSystem.stat(f)
93-
if err != nil {
94-
return l.cfg.newErrInstance(errors.Wrapf(err, token.NoPos, "could not find file %v", f))
95-
}
96-
if fi.IsDir() {
97-
return l.cfg.newErrInstance(errors.Newf(token.NoPos, "file is a directory %v", f))
98-
}
99-
}
100-
10184
fp := newFileProcessor(l.cfg, pkg, l.tagger)
10285
if l.cfg.Package == "*" {
10386
fp.allPackages = true

0 commit comments

Comments
 (0)