-
Notifications
You must be signed in to change notification settings - Fork 330
internal/encoding/gotypes: support go import aliasing #4028
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
phoban01
wants to merge
10
commits into
cue-lang:master
Choose a base branch
from
phoban01:support-generating-go-import-alias
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
99e3745
internal/encoding/gotypes: support go import aliasing
phoban01 d712913
fix: rewrite test to avoid cue.mod/gen
phoban01 1d08d49
fix: avoid two-layer format
phoban01 5e57442
fix: undo whitespace addition
phoban01 6132cd4
fix: reword doc string
phoban01 9b70324
fix: rename aliasLookup -> importAliases
phoban01 b887614
fix: simplify gatherImportAliases; removing _ alias check
phoban01 d5bae8b
fix: do not pass importAliases when generating goPkgName
phoban01 a50de83
fix: ensure conflicting aliases are handled
phoban01 9ac432f
fix: handle duplicate alias/package names
phoban01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# reproduction for https://github.com/cue-lang/cue/issues/3974 | ||
exec cue exp gengotypes | ||
cmp cue_types_main_gen.go expect-gengo | ||
|
||
-- cue.mod/module.cue -- | ||
module: "mod.test" | ||
language: version: "v0.13.0" | ||
|
||
-- pkg/k8s.io/apimachinery/pkg/apis/meta/v1/types_go_gen.cue -- | ||
package v1 | ||
|
||
#ObjectMeta: {} | ||
|
||
-- pkg/k8s.io/api/core/v1/types_go_gen.cue -- | ||
package v1 | ||
|
||
#PodSpec: {} | ||
|
||
-- main.cue -- | ||
package main | ||
|
||
import ( | ||
metav1 "mod.test/pkg/k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"mod.test/pkg/k8s.io/api/core/v1" | ||
) | ||
|
||
#Spec: { | ||
meta: metav1.#ObjectMeta | ||
spec: v1.#PodSpec | ||
} | ||
|
||
-- expect-gengo -- | ||
// Code generated by "cue exp gengotypes"; DO NOT EDIT. | ||
|
||
package main | ||
|
||
import ( | ||
"mod.test/pkg/k8s.io/api/core/v1" | ||
metav1 "mod.test/pkg/k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
type Spec struct { | ||
Meta metav1.ObjectMeta `json:"meta"` | ||
|
||
Spec v1.PodSpec `json:"spec"` | ||
} |
57 changes: 57 additions & 0 deletions
57
cmd/cue/cmd/testdata/script/cmd_exp_gengo_alias_conflict.txtar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# reproduction for https://github.com/cue-lang/cue/issues/3974 | ||
exec cue exp gengotypes | ||
cmp cue_types_main_gen.go expect-gengo | ||
|
||
-- cue.mod/module.cue -- | ||
module: "mod.test" | ||
language: version: "v0.13.0" | ||
|
||
-- pkg/foo/p1/p1.cue -- | ||
package p1 | ||
|
||
#Foo: int | ||
|
||
-- pkg/bar/p2/p2.cue -- | ||
package p2 | ||
|
||
#Bar: string | ||
|
||
-- f1.cue -- | ||
package main | ||
|
||
import ( | ||
same "mod.test/pkg/foo/p1" | ||
) | ||
|
||
#A: { | ||
foo: same.#Foo | ||
} | ||
|
||
-- f2.cue -- | ||
package main | ||
|
||
import ( | ||
same "mod.test/pkg/bar/p2" | ||
) | ||
|
||
#B: { | ||
bar: same.#Bar | ||
} | ||
|
||
-- expect-gengo -- | ||
// Code generated by "cue exp gengotypes"; DO NOT EDIT. | ||
|
||
package main | ||
|
||
import ( | ||
same1 "mod.test/pkg/bar/p2" | ||
same "mod.test/pkg/foo/p1" | ||
) | ||
|
||
type A struct { | ||
Foo same.Foo `json:"foo"` | ||
} | ||
|
||
type B struct { | ||
Bar same1.Bar `json:"bar"` | ||
} |
57 changes: 57 additions & 0 deletions
57
cmd/cue/cmd/testdata/script/cmd_exp_gengo_alias_duplicate.txtar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# reproduction for https://github.com/cue-lang/cue/issues/3974 | ||
exec cue exp gengotypes | ||
cmp cue_types_main_gen.go expect-gengo | ||
|
||
-- cue.mod/module.cue -- | ||
module: "mod.test" | ||
language: version: "v0.13.0" | ||
|
||
-- pkg/same/same.cue -- | ||
package same | ||
|
||
#Same: int | ||
|
||
-- pkg/foo/foo.cue -- | ||
package foo | ||
|
||
#Bar: string | ||
|
||
-- f1.cue -- | ||
package main | ||
|
||
import ( | ||
"mod.test/pkg/same" | ||
) | ||
|
||
#A: { | ||
value: same.#Same | ||
} | ||
|
||
-- f2.cue -- | ||
package main | ||
|
||
import ( | ||
same "mod.test/pkg/foo" | ||
) | ||
|
||
#B: { | ||
bar: same.#Bar | ||
} | ||
|
||
-- expect-gengo -- | ||
// Code generated by "cue exp gengotypes"; DO NOT EDIT. | ||
|
||
package main | ||
|
||
import ( | ||
same1 "mod.test/pkg/foo" | ||
"mod.test/pkg/same" | ||
) | ||
|
||
type A struct { | ||
Value same.Same `json:"value"` | ||
} | ||
|
||
type B struct { | ||
Bar same1.Bar `json:"bar"` | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that we organize fields on a per-package and per-definition basis. This should be on a per-package basis I assume.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I follow here: should I clarify the description or am I missing something in respect of the package handling implementation?