Skip to content

Commit

Permalink
cue/load: make imports work in "all package" mode
Browse files Browse the repository at this point in the history
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. Do a shallow copy of the whole
value instead, which will copy the `loadFunc` field too.

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
Change-Id: I9f456fc7f09497ef16ce5d09a2f84c1f48d3374e
Dispatch-Trailer: {"type":"trybot","CL":1201522,"patchset":1,"ref":"refs/changes/22/1201522/1","targetBranch":"master"}
  • Loading branch information
rogpeppe authored and cueckoo committed Sep 19, 2024
1 parent 636125b commit 2ebac35
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
16 changes: 7 additions & 9 deletions cue/load/loader_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,13 @@ func (fp *fileProcessor) add(root string, file *build.File, mode importMode) {
return
}
if q == nil {
q = &build.Instance{
PkgName: pkg,

Dir: p.Dir,
DisplayPath: p.DisplayPath,
ImportPath: p.ImportPath + ":" + pkg,
Root: p.Root,
Module: p.Module,
}
// Copy the original instance including private fields,
// because the private fields include the loadFunc, without which
// the import logic will not work.
q0 := *p
q = &q0
q.PkgName = pkg
q.ImportPath += ":" + pkg
fp.pkgs[pkg] = q
}
p = q
Expand Down
6 changes: 4 additions & 2 deletions cue/load/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,10 @@ root: $CWD/testdata/testmod
dir: $CWD/testdata/testmod
display:.
files:
$CWD/testdata/testmod/test.cue`,
}}
$CWD/testdata/testmod/anon.cue
$CWD/testdata/testmod/test.cue
imports:
mod.test/test/sub: $CWD/testdata/testmod/sub/sub.cue`}}
tdtest.Run(t, testCases, func(t *tdtest.T, tc *loadTest) {
pkgs := Instances(tc.args, tc.cfg)

Expand Down

0 comments on commit 2ebac35

Please sign in to comment.