Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

path resolution issue for generated files #452

Closed
errordeveloper opened this issue Jul 27, 2020 · 3 comments
Closed

path resolution issue for generated files #452

errordeveloper opened this issue Jul 27, 2020 · 3 comments

Comments

@errordeveloper
Copy link

I have a Go+CUE project, the Go import root is github.com/isovalent/foo/operator (i.e. repo is github.com/isovalent/foo, and code is in operator subdirectory, I shall refer to any files using paths relative to the operator subdirectory).

I have created subdirectory cue.mod and cue.mod/module.cue contains the following line:

module: "github.com/isovalent/foo/operator"

I have created Go types defined in subdirectory api/v1alpha1, and I generated CUE schema for these types using the following command:

cue get go github.com/isovalent/foo/operator/api/v1alpha1

I created a CUE file pkg/template/testassets/template.cue, which contains:

package template

import "github.com/isovalent/foo/operator/api/v1alpha1"

And this is what I am seeing:

$ cue eval ./pkg/template/testassets/template.cue
import failed: cannot find package "github.com/isovalent/foo/operator/api/v1alpha1":
    ./pkg/template/testassets/template.cue:6:8
$

I was not able to tell what is really going on, according to the docs it should find the following directory:

cue.mod/gen/github.com/isovalent/gke-test-cluster-management/operator/api/v1alpha1

Having made a few guesses, I realised that it's looking in the same directory where Go types are, and there no CUE files in that directory.

I was able to confirm this by placing a dummy file api/v1alpha1/touch.cue:

package v1alpha1

foo: {}

And running:

$ cue eval github.com/isovalent/gke-test-cluster-management/operator/api/v1alpha1
foo: {}
$

Next, I tried to modify cue.mod/module.cue and append a string to the path:

module: "github.com/isovalent/foo/operator/cue"

No I got it working as expected, but it's still quite odd and very confusing. If Go source directories are used during import resolution, why is go.mod needed? I suppose this is just a bug.

@mpvl
Copy link
Contributor

mpvl commented Nov 21, 2020

One thing to test is whether it is the name pkg. This used to have special meaning when we didn't have the cue.mod system yet. And it still does, but should be ignored when it finds a cue.mod directory.

It is a bit hard to piece out what your setup from the text though. Easier would be to have a txtar reproducer (can use txtar-c to create it) and/or have a tree output of your directory structure.

@seh
Copy link

seh commented Apr 29, 2021

This pkg directory came up in this Slack discussion in the "language" channel. Is this special treatment of the top-level pkg directory deprecated?

Here's an example that only works when the import target's files are situated beneath a top-level pkg directory:

-- outside/outside.cue --
package outside

import "example.com/component"

top: component.name
-- pkg/example.com/component/component.cue --
package component

name: "component"

I couldn't find any documentation that mentions this treatment, nor could I find where in the CUE source code it handles this case.

@cueckoo
Copy link

cueckoo commented Jul 3, 2021

This issue has been migrated to cue-lang/cue#452.

For more details about CUE's migration to a new home, please see cue-lang/cue#1078.

@cueckoo cueckoo closed this as completed Jul 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants