Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
cue/load: factor out addFiles.
Browse files Browse the repository at this point in the history
Change-Id: I38f451b3b675fefca1f785dff5321b22047413d1
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/4561
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
  • Loading branch information
mpvl committed Jan 8, 2020
1 parent d4faf4b commit 4fd96d9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
11 changes: 1 addition & 10 deletions cue/load/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,7 @@ func (l *loader) importPkg(pos token.Pos, p *build.Instance) *build.Instance {
return p
}

for _, f := range p.CUEFiles {
if !ctxt.isAbsPath(f) {
f = ctxt.joinPath(cfg.ModuleRoot, f)
}
r, err := ctxt.openFile(f)
if err != nil {
p.ReportError(err)
}
_ = p.AddFile(f, r)
}
l.addFiles(cfg.ModuleRoot, p)
p.Complete()
return p
}
Expand Down
29 changes: 18 additions & 11 deletions cue/load/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,7 @@ func (l *loader) cueFilesPackage(files []string) *build.Instance {
// bp.ImportPath = ModDirImportPath(dir)
// }

for _, f := range pkg.CUEFiles {
fs := &l.cfg.fileSystem
if !fs.isAbsPath(f) {
f = fs.joinPath(cfg.Dir, f)
}
r, err := fs.openFile(f)
if err != nil {
pkg.ReportError(err)
}
_ = pkg.AddFile(f, r)
}
l.addFiles(cfg.Dir, pkg)

pkg.Local = true
l.stk.Push("user")
Expand All @@ -176,6 +166,23 @@ func (l *loader) cueFilesPackage(files []string) *build.Instance {
return pkg
}

func (l *loader) addFiles(dir string, p *build.Instance) {
files := p.CUEFiles
fs := &l.cfg.fileSystem

for _, f := range files {
if !fs.isAbsPath(f) {
f = fs.joinPath(dir, f)
}
r, err := fs.openFile(f)
if err != nil {
p.ReportError(err)
}

_ = p.AddFile(f, r)
}
}

func cleanImport(path string) string {
orig := path
path = pathpkg.Clean(path)
Expand Down
5 changes: 1 addition & 4 deletions cue/load/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,6 @@ dir: $CWD/testdata/toolonly
display:./toolonly`,
}}
for i, tc := range testCases {
// if i != 5 {
// continue
// }
t.Run(strconv.Itoa(i)+"/"+strings.Join(tc.args, ":"), func(t *testing.T) {
pkgs := Instances(tc.args, tc.cfg)

Expand All @@ -261,7 +258,7 @@ display:./toolonly`,
want := strings.TrimSpace(tc.want)
want = strings.Replace(want, "\t", " ", -1)
if got != want {
t.Errorf("\n%s", diff.Diff(got, want))
t.Errorf("\n%s", diff.Diff(want, got))
t.Logf("\n%s", got)
}
})
Expand Down

0 comments on commit 4fd96d9

Please sign in to comment.