Skip to content

Commit 43a1e12

Browse files
committed
cue/load: make imports work in "all package" mode
The `build.Instance` was being created directly by `cue/load`, but that ends up with an instance that contains a nil `loadFunc`, so imports are then ignored. Use the regular build context to create the new instance instead. Signed-off-by: Roger Peppe <[email protected]> Change-Id: I9f456fc7f09497ef16ce5d09a2f84c1f48d3374e Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201522 Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Daniel Martí <[email protected]>
1 parent deae2a0 commit 43a1e12

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

cue/load/loader_common.go

+6-9
Original file line numberDiff line numberDiff line change
@@ -243,15 +243,12 @@ func (fp *fileProcessor) add(root string, file *build.File, mode importMode) {
243243
return
244244
}
245245
if q == nil {
246-
q = &build.Instance{
247-
PkgName: pkg,
248-
249-
Dir: p.Dir,
250-
DisplayPath: p.DisplayPath,
251-
ImportPath: p.ImportPath + ":" + pkg,
252-
Root: p.Root,
253-
Module: p.Module,
254-
}
246+
q = fp.c.Context.NewInstance(p.Dir, nil)
247+
q.PkgName = pkg
248+
q.DisplayPath = p.DisplayPath
249+
q.ImportPath = p.ImportPath + ":" + pkg
250+
q.Root = p.Root
251+
q.Module = p.Module
255252
fp.pkgs[pkg] = q
256253
}
257254
p = q

cue/load/loader_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,9 @@ root: $CWD/testdata/testmod
635635
dir: $CWD/testdata/testmod
636636
display:.
637637
files:
638-
$CWD/testdata/testmod/test.cue`,
638+
$CWD/testdata/testmod/test.cue
639+
imports:
640+
mod.test/test/sub: $CWD/testdata/testmod/sub/sub.cue`,
639641
}}
640642
tdtest.Run(t, testCases, func(t *tdtest.T, tc *loadTest) {
641643
pkgs := Instances(tc.args, tc.cfg)

0 commit comments

Comments
 (0)