-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal/mod/modpkgload: support gen directories
This change adds support for gen directories in the main module. If there's a package in a gen (or pkg or usr) directory, then it will be used unless there's another such package already present in the module graph, in which case we'll get an "ambiguous import" error. In order to fit this into the existing algorithm, we invent a new special module, "local" which notionally holds all packages that are inside `cue.mod`. Signed-off-by: Roger Peppe <[email protected]> Change-Id: I1b74bf76653301098f525298005b8ac19d831156 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1176005 TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Daniel Martí <[email protected]>
- Loading branch information
Showing
13 changed files
with
319 additions
and
42 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,38 +1,78 @@ | ||
# When CUE_REGISTRY is correctly set, packages in the | ||
# pkg directory are ignored. | ||
# pkg, usr and gen directories will be used when they don't conflict with | ||
# other module dependencies. | ||
|
||
exec cue export . | ||
cmp stdout expect-stdout | ||
|
||
-- expect-stdout -- | ||
"registry source" | ||
{ | ||
"e": { | ||
"a": { | ||
"remote": true | ||
} | ||
}, | ||
"local_pkg": { | ||
"a": { | ||
"pkg": true | ||
} | ||
}, | ||
"local_pkg_usr": { | ||
"a": { | ||
"pkg": true, | ||
"usr": true | ||
} | ||
}, | ||
"local_gen_usr": { | ||
"a": { | ||
"gen": true, | ||
"usr": true | ||
} | ||
} | ||
} | ||
-- main.cue -- | ||
package main | ||
import "example.com/e" | ||
import ( | ||
"example.com/e" | ||
local_pkg "example.com/e/local_pkg:x" | ||
local_pkg_usr "example.com/e/local_pkg_usr:x" | ||
local_gen_usr "example.com/e/local_gen_usr:x" | ||
) | ||
|
||
e.foo | ||
"e": e | ||
"local_pkg": local_pkg | ||
"local_pkg_usr": local_pkg_usr | ||
"local_gen_usr": local_gen_usr | ||
|
||
-- cue.mod/module.cue -- | ||
module: "test.org" | ||
deps: "example.com/e": v: "v0.0.1" | ||
|
||
-- cue.mod/pkg/example.com/e/cue.mod/module.cue -- | ||
module: "example.com/e" | ||
-- cue.mod/pkg/example.com/e/local_pkg/x.cue -- | ||
package x | ||
a: pkg: true | ||
|
||
-- cue.mod/pkg/example.com/e/main.cue -- | ||
package e | ||
foo: "cue.mod/pkg source" | ||
-- cue.mod/pkg/example.com/e/local_pkg_usr/x.cue -- | ||
package x | ||
a: pkg: true | ||
|
||
-- cue.mod/pkg/example.com/e/cue.mod/module.cue -- | ||
module: "example.com/e" | ||
-- cue.mod/usr/example.com/e/local_pkg_usr/x.cue -- | ||
package x | ||
a: usr: true | ||
|
||
-- cue.mod/pkg/example.com/e/main.cue -- | ||
package e | ||
foo: "cue.mod/pkg source" | ||
-- cue.mod/usr/example.com/e/local_gen_usr/x.cue -- | ||
package x | ||
a: usr: true | ||
|
||
-- cue.mod/gen/example.com/e/local_gen_usr/x.cue -- | ||
package x | ||
a: gen: true | ||
|
||
-- _registry/example.com_e_v0.0.1/cue.mod/module.cue -- | ||
module: "example.com/e@v0" | ||
|
||
-- _registry/example.com_e_v0.0.1/main.cue -- | ||
package e | ||
|
||
foo: "registry source" | ||
a: remote: true | ||
|
36 changes: 36 additions & 0 deletions
36
cmd/cue/cmd/testdata/script/registry_with_pkg_conflict.txtar
This file contains 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,36 @@ | ||
# When CUE_REGISTRY is correctly set, packages in the | ||
# pkg directory will result in an error when they conflict with actual | ||
# dependencies. | ||
|
||
! exec cue export . | ||
cmp stderr expect-stderr | ||
|
||
-- expect-stderr -- | ||
import failed: cannot find package "example.com/e": ambiguous import: found package example.com/e in multiple modules: | ||
example.com/e@v0 v0.0.1 (.) | ||
local (cue.mod/pkg/example.com/e): | ||
./main.cue:2:8 | ||
-- main.cue -- | ||
package main | ||
import "example.com/e" | ||
|
||
e.foo | ||
|
||
-- cue.mod/module.cue -- | ||
module: "test.org" | ||
deps: "example.com/e": v: "v0.0.1" | ||
|
||
-- cue.mod/pkg/example.com/e/cue.mod/module.cue -- | ||
module: "example.com/e" | ||
|
||
-- cue.mod/pkg/example.com/e/main.cue -- | ||
package e | ||
foo: "cue.mod/pkg source" | ||
|
||
-- _registry/example.com_e_v0.0.1/cue.mod/module.cue -- | ||
module: "example.com/e@v0" | ||
|
||
-- _registry/example.com_e_v0.0.1/main.cue -- | ||
package e | ||
|
||
foo: "registry source" |
43 changes: 43 additions & 0 deletions
43
cmd/cue/cmd/testdata/script/registry_with_remote_gen.txtar
This file contains 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,43 @@ | ||
# This tests what happens when there's a remote module that includes | ||
# a gen directory. It's not usable unless a local gen directory is | ||
# created too. | ||
|
||
! exec cue export . | ||
stderr 'import failed: import failed: cannot find package "other.com/p": cannot find module providing package other.com/p:' | ||
mkdir cue.mod/gen/other.com/p | ||
cp _registry/example.com_e_v0.0.1/gen/other.com/p/p.cue cue.mod/gen/other.com/p | ||
exec cue export . | ||
cmp stdout expect-stdout | ||
-- expect-stdout -- | ||
{ | ||
"e": { | ||
"a": { | ||
"a": { | ||
"p": true | ||
} | ||
} | ||
} | ||
} | ||
-- main.cue -- | ||
package main | ||
import "example.com/e" | ||
|
||
"e": e | ||
|
||
-- cue.mod/module.cue -- | ||
module: "test.org" | ||
deps: "example.com/e": v: "v0.0.1" | ||
|
||
-- _registry/example.com_e_v0.0.1/cue.mod/module.cue -- | ||
module: "example.com/e@v0" | ||
|
||
-- _registry/example.com_e_v0.0.1/main.cue -- | ||
package e | ||
import "other.com/p" | ||
|
||
a: p | ||
|
||
-- _registry/example.com_e_v0.0.1/gen/other.com/p/p.cue -- | ||
package p | ||
a: p: true | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.