Skip to content

Commit 3142030

Browse files
committed
internal/mod/zip: adapt to CUE semantics
Note: experimental feature. Summary of changes from Go version: - The canonical version of a module path always includes a major version (even at v0 and v1). - we don't encode the module version in a top level directory. Instead, the contents of the module are exactly those in the zip file. - finding the module.cue file becomes a little more awkward because it's inside a subdirectory. - we return the contents of the module.cue file so that it can be checked by logic external to this package, which avoids having the zip package depend on the entire CUE interpreter. - `CreateFromVCS` is not needed, at least for now. For #2330. Signed-off-by: Roger Peppe <[email protected]> Change-Id: I0e29102031f6e95a28b456beec3bdab144792083 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1168706 Reviewed-by: Paul Jolly <[email protected]> Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent 4eca0c7 commit 3142030

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+601
-1609
lines changed

internal/mod/zip/testdata/check_dir/empty.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
wantErr=no cue.mod/module.cue file found
12
-- want --
23
valid:
34

Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
-- want --
22
valid:
3-
$work/valid.go
3+
$work/valid.cue
4+
$work/vendor/x/y
45

56
omitted:
67
$work/.hg_archival.txt: file is inserted by 'hg archive' and is always omitted
8+
$work/sub/cue.mod/module.cue: file is in another module
79
$work/.git: directory is a version control repository
8-
$work/sub: directory is in another module
9-
$work/vendor/x/y: file is in vendor directory
1010

1111
invalid:
12-
$work/GO.MOD: go.mod files must have lowercase names
13-
$work/invalid.go': malformed file path "invalid.go'": invalid char '\''
14-
-- valid.go --
15-
-- GO.MOD --
16-
-- invalid.go' --
12+
$work/CUE.MOD: cue.mod directories must have lowercase names
13+
$work/invalid.cue': malformed file path "invalid.cue'": invalid char '\''
14+
-- valid.cue --
15+
-- CUE.MOD --
16+
-- invalid.cue' --
1717
-- vendor/x/y --
18-
-- sub/go.mod --
18+
-- sub/cue.mod/module.cue --
1919
-- .hg_archival.txt --
2020
-- .git/x --

internal/mod/zip/testdata/check_files/empty.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
wantErr=no cue.mod/module.cue file found
12
-- want --
23
valid:
34

internal/mod/zip/testdata/check_files/various.txt

+26-5
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,44 @@
11
-- want --
22
valid:
3+
valid.cue
4+
other/valid.cue
5+
cue.mod/module.cue
6+
cue.mod/pkg_other/x
7+
cue.mod/pkg/x
8+
cue.mod/usr/x
9+
cue.mod/gen/x
10+
GO.MOD
11+
vendor/x/y
312
valid.go
413

514
omitted:
6-
vendor/x/y: file is in vendor directory
7-
sub/go.mod: file is in another module
15+
sub1/cue.mod/module.cue: file is in another module
16+
sub1/something.cue: file is in another module
17+
sub2/CUE.MOD/module.cue: file is in another module
818
.hg_archival.txt: file is inserted by 'hg archive' and is always omitted
919

1020
invalid:
21+
cue.mod/Module.cue: cue.mod/module.cue files must have lowercase names
1122
not/../clean: file path is not clean
12-
GO.MOD: go.mod files must have lowercase names
23+
CUE.MOD/module.cue: cue.mod directories must have lowercase names
1324
invalid.go': malformed file path "invalid.go'": invalid char '\''
1425
valid.go: multiple entries for file "valid.go"
15-
-- valid.go --
26+
-- valid.cue --
27+
-- other/valid.cue --
28+
-- cue.mod/module.cue --
29+
-- cue.mod/Module.cue --
30+
-- cue.mod/pkg_other/x --
31+
-- cue.mod/pkg/x --
32+
-- cue.mod/usr/x --
33+
-- cue.mod/gen/x --
1634
-- not/../clean --
1735
-- GO.MOD --
36+
-- CUE.MOD/module.cue --
1837
-- invalid.go' --
1938
-- vendor/x/y --
20-
-- sub/go.mod --
39+
-- sub1/cue.mod/module.cue --
40+
-- sub1/something.cue --
41+
-- sub2/CUE.MOD/module.cue --
2142
-- .hg_archival.txt --
2243
-- valid.go --
2344
duplicate

internal/mod/zip/testdata/check_zip/empty.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
path=example.com/empty
1+
path=example.com/empty@v1
2+
wantErr=no cue.mod/module.cue file found
23
version=v1.0.0
34
-- want --
45
valid:
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
path=example.com/various
1+
path=example.com/various@v1
22
version=v1.0.0
33
-- want --
44
valid:
5-
example.com/[email protected]/valid.go
5+
valid.go
66

77
omitted:
88

