this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <rogpeppe@gmail.com>
Change-Id: I703b7c1f95be253070792d7744589474ce88ad7a
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1194827
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

+10
+6
cmd/cue/cmd/testdata/script/def_proto.txtar
··· 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 1 7 exec cue def policy.proto -p api -I include 2 8 cmp stdout expect-stdout 3 9
+4
cue/load/instances.go
··· 188 188 } 189 189 // Add any imports found in other files. 190 190 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 + } 191 195 syntaxes, err := synCache.getSyntax(f) 192 196 if err != nil { 193 197 return nil, fmt.Errorf("cannot get syntax for %q: %v", f.Filename, err)