cue-lang / cue

The home of the CUE language! Validate and define text-based and dynamic configuration
https://cuelang.org
Apache License 2.0
5.14k stars 294 forks source link

cmd/cue: get go generates packages conflicting with the standard library #648

Open cueckoo opened 3 years ago

cueckoo commented 3 years ago

Originally opened by @myitcv in https://github.com/cuelang/cue/issues/648

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

$ cue version
cue version +f0c025c1 linux/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

cat <<'EOD' | testscript -v
exec go mod init blah
exec cue mod init blah.com
exec go get mvdan.cc/sh/v3@v3.2.1
exec cue get go mvdan.cc/sh/v3/...
exec cue def mvdan.cc/sh/v3/syntax
EOD

What did you expect to see?

Success.

What did you see instead?

> exec go mod init blah
[stderr]
go: creating new go.mod: module blah
> exec cue mod init blah.com
> exec go get mvdan.cc/sh/v3
[stderr]
go: mvdan.cc/sh/v3 upgrade => v3.2.1
> exec cue get go mvdan.cc/sh/v3/...
> exec cue def mvdan.cc/sh/v3/syntax
[stderr]
package "io" not found:
    ./cue.mod/gen/mvdan.cc/sh/v3/syntax/parser_go_gen.cue:7:8
[exit status 1]

Per offline discussion with @mpvl, Go standard library packages need to mapped to a domain-qualified module path. Perhaps something like golang.org/pkg/io etc.

cueckoo commented 3 years ago

Original reply by @myitcv in https://github.com/cuelang/cue/issues/648#issuecomment-782089553

Another good test case here is https://github.com/goreleaser/goreleaser/discussions/2065

sjwl commented 1 year ago

still a problem with v0.5.0-beta.2

cue get go github.com/helmfile/helmfile/pkg/helmexec
cue def github.com/helmfile/helmfile/pkg/helmexec 
builtin package "io" undefined:
    ./cue.mod/gen/github.com/helmfile/helmfile/pkg/helmexec/context_go_gen.cue:7:8

My Workaround:

  1. move cue.mod/gen/io/ to cue.mod/pkg/golang.org/pkg/io/
  2. move cue.mod/gen/github.com/helmfile/helmfile/pkg/helmexec/ to cue.mod/pkg/github.com/helmfile/helmfile/pkg/helmexec/
  3. modify cue.mod/pkg/github.com/helmfile/helmfile/pkg/helmexec/context_go_gen.cue

    from

    import "io"

    to

    import "golang.org/pkg/io"
mvdan commented 1 year ago

Multiple duplicates of this issue have been filed, so in the hopes of making this issue more discoverable, I've given it a slightly more specific title.

myitcv commented 1 year ago

Dropping the now-defunct v0.4.x milestone from this issue, but leaving the zGarden label such that we come round to considering what milestone this should sit in.

yujunz commented 1 year ago

Per offline discussion with @mpvl, Go standard library packages need to mapped to a domain-qualified module path. Perhaps something like golang.org/pkg/io etc.

Or pkg.go.dev/io?

bradbeck commented 10 months ago

Are we getting any closer to resolving this issue?

I've run into a similar issue relative to sigstore.

$ cue eval    
builtin package "reflect" undefined:
    ./cue.mod/gen/github.com/sigstore/k8s-manifest-sigstore/pkg/util/mapnode/node_go_gen.cue:7:8

See: https://github.com/bradbeck/k8s-cue

iNoahNothing commented 6 months ago

I've just ran into the same issue importing the cilium api with cue get go github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2

builtin package "reflect" undefined:
    ./cue.mod/gen/github.com/go-openapi/strfmt/format_go_gen.cue:7:8
mehemken commented 6 months ago

I've run into this tying to get the Kyverno schema. Fails with same sigstore error as @bradbeck but adding it here for searchability.

go get github.com/kyverno/kyverno/api/kyverno/v1
cue get go github.com/kyverno/kyverno/api/kyverno/v1
builtin package "reflect" undefined:
    ./cue.mod/gen/github.com/sigstore/k8s-manifest-sigstore/pkg/util/mapnode/node_go_gen.cue:7:8

# but also:
builtin package "internal/abi" undefined:
    ./cue.mod/gen/pkg.go.dev/pkg/reflect/type_go_gen.cue:18:8

I was able to use @sjwl 's workaround. But I feel like that's going to blow up in my face one day :)