99
invalid:
10-
noprefix: path does not have prefix "example.com/[email protected]/"
11-
example.com/[email protected]/not/../clean: file path is not clean
12-
example.com/[email protected]/invalid.go': malformed file path "invalid.go'": invalid char '\''
13-
example.com/[email protected]/GO.MOD: go.mod files must have lowercase names
14-
example.com/[email protected]/valid.go: multiple entries for file "valid.go"
15-
-- noprefix --
16-
-- example.com/[email protected]/valid.go --
17-
-- example.com/[email protected]/not/../clean --
18-
-- example.com/[email protected]/invalid.go' --
19-
-- example.com/[email protected]/GO.MOD --
20-
-- example.com/[email protected]/valid.go --
10+
not/../clean: file path is not clean
11+
invalid.go': malformed file path "invalid.go'": invalid char '\''
12+
CUE.MOD: cue.mod is not a directory
13+
valid.go: multiple entries for file "valid.go"
14+
-- valid.go --
15+
-- not/../clean --
16+
-- invalid.go' --
17+
-- CUE.MOD --
18+
-- valid.go --
2119
duplicate

internal/mod/zip/testdata/create/bad_file_path.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
path=example.com/m
1+
path=example.com/m@v1
22
version=v1.0.0
33
wantErr=malformed file path "bad.go'": invalid char '\''
44
-- bad.go' --
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
path=example.com/m
1+
path=example.com/m@v1
22
version=v1.0.0
3-
wantErr=GO.MOD: go.mod files must have lowercase names
4-
-- GO.MOD --
5-
module example.com/m
3+
wantErr=create zip: CUE.MOD/MODULE.CUE: cue.mod directories must have lowercase names
4+
-- CUE.MOD/MODULE.CUE --
5+
module: "example.com/m"

internal/mod/zip/testdata/create/bad_mod_path.txt

-3
This file was deleted.

internal/mod/zip/testdata/create/bad_mod_path_version_suffix.txt

-3
This file was deleted.

internal/mod/zip/testdata/create/bad_version.txt

-3
This file was deleted.

internal/mod/zip/testdata/create/dup_file.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
path=example.com/m
1+
path=example.com/m@v1
22
version=v1.0.0
33
wantErr=multiple entries for file "dup.go"
44
-- dup.go --

internal/mod/zip/testdata/create/dup_file_and_dir.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
path=example.com/m
1+
path=example.com/m@v1
22
version=v1.0.0
33
wantErr=entry "a.go" is both a file and a directory
44
-- a.go --
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
path=example.com/empty
1+
path=example.com/empty@v1
22
version=v1.0.0
33
hash=h1:47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=
4+
wantErr=no cue.mod/module.cue file found
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
path=example.com/m
1+
path=example.com/m@v1
22
version=v1.0.0
3-
hash=h1:xctQQey8/y7IcBjFZDP/onWLSXhlqcsC3i1fgSdpMHk=
3+
hash=h1:kfXam9weeIGbXPqzuILvA7E/rit+44dEMb1xuXLpJwE=
44
-- a.go --
55
package a
6-
-- b/GO.MOD --
6+
-- cue.mod/module.cue --
7+
module: "example.com/m"
8+
-- b/CUE.MOD/foo --
79
MODULE EXAMPLE.COM/M/B
810
-- b/b.go --
911
package b
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
path=example.com/m
1+
path=example.com/m@v1
22
version=v1.0.0
3-
hash=h1:XduFAgX/GaspZa8Jv4pfzoGEzNaU/r88PiCunijw5ok=
4-
-- go.mod --
5-
module example.com/m
3+
hash=h1:W4OVf+GhuR8uGVPxUsw60LKchTUbx+6hPgZygdB2reM=
4+
-- cue.mod/module.cue --
5+
module: "example.com/m"
66

7-
go 1.13
8-
-- sub/go.mod --
9-
module example.com/m/sub
7+
-- sub/cue.mod/module.cue --
8+
module: "example.com/m/sub"
109
-- sub/x.go' --
1110
invalid name, but this shouldn't be read
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
path=example.com/m
1+
path=example.com/m@v1
22
version=v1.0.0
3-
hash=h1:5u93LDLN0Me+NGfZtRpA5mHxY8svfykHpq4CMSaBZyc=
4-
-- go.mod --
5-
module example.com/m
3+
hash=h1:RGlDmT/EEpEYgcga7aIizwsyIh7qqsWvgHL1aZk1aJo=
4+
-- cue.mod/module.cue --
5+
module: "example.com/m"
66

7-
go 1.13
8-
-- vendor/modules.txt --
9-
included
10-
see comment in isVendoredPackage and golang.org/issue/31562.
11-
-- vendor/example.com/x/x.go --
7+
-- cue.mod/vendor/example.com/x/x.go --
128
excluded
139
-- sub/vendor/sub.txt --
14-
excluded
10+
included

