cue icon indicating copy to clipboard operation
cue copied to clipboard

CUE modules that have a gen directory can't be used

Open vikstrous2 opened this issue 1 year ago • 4 comments

What version of CUE are you using (cue version)?

cue version v0.9.0-rc.1

go version go1.22.1
      -buildmode exe
       -compiler gc
  DefaultGODEBUG httplaxcontentlength=1,httpmuxgo121=1,tls10server=1,tlsrsakex=1,tlsunsafeekm=1
     CGO_ENABLED 1
          GOARCH amd64
            GOOS linux
         GOAMD64 v1
cue.lang.version v0.9.0

Does this issue reproduce with the latest stable release?

yes

What did you do?

In a new directory, create a module and add a dependency:

cue mod init github.com/vikstrous/cuek8stest
cue mod get github.com/vikstrous/cuek8s

Create a file: test.cue

package cuek8stest

import "github.com/vikstrous/cuek8s"

hello: cuek8s.#Hello

service: cuek8s.#Service

Then run cue eval

What did you expect to see?

it shouldn't error

What did you see instead?

github.com/vikstrous/[email protected]/vikstrous/cuek8s: import failed: import failed: cannot find package "k8s.io/api/core/v1": cannot find module providing package k8s.io/api/core/v1:
    ./test.cue:3:8
    ../.cache/cue/mod/extract/github.com/vikstrous/[email protected]/hello.cue:3:8

vikstrous2 avatar Jun 14 '24 14:06 vikstrous2

I'm seeing something similar as well

nyarly avatar Jun 18 '24 00:06 nyarly

Same here.

ckazimie avatar Jun 23 '24 13:06 ckazimie

I'm planning to start trying to work around this by rewriting package paths and moving the gen packages out of the gen directory. To reproduce this issue, use version v0.0.8 of https://github.com/vikstrous/cuek8s

vikstrous2 avatar Jun 24 '24 13:06 vikstrous2

This is the workaround: https://github.com/vikstrous/cuek8s/blob/master/generate.sh

vikstrous2 avatar Jun 24 '24 14:06 vikstrous2

I am also encountering this issue with a module published using 0.9.2 and source: kind: "self".

tvandinther avatar Jul 02 '24 09:07 tvandinther

Note that this behaviour is documented in the introduction to the CUE modules reference:

as a transitionary measure, the CUE tool still supports the import of packages present in the cue.mod/pkg, cue.mod/usr and cue.mod/gen directories. This only applies to the main module, and if there is any ambiguity with respect to regular module dependencies an “ambiguous import” error will be reported.

Note the "as a transitionary measure" caveat above. Eventually, it's possible/probable that support for the gen, usr and pkg directories will be dropped in favour of regular published packages.

rogpeppe avatar Jul 18 '24 13:07 rogpeppe

Closing this issue as everything seems to be functioning as intended.

rogpeppe avatar Jul 18 '24 13:07 rogpeppe