Skip to content

Commit ac35a40

Browse files
committed
cue/load: do not scan imports of non-CUE files
The recent fix to do better with imports in command-line-specified files (https://cuelang.org/cl/1194765) changed cue/load to scan imports before loading files. It scans imports in all files including non-CUE files. This turns out to be a problem because the code to get the CUE syntax in turn invokes the internal/encoding.Decoder logic which requires a fully populated encoding.Config struct in order to do its job properly. Specifically, the encoding.Config created by cue/load does not have the protobuf import path required when decoding protobuf files, so this was failing. Work around this by scanning imports of CUE files only, mirroring the same logic in cue/load.matchFile. In the future, we will probably have to rework this, as it's entirely possible that non-CUE specified on the command line might end up producing a CUE representation that imports external CUE packages, but for now this should be sufficient. Signed-off-by: Roger Peppe <[email protected]> Change-Id: I703b7c1f95be253070792d7744589474ce88ad7a Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1194827 Reviewed-by: Daniel Martí <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent f513a17 commit ac35a40

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

cmd/cue/cmd/testdata/script/def_proto.txtar

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
env CUE_EXPERIMENT=modules=0
2+
exec cue def policy.proto -p api -I include
3+
cmp stdout expect-stdout
4+
5+
env CUE_EXPERIMENT=modules
6+
env CUE_CACHE_DIR=$WORK/tmp/cache
17
exec cue def policy.proto -p api -I include
28
cmp stdout expect-stdout
39

cue/load/instances.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ func loadPackages(ctx context.Context, cfg *Config, synCache *syntaxCache, extra
188188
}
189189
// Add any imports found in other files.
190190
for _, f := range otherFiles {
191+
if f.Encoding != build.CUE {
192+
// not a CUE file; assume it has no imports for now.
193+
continue
194+
}
191195
syntaxes, err := synCache.getSyntax(f)
192196
if err != nil {
193197
return nil, fmt.Errorf("cannot get syntax for %q: %v", f.Filename, err)

0 commit comments

Comments
 (0)