internal/mod/zip/testdata/create/file_case_conflict.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
path=example.com/m
1+
path=example.com/m@v1
22
version=v1.0.0
33
wantErr=case-insensitive file name collision: "m.go" and "M.GO"
44
-- m.go --

internal/mod/zip/testdata/create/go_mod_dir.txt

-5
This file was deleted.

internal/mod/zip/testdata/create/invalid_utf8_mod_path.txt

-3
This file was deleted.
+7-18
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
1-
path=example.com/m
1+
path=example.com/m@v1
22
version=v1.0.0
3-
hash=h1:tpqYOOmuilagXzyqoJ3roUjp8gneQeTv5YVpL6BG7/k=
4-
-- go.mod --
5-
module example.com/m
6-
7-
go 1.13
8-
-- m.go --
3+
hash=h1:pMP6w+M7uoGv0NdCdaJk4KX++ZpbTibPMuqnvDngD48=
4+
-- cue.mod/module.cue --
5+
module: "example.com/m"
6+
-- m.cue --
97
package m
10-
11-
func Foo() int { return 42 }
12-
-- cmd/hello/hello.go --
8+
-- foo/bar/hello.cue --
139
package main
1410

15-
import (
16-
"fmt"
17-
"example.com/m"
18-
)
19-
20-
func main() {
21-
fmt.Println(m.Foo())
22-
}
11+
x: "hello"

internal/mod/zip/testdata/create_from_dir/bad_file_path.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
path=example.com/m
1+
path=example.com/m@v1
22
version=v1.0.0
33
wantErr=malformed file path "bad.go'": invalid char '\''
44
-- bad.go' --
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
path=example.com/m
1+
path=example.com/m@v1
22
version=v1.0.0
3-
wantErr=GO.MOD: go.mod files must have lowercase names
4-
-- GO.MOD --
5-
module example.com/m
3+
wantErr=cue.mod/MODULE.CUE: cue.mod/module.cue files must have lowercase names
4+
-- cue.mod/MODULE.CUE --
5+
module: "example.com/m"

internal/mod/zip/testdata/create_from_dir/bad_mod_path.txt

-3
This file was deleted.

internal/mod/zip/testdata/create_from_dir/bad_mod_path_version_suffix.txt

-3
This file was deleted.

internal/mod/zip/testdata/create_from_dir/bad_version.txt

-3
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
path=example.com/empty
1+
path=example.com/empty@v1
22
version=v1.0.0
33
hash=h1:47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=
4+
wantErr=no cue.mod/module.cue file found
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
path=example.com/m
1+
path=example.com/m@v1
22
version=v1.0.0
3-
hash=h1:XduFAgX/GaspZa8Jv4pfzoGEzNaU/r88PiCunijw5ok=
4-
-- go.mod --
5-
module example.com/m
6-
7-
go 1.13
8-
-- sub/go.mod --
9-
module example.com/m/sub
3+
hash=h1:js1etTKx6RMP5ZMV2GIUC2hUhREIdF7sb4aiWzQLkOU=
4+
-- cue.mod/module.cue --
5+
module: "example.com/m"
6+
-- sub/cue.mod/module.cue --
7+
module: "example.com/m/sub"
108
-- sub/x.go' --
119
invalid name, but this shouldn't be read
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
path=example.com/m
1+
path=example.com/m@v1
22
version=v1.0.0
3-
hash=h1:47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=
3+
hash=h1:js1etTKx6RMP5ZMV2GIUC2hUhREIdF7sb4aiWzQLkOU=
44
-- .bzr/exclude --
55
exclude
66
-- .git/exclude --
@@ -9,3 +9,5 @@ exclude
99
exclude
1010
-- .svn/exclude --
1111
exclude
12+
-- cue.mod/module.cue --
13+
module: "example.com/m"
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
path=example.com/m
1+
path=example.com/m@v1
22
version=v1.0.0
3-
hash=h1:5u93LDLN0Me+NGfZtRpA5mHxY8svfykHpq4CMSaBZyc=
4-
-- go.mod --
5-
module example.com/m
3+
hash=h1:RGlDmT/EEpEYgcga7aIizwsyIh7qqsWvgHL1aZk1aJo=
4+
-- cue.mod/module.cue --
5+
module: "example.com/m"
66

7-
go 1.13
8-
-- vendor/modules.txt --
9-
included
10-
see comment in isVendoredPackage and golang.org/issue/31562.
11-
-- vendor/example.com/x/x.go --
7+
-- cue.mod/vendor/example.com/x/x.go --
128
excluded
139
-- sub/vendor/sub.txt --
14-
excluded
10+
included

internal/mod/zip/testdata/create_from_dir/go_mod_dir.txt

-5
This file was deleted.

internal/mod/zip/testdata/create_from_dir/invalid_utf8_mod_path.txt

-3
This file was deleted.

0 commit comments

Comments
 (0)