diff options
author | Ian Lance Taylor <iant@golang.org> | 2021-03-12 19:44:12 -0800 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2021-03-15 14:52:55 -0700 |
commit | 3a5bcac339c5b166bc1a51c38226a8dc5e6484ca (patch) | |
tree | 0049b97ee92ee092025a5691336112654a21be94 /libgo | |
parent | Update gcc sv.po. (diff) | |
download | gcc-3a5bcac339c5b166bc1a51c38226a8dc5e6484ca.tar.gz gcc-3a5bcac339c5b166bc1a51c38226a8dc5e6484ca.tar.bz2 gcc-3a5bcac339c5b166bc1a51c38226a8dc5e6484ca.tar.xz |
libgo: update to Go 1.16.2 release
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/301459
Diffstat (limited to 'libgo')
32 files changed, 509 insertions, 191 deletions
diff --git a/libgo/MERGE b/libgo/MERGE index 183b0245ee2..a52dceb182f 100644 --- a/libgo/MERGE +++ b/libgo/MERGE | |||
@@ -1,4 +1,4 @@ | |||
1 | f21be2fdc6f1becdbed1592ea0b245cdeedc5ac8 | 1 | 3979fb9af9ccfc0b7ccb613dcf256b18c2c295f0 |
2 | 2 | ||
3 | The first line of this file holds the git revision number of the | 3 | The first line of this file holds the git revision number of the |
4 | last merge done from the master library sources. | 4 | last merge done from the master library sources. |
diff --git a/libgo/VERSION b/libgo/VERSION index 4befab24bc9..d0b0a900460 100644 --- a/libgo/VERSION +++ b/libgo/VERSION | |||
@@ -1 +1 @@ | |||
go1.16 | go1.16.2 | ||
diff --git a/libgo/go/archive/zip/reader.go b/libgo/go/archive/zip/reader.go index 8b4e77875fb..c288ad965bc 100644 --- a/libgo/go/archive/zip/reader.go +++ b/libgo/go/archive/zip/reader.go | |||
@@ -664,7 +664,7 @@ func toValidName(name string) string { | |||
664 | if strings.HasPrefix(p, "/") { | 664 | if strings.HasPrefix(p, "/") { |
665 | p = p[len("/"):] | 665 | p = p[len("/"):] |
666 | } | 666 | } |
667 | for strings.HasPrefix(name, "../") { | 667 | for strings.HasPrefix(p, "../") { |
668 | p = p[len("../"):] | 668 | p = p[len("../"):] |
669 | } | 669 | } |
670 | return p | 670 | return p |
diff --git a/libgo/go/archive/zip/reader_test.go b/libgo/go/archive/zip/reader_test.go index 34e96f7da43..5faf1f49b51 100644 --- a/libgo/go/archive/zip/reader_test.go +++ b/libgo/go/archive/zip/reader_test.go | |||
@@ -1081,3 +1081,38 @@ func TestFS(t *testing.T) { | |||
1081 | t.Fatal(err) | 1081 | t.Fatal(err) |
1082 | } | 1082 | } |
1083 | } | 1083 | } |
1084 | |||
1085 | func TestCVE202127919(t *testing.T) { | ||
1086 | // Archive containing only the file "../test.txt" | ||
1087 | data := []byte{ | ||
1088 | 0x50, 0x4b, 0x03, 0x04, 0x14, 0x00, 0x08, 0x00, | ||
1089 | 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
1090 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
1091 | 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x2e, 0x2e, | ||
1092 | 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x74, 0x78, | ||
1093 | 0x74, 0x0a, 0xc9, 0xc8, 0x2c, 0x56, 0xc8, 0x2c, | ||
1094 | 0x56, 0x48, 0x54, 0x28, 0x49, 0x2d, 0x2e, 0x51, | ||
1095 | 0x28, 0x49, 0xad, 0x28, 0x51, 0x48, 0xcb, 0xcc, | ||
1096 | 0x49, 0xd5, 0xe3, 0x02, 0x04, 0x00, 0x00, 0xff, | ||
1097 | 0xff, 0x50, 0x4b, 0x07, 0x08, 0xc0, 0xd7, 0xed, | ||
1098 | 0xc3, 0x20, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, | ||
1099 | 0x00, 0x50, 0x4b, 0x01, 0x02, 0x14, 0x00, 0x14, | ||
1100 | 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, | ||
1101 | 0x00, 0xc0, 0xd7, 0xed, 0xc3, 0x20, 0x00, 0x00, | ||
1102 | 0x00, 0x1a, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, | ||
1103 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
1104 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2e, | ||
1105 | 0x2e, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x74, | ||
1106 | 0x78, 0x74, 0x50, 0x4b, 0x05, 0x06, 0x00, 0x00, | ||
1107 | 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x39, 0x00, | ||
1108 | 0x00, 0x00, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
1109 | } | ||
1110 | r, err := NewReader(bytes.NewReader([]byte(data)), int64(len(data))) | ||
1111 | if err != nil { | ||
1112 | t.Fatalf("Error reading the archive: %v", err) | ||
1113 | } | ||
1114 | _, err = r.Open("test.txt") | ||
1115 | if err != nil { | ||
1116 | t.Errorf("Error reading file: %v", err) | ||
1117 | } | ||
1118 | } | ||
diff --git a/libgo/go/cmd/go.mod b/libgo/go/cmd/go.mod index 235e28f64f3..35582f3975f 100644 --- a/libgo/go/cmd/go.mod +++ b/libgo/go/cmd/go.mod | |||
@@ -6,7 +6,7 @@ require ( | |||
6 | github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2 | 6 | github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2 |
7 | golang.org/x/arch v0.0.0-20201008161808-52c3e6f60cff | 7 | golang.org/x/arch v0.0.0-20201008161808-52c3e6f60cff |
8 | golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 | 8 | golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 |
9 | golang.org/x/mod v0.4.1 | 9 | golang.org/x/mod v0.4.2-0.20210302225053-d515b24adc21 |
10 | golang.org/x/sys v0.0.0-20201204225414-ed752295db88 // indirect | 10 | golang.org/x/sys v0.0.0-20201204225414-ed752295db88 // indirect |
11 | golang.org/x/tools v0.0.0-20210107193943-4ed967dd8eff | 11 | golang.org/x/tools v0.0.0-20210107193943-4ed967dd8eff |
12 | ) | 12 | ) |
diff --git a/libgo/go/cmd/go/internal/get/get.go b/libgo/go/cmd/go/internal/get/get.go index 38ff3823f22..329a2f5eda4 100644 --- a/libgo/go/cmd/go/internal/get/get.go +++ b/libgo/go/cmd/go/internal/get/get.go | |||
@@ -431,7 +431,7 @@ func downloadPackage(p *load.Package) error { | |||
431 | } | 431 | } |
432 | importPrefix = importPrefix[:slash] | 432 | importPrefix = importPrefix[:slash] |
433 | } | 433 | } |
434 | if err := module.CheckImportPath(importPrefix); err != nil { | 434 | if err := checkImportPath(importPrefix); err != nil { |
435 | return fmt.Errorf("%s: invalid import path: %v", p.ImportPath, err) | 435 | return fmt.Errorf("%s: invalid import path: %v", p.ImportPath, err) |
436 | } | 436 | } |
437 | security := web.SecureOnly | 437 | security := web.SecureOnly |
@@ -591,3 +591,31 @@ func selectTag(goVersion string, tags []string) (match string) { | |||
591 | } | 591 | } |
592 | return "" | 592 | return "" |
593 | } | 593 | } |
594 | |||
595 | // checkImportPath is like module.CheckImportPath, but it forbids leading dots | ||
596 | // in path elements. This can lead to 'go get' creating .git and other VCS | ||
597 | // directories in places we might run VCS tools later. | ||
598 | func checkImportPath(path string) error { | ||
599 | if err := module.CheckImportPath(path); err != nil { | ||
600 | return err | ||
601 | } | ||
602 | checkElem := func(elem string) error { | ||
603 | if elem[0] == '.' { | ||
604 | return fmt.Errorf("malformed import path %q: leading dot in path element", path) | ||
605 | } | ||
606 | return nil | ||
607 | } | ||
608 | elemStart := 0 | ||
609 | for i, r := range path { | ||
610 | if r == '/' { | ||
611 | if err := checkElem(path[elemStart:]); err != nil { | ||
612 | return err | ||
613 | } | ||
614 | elemStart = i + 1 | ||
615 | } | ||
616 | } | ||
617 | if err := checkElem(path[elemStart:]); err != nil { | ||
618 | return err | ||
619 | } | ||
620 | return nil | ||
621 | } | ||
diff --git a/libgo/go/cmd/go/internal/modcmd/tidy.go b/libgo/go/cmd/go/internal/modcmd/tidy.go index 3b83d87a8eb..8bc9ed50bed 100644 --- a/libgo/go/cmd/go/internal/modcmd/tidy.go +++ b/libgo/go/cmd/go/internal/modcmd/tidy.go | |||
@@ -62,10 +62,11 @@ func runTidy(ctx context.Context, cmd *base.Command, args []string) { | |||
62 | modload.RootMode = modload.NeedRoot | 62 | modload.RootMode = modload.NeedRoot |
63 | 63 | ||
64 | modload.LoadPackages(ctx, modload.PackageOpts{ | 64 | modload.LoadPackages(ctx, modload.PackageOpts{ |
65 | Tags: imports.AnyTags(), | 65 | Tags: imports.AnyTags(), |
66 | ResolveMissingImports: true, | 66 | ResolveMissingImports: true, |
67 | LoadTests: true, | 67 | LoadTests: true, |
68 | AllowErrors: tidyE, | 68 | AllowErrors: tidyE, |
69 | SilenceMissingStdImports: true, | ||
69 | }, "all") | 70 | }, "all") |
70 | 71 | ||
71 | modload.TidyBuildList() | 72 | modload.TidyBuildList() |
diff --git a/libgo/go/cmd/go/internal/modcmd/vendor.go b/libgo/go/cmd/go/internal/modcmd/vendor.go index d3ed9e00e22..ac1fb7720aa 100644 --- a/libgo/go/cmd/go/internal/modcmd/vendor.go +++ b/libgo/go/cmd/go/internal/modcmd/vendor.go | |||
@@ -64,10 +64,11 @@ func runVendor(ctx context.Context, cmd *base.Command, args []string) { | |||
64 | modload.RootMode = modload.NeedRoot | 64 | modload.RootMode = modload.NeedRoot |
65 | 65 | ||
66 | loadOpts := modload.PackageOpts{ | 66 | loadOpts := modload.PackageOpts{ |
67 | Tags: imports.AnyTags(), | 67 | Tags: imports.AnyTags(), |
68 | ResolveMissingImports: true, | 68 | ResolveMissingImports: true, |
69 | UseVendorAll: true, | 69 | UseVendorAll: true, |
70 | AllowErrors: vendorE, | 70 | AllowErrors: vendorE, |
71 | SilenceMissingStdImports: true, | ||
71 | } | 72 | } |
72 | _, pkgs := modload.LoadPackages(ctx, loadOpts, "all") | 73 | _, pkgs := modload.LoadPackages(ctx, loadOpts, "all") |
73 | 74 | ||
diff --git a/libgo/go/cmd/go/internal/modget/get.go b/libgo/go/cmd/go/internal/modget/get.go index dccacd3d1ee..5a98408a325 100644 --- a/libgo/go/cmd/go/internal/modget/get.go +++ b/libgo/go/cmd/go/internal/modget/get.go | |||
@@ -1514,7 +1514,7 @@ func (r *resolver) checkPackagesAndRetractions(ctx context.Context, pkgPatterns | |||
1514 | } | 1514 | } |
1515 | } | 1515 | } |
1516 | if retractPath != "" { | 1516 | if retractPath != "" { |
1517 | fmt.Fprintf(os.Stderr, "go: to switch to the latest unretracted version, run:\n\tgo get %s@latest", retractPath) | 1517 | fmt.Fprintf(os.Stderr, "go: to switch to the latest unretracted version, run:\n\tgo get %s@latest\n", retractPath) |
1518 | } | 1518 | } |
1519 | } | 1519 | } |
1520 | 1520 | ||
diff --git a/libgo/go/cmd/go/internal/modget/query.go b/libgo/go/cmd/go/internal/modget/query.go index d8364c8c0d3..1a5a60f7eb9 100644 --- a/libgo/go/cmd/go/internal/modget/query.go +++ b/libgo/go/cmd/go/internal/modget/query.go | |||
@@ -186,7 +186,7 @@ func (q *query) validate() error { | |||
186 | if q.pattern == "all" { | 186 | if q.pattern == "all" { |
187 | // If there is no main module, "all" is not meaningful. | 187 | // If there is no main module, "all" is not meaningful. |
188 | if !modload.HasModRoot() { | 188 | if !modload.HasModRoot() { |
189 | return fmt.Errorf(`cannot match "all": working directory is not part of a module`) | 189 | return fmt.Errorf(`cannot match "all": %v`, modload.ErrNoModRoot) |
190 | } | 190 | } |
191 | if !versionOkForMainModule(q.version) { | 191 | if !versionOkForMainModule(q.version) { |
192 | // TODO(bcmills): "all@none" seems like a totally reasonable way to | 192 | // TODO(bcmills): "all@none" seems like a totally reasonable way to |
diff --git a/libgo/go/cmd/go/internal/modload/import.go b/libgo/go/cmd/go/internal/modload/import.go index 182429aee41..995641c9f1f 100644 --- a/libgo/go/cmd/go/internal/modload/import.go +++ b/libgo/go/cmd/go/internal/modload/import.go | |||
@@ -51,7 +51,7 @@ func (e *ImportMissingError) Error() string { | |||
51 | if e.isStd { | 51 | if e.isStd { |
52 | return fmt.Sprintf("package %s is not in GOROOT (%s)", e.Path, filepath.Join(cfg.GOROOT, "src", e.Path)) | 52 | return fmt.Sprintf("package %s is not in GOROOT (%s)", e.Path, filepath.Join(cfg.GOROOT, "src", e.Path)) |
53 | } | 53 | } |
54 | if e.QueryErr != nil { | 54 | if e.QueryErr != nil && e.QueryErr != ErrNoModRoot { |
55 | return fmt.Sprintf("cannot find module providing package %s: %v", e.Path, e.QueryErr) | 55 | return fmt.Sprintf("cannot find module providing package %s: %v", e.Path, e.QueryErr) |
56 | } | 56 | } |
57 | if cfg.BuildMod == "mod" || (cfg.BuildMod == "readonly" && allowMissingModuleImports) { | 57 | if cfg.BuildMod == "mod" || (cfg.BuildMod == "readonly" && allowMissingModuleImports) { |
@@ -66,13 +66,11 @@ func (e *ImportMissingError) Error() string { | |||
66 | return fmt.Sprintf("module %s provides package %s and is replaced but not required; to add it:\n\tgo get %s", e.replaced.Path, e.Path, suggestArg) | 66 | return fmt.Sprintf("module %s provides package %s and is replaced but not required; to add it:\n\tgo get %s", e.replaced.Path, e.Path, suggestArg) |
67 | } | 67 | } |
68 | 68 | ||
69 | suggestion := "" | 69 | message := fmt.Sprintf("no required module provides package %s", e.Path) |
70 | if !HasModRoot() { | 70 | if e.QueryErr != nil { |
71 | suggestion = ": working directory is not part of a module" | 71 | return fmt.Sprintf("%s: %v", message, e.QueryErr) |
72 | } else { | ||
73 | suggestion = fmt.Sprintf("; to add it:\n\tgo get %s", e.Path) | ||
74 | } | 72 | } |
75 | return fmt.Sprintf("no required module provides package %s%s", e.Path, suggestion) | 73 | return fmt.Sprintf("%s; to add it:\n\tgo get %s", message, e.Path) |
76 | } | 74 | } |
77 | 75 | ||
78 | if e.newMissingVersion != "" { | 76 | if e.newMissingVersion != "" { |
@@ -318,7 +316,11 @@ func importFromBuildList(ctx context.Context, path string, buildList []module.Ve | |||
318 | return mods[0], dirs[0], nil | 316 | return mods[0], dirs[0], nil |
319 | } | 317 | } |
320 | 318 | ||
321 | return module.Version{}, "", &ImportMissingError{Path: path, isStd: pathIsStd} | 319 | var queryErr error |
320 | if !HasModRoot() { | ||
321 | queryErr = ErrNoModRoot | ||
322 | } | ||
323 | return module.Version{}, "", &ImportMissingError{Path: path, QueryErr: queryErr, isStd: pathIsStd} | ||
322 | } | 324 | } |
323 | 325 | ||
324 | // queryImport attempts to locate a module that can be added to the current | 326 | // queryImport attempts to locate a module that can be added to the current |
diff --git a/libgo/go/cmd/go/internal/modload/init.go b/libgo/go/cmd/go/internal/modload/init.go index bc8d17e0a5f..8ec1c8681a9 100644 --- a/libgo/go/cmd/go/internal/modload/init.go +++ b/libgo/go/cmd/go/internal/modload/init.go | |||
@@ -177,7 +177,7 @@ func Init() { | |||
177 | base.Fatalf("go: cannot find main module, but -modfile was set.\n\t-modfile cannot be used to set the module root directory.") | 177 | base.Fatalf("go: cannot find main module, but -modfile was set.\n\t-modfile cannot be used to set the module root directory.") |
178 | } | 178 | } |
179 | if RootMode == NeedRoot { | 179 | if RootMode == NeedRoot { |
180 | base.Fatalf("go: cannot find main module; see 'go help modules'") | 180 | base.Fatalf("go: %v", ErrNoModRoot) |
181 | } | 181 | } |
182 | if !mustUseModules { | 182 | if !mustUseModules { |
183 | // GO111MODULE is 'auto', and we can't find a module root. | 183 | // GO111MODULE is 'auto', and we can't find a module root. |
@@ -338,9 +338,11 @@ func die() { | |||
338 | } | 338 | } |
339 | base.Fatalf("go: cannot find main module, but found %s in %s\n\tto create a module there, run:\n\t%sgo mod init", name, dir, cdCmd) | 339 | base.Fatalf("go: cannot find main module, but found %s in %s\n\tto create a module there, run:\n\t%sgo mod init", name, dir, cdCmd) |
340 | } | 340 | } |
341 | base.Fatalf("go: cannot find main module; see 'go help modules'") | 341 | base.Fatalf("go: %v", ErrNoModRoot) |
342 | } | 342 | } |
343 | 343 | ||
344 | var ErrNoModRoot = errors.New("go.mod file not found in current directory or any parent directory; see 'go help modules'") | ||
345 | |||
344 | // LoadModFile sets Target and, if there is a main module, parses the initial | 346 | // LoadModFile sets Target and, if there is a main module, parses the initial |
345 | // build list from its go.mod file. | 347 | // build list from its go.mod file. |
346 | // | 348 | // |
@@ -539,9 +541,10 @@ func fixVersion(ctx context.Context, fixed *bool) modfile.VersionFixer { | |||
539 | } | 541 | } |
540 | } | 542 | } |
541 | if vers != "" && module.CanonicalVersion(vers) == vers { | 543 | if vers != "" && module.CanonicalVersion(vers) == vers { |
542 | if err := module.CheckPathMajor(vers, pathMajor); err == nil { | 544 | if err := module.CheckPathMajor(vers, pathMajor); err != nil { |
543 | return vers, nil | 545 | return "", module.VersionError(module.Version{Path: path, Version: vers}, err) |
544 | } | 546 | } |
547 | return vers, nil | ||
545 | } | 548 | } |
546 | 549 | ||
547 | info, err := Query(ctx, path, vers, "", nil) | 550 | info, err := Query(ctx, path, vers, "", nil) |
diff --git a/libgo/go/cmd/go/internal/modload/list.go b/libgo/go/cmd/go/internal/modload/list.go index 3491f941cd3..7b1aa7fd413 100644 --- a/libgo/go/cmd/go/internal/modload/list.go +++ b/libgo/go/cmd/go/internal/modload/list.go | |||
@@ -73,7 +73,7 @@ func listModules(ctx context.Context, args []string, listVersions, listRetracted | |||
73 | base.Fatalf("go: cannot use relative path %s to specify module", arg) | 73 | base.Fatalf("go: cannot use relative path %s to specify module", arg) |
74 | } | 74 | } |
75 | if !HasModRoot() && (arg == "all" || strings.Contains(arg, "...")) { | 75 | if !HasModRoot() && (arg == "all" || strings.Contains(arg, "...")) { |
76 | base.Fatalf("go: cannot match %q: working directory is not part of a module", arg) | 76 | base.Fatalf("go: cannot match %q: %v", arg, ErrNoModRoot) |
77 | } | 77 | } |
78 | if i := strings.Index(arg, "@"); i >= 0 { | 78 | if i := strings.Index(arg, "@"); i >= 0 { |
79 | path := arg[:i] | 79 | path := arg[:i] |
diff --git a/libgo/go/cmd/go/internal/modload/load.go b/libgo/go/cmd/go/internal/modload/load.go index 6d87acc6d3b..154fc3c6f0a 100644 --- a/libgo/go/cmd/go/internal/modload/load.go +++ b/libgo/go/cmd/go/internal/modload/load.go | |||
@@ -170,6 +170,12 @@ type PackageOpts struct { | |||
170 | // that occur while loading packages. SilenceErrors implies AllowErrors. | 170 | // that occur while loading packages. SilenceErrors implies AllowErrors. |
171 | SilenceErrors bool | 171 | SilenceErrors bool |
172 | 172 | ||
173 | // SilenceMissingStdImports indicates that LoadPackages should not print | ||
174 | // errors or terminate the process if an imported package is missing, and the | ||
175 | // import path looks like it might be in the standard library (perhaps in a | ||
176 | // future version). | ||
177 | SilenceMissingStdImports bool | ||
178 | |||
173 | // SilenceUnmatchedWarnings suppresses the warnings normally emitted for | 179 | // SilenceUnmatchedWarnings suppresses the warnings normally emitted for |
174 | // patterns that did not match any packages. | 180 | // patterns that did not match any packages. |
175 | SilenceUnmatchedWarnings bool | 181 | SilenceUnmatchedWarnings bool |
@@ -287,8 +293,13 @@ func LoadPackages(ctx context.Context, opts PackageOpts, patterns ...string) (ma | |||
287 | sumErr.importerIsTest = importer.testOf != nil | 293 | sumErr.importerIsTest = importer.testOf != nil |
288 | } | 294 | } |
289 | } | 295 | } |
296 | silence := opts.SilenceErrors | ||
297 | if stdErr := (*ImportMissingError)(nil); errors.As(pkg.err, &stdErr) && | ||
298 | stdErr.isStd && opts.SilenceMissingStdImports { | ||
299 | silence = true | ||
300 | } | ||
290 | 301 | ||
291 | if !opts.SilenceErrors { | 302 | if !silence { |
292 | if opts.AllowErrors { | 303 | if opts.AllowErrors { |
293 | fmt.Fprintf(os.Stderr, "%s: %v\n", pkg.stackText(), pkg.err) | 304 | fmt.Fprintf(os.Stderr, "%s: %v\n", pkg.stackText(), pkg.err) |
294 | } else { | 305 | } else { |
diff --git a/libgo/go/cmd/go/internal/run/run.go b/libgo/go/cmd/go/internal/run/run.go index 99578b244c8..666b1a0e560 100644 --- a/libgo/go/cmd/go/internal/run/run.go +++ b/libgo/go/cmd/go/internal/run/run.go | |||
@@ -96,28 +96,12 @@ func runRun(ctx context.Context, cmd *base.Command, args []string) { | |||
96 | base.Fatalf("go run: no go files listed") | 96 | base.Fatalf("go run: no go files listed") |
97 | } | 97 | } |
98 | cmdArgs := args[i:] | 98 | cmdArgs := args[i:] |
99 | if p.Error != nil { | 99 | load.CheckPackageErrors([]*load.Package{p}) |
100 | base.Fatalf("%s", p.Error) | ||
101 | } | ||
102 | 100 | ||
103 | p.Internal.OmitDebug = true | ||
104 | if len(p.DepsErrors) > 0 { | ||
105 | // Since these are errors in dependencies, | ||
106 | // the same error might show up multiple times, | ||
107 | // once in each package that depends on it. | ||
108 | // Only print each once. | ||
109 | printed := map[*load.PackageError]bool{} | ||
110 | for _, err := range p.DepsErrors { | ||
111 | if !printed[err] { | ||
112 | printed[err] = true | ||
113 | base.Errorf("%s", err) | ||
114 | } | ||
115 | } | ||
116 | } | ||
117 | base.ExitIfErrors() | ||
118 | if p.Name != "main" { | 101 | if p.Name != "main" { |
119 | base.Fatalf("go run: cannot run non-main package") | 102 | base.Fatalf("go run: cannot run non-main package") |
120 | } | 103 | } |
104 | p.Internal.OmitDebug = true | ||
121 | p.Target = "" // must build - not up to date | 105 | p.Target = "" // must build - not up to date |
122 | if p.Internal.CmdlineFiles { | 106 | if p.Internal.CmdlineFiles { |
123 | //set executable name if go file is given as cmd-argument | 107 | //set executable name if go file is given as cmd-argument |
diff --git a/libgo/go/cmd/go/testdata/script/mod_convert_dep.txt b/libgo/go/cmd/go/testdata/script/mod_convert_dep.txt index ad22aca5be8..875a836fd27 100644 --- a/libgo/go/cmd/go/testdata/script/mod_convert_dep.txt +++ b/libgo/go/cmd/go/testdata/script/mod_convert_dep.txt | |||
@@ -18,7 +18,7 @@ stdout '^m$' | |||
18 | # Test that we ignore directories when trying to find alternate config files. | 18 | # Test that we ignore directories when trying to find alternate config files. |
19 | cd $WORK/gopkgdir/x | 19 | cd $WORK/gopkgdir/x |
20 | ! go list . | 20 | ! go list . |
21 | stderr 'cannot find main module' | 21 | stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$' |
22 | ! stderr 'Gopkg.lock' | 22 | ! stderr 'Gopkg.lock' |
23 | 23 | ||
24 | -- $WORK/test/Gopkg.lock -- | 24 | -- $WORK/test/Gopkg.lock -- |
diff --git a/libgo/go/cmd/go/testdata/script/mod_edit.txt b/libgo/go/cmd/go/testdata/script/mod_edit.txt index d7e681e8313..9da69306dac 100644 --- a/libgo/go/cmd/go/testdata/script/mod_edit.txt +++ b/libgo/go/cmd/go/testdata/script/mod_edit.txt | |||
@@ -16,9 +16,9 @@ cmpenv go.mod $WORK/go.mod.init | |||
16 | cmpenv go.mod $WORK/go.mod.init | 16 | cmpenv go.mod $WORK/go.mod.init |
17 | 17 | ||
18 | # go mod edits | 18 | # go mod edits |
19 | go mod edit -droprequire=x.1 -require=x.1@v1.0.0 -require=x.2@v1.1.0 -droprequire=x.2 -exclude='x.1 @ v1.2.0' -exclude=x.1@v1.2.1 -replace=x.1@v1.3.0=y.1@v1.4.0 -replace='x.1@v1.4.0 = ../z' -retract=v1.6.0 -retract=[v1.1.0,v1.2.0] -retract=[v1.3.0,v1.4.0] -retract=v1.0.0 | 19 | go mod edit -droprequire=x.1 -require=x.1@v1.0.0 -require=x.2@v1.1.0 -droprequire=x.2 -exclude='x.1 @ v1.2.0' -exclude=x.1@v1.2.1 -exclude=x.1@v2.0.0+incompatible -replace=x.1@v1.3.0=y.1@v1.4.0 -replace='x.1@v1.4.0 = ../z' -retract=v1.6.0 -retract=[v1.1.0,v1.2.0] -retract=[v1.3.0,v1.4.0] -retract=v1.0.0 |
20 | cmpenv go.mod $WORK/go.mod.edit1 | 20 | cmpenv go.mod $WORK/go.mod.edit1 |
21 | go mod edit -droprequire=x.1 -dropexclude=x.1@v1.2.1 -dropreplace=x.1@v1.3.0 -require=x.3@v1.99.0 -dropretract=v1.0.0 -dropretract=[v1.1.0,v1.2.0] | 21 | go mod edit -droprequire=x.1 -dropexclude=x.1@v1.2.1 -dropexclude=x.1@v2.0.0+incompatible -dropreplace=x.1@v1.3.0 -require=x.3@v1.99.0 -dropretract=v1.0.0 -dropretract=[v1.1.0,v1.2.0] |
22 | cmpenv go.mod $WORK/go.mod.edit2 | 22 | cmpenv go.mod $WORK/go.mod.edit2 |
23 | 23 | ||
24 | # -exclude and -retract reject invalid versions. | 24 | # -exclude and -retract reject invalid versions. |
@@ -27,6 +27,17 @@ stderr '^go mod: -exclude=example.com/m@bad: version "bad" invalid: must be of t | |||
27 | ! go mod edit -retract=bad | 27 | ! go mod edit -retract=bad |
28 | stderr '^go mod: -retract=bad: version "bad" invalid: must be of the form v1.2.3$' | 28 | stderr '^go mod: -retract=bad: version "bad" invalid: must be of the form v1.2.3$' |
29 | 29 | ||
30 | ! go mod edit -exclude=example.com/m@v2.0.0 | ||
31 | stderr '^go mod: -exclude=example.com/m@v2\.0\.0: version "v2\.0\.0" invalid: should be v2\.0\.0\+incompatible \(or module example\.com/m/v2\)$' | ||
32 | |||
33 | ! go mod edit -exclude=example.com/m/v2@v1.0.0 | ||
34 | stderr '^go mod: -exclude=example.com/m/v2@v1\.0\.0: version "v1\.0\.0" invalid: should be v2, not v1$' | ||
35 | |||
36 | ! go mod edit -exclude=gopkg.in/example.v1@v2.0.0 | ||
37 | stderr '^go mod: -exclude=gopkg\.in/example\.v1@v2\.0\.0: version "v2\.0\.0" invalid: should be v1, not v2$' | ||
38 | |||
39 | cmpenv go.mod $WORK/go.mod.edit2 | ||
40 | |||
30 | # go mod edit -json | 41 | # go mod edit -json |
31 | go mod edit -json | 42 | go mod edit -json |
32 | cmpenv stdout $WORK/go.mod.json | 43 | cmpenv stdout $WORK/go.mod.json |
@@ -88,6 +99,7 @@ require x.1 v1.0.0 | |||
88 | exclude ( | 99 | exclude ( |
89 | x.1 v1.2.0 | 100 | x.1 v1.2.0 |
90 | x.1 v1.2.1 | 101 | x.1 v1.2.1 |
102 | x.1 v2.0.0+incompatible | ||
91 | ) | 103 | ) |
92 | 104 | ||
93 | replace ( | 105 | replace ( |
diff --git a/libgo/go/cmd/go/testdata/script/mod_find.txt b/libgo/go/cmd/go/testdata/script/mod_find.txt index 9468acfd33d..1e01973ff41 100644 --- a/libgo/go/cmd/go/testdata/script/mod_find.txt +++ b/libgo/go/cmd/go/testdata/script/mod_find.txt | |||
@@ -49,7 +49,7 @@ rm go.mod | |||
49 | # Test that we ignore directories when trying to find go.mod. | 49 | # Test that we ignore directories when trying to find go.mod. |
50 | cd $WORK/gomoddir | 50 | cd $WORK/gomoddir |
51 | ! go list . | 51 | ! go list . |
52 | stderr 'cannot find main module' | 52 | stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$' |
53 | 53 | ||
54 | [!symlink] stop | 54 | [!symlink] stop |
55 | 55 | ||
diff --git a/libgo/go/cmd/go/testdata/script/mod_outside.txt b/libgo/go/cmd/go/testdata/script/mod_outside.txt index 8f01b5d2426..565589268ee 100644 --- a/libgo/go/cmd/go/testdata/script/mod_outside.txt +++ b/libgo/go/cmd/go/testdata/script/mod_outside.txt | |||
@@ -12,13 +12,13 @@ stdout 'NUL|/dev/null' | |||
12 | # 'go list' without arguments implicitly operates on the current directory, | 12 | # 'go list' without arguments implicitly operates on the current directory, |
13 | # which is not in a module. | 13 | # which is not in a module. |
14 | ! go list | 14 | ! go list |
15 | stderr 'cannot find main module' | 15 | stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$' |
16 | go list -m | 16 | go list -m |
17 | stdout '^command-line-arguments$' | 17 | stdout '^command-line-arguments$' |
18 | # 'go list' in the working directory should fail even if there is a a 'package | 18 | # 'go list' in the working directory should fail even if there is a a 'package |
19 | # main' present: without a main module, we do not know its package path. | 19 | # main' present: without a main module, we do not know its package path. |
20 | ! go list ./needmod | 20 | ! go list ./needmod |
21 | stderr 'cannot find main module' | 21 | stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$' |
22 | 22 | ||
23 | # 'go list all' lists the transitive import graph of the main module, | 23 | # 'go list all' lists the transitive import graph of the main module, |
24 | # which is empty if there is no main module. | 24 | # which is empty if there is no main module. |
@@ -41,7 +41,7 @@ stdout 'command-line-arguments' | |||
41 | 41 | ||
42 | # 'go list' on a package from a module should fail. | 42 | # 'go list' on a package from a module should fail. |
43 | ! go list example.com/printversion | 43 | ! go list example.com/printversion |
44 | stderr '^no required module provides package example.com/printversion: working directory is not part of a module$' | 44 | stderr '^no required module provides package example.com/printversion: go.mod file not found in current directory or any parent directory; see ''go help modules''$' |
45 | 45 | ||
46 | 46 | ||
47 | # 'go list -m' with an explicit version should resolve that version. | 47 | # 'go list -m' with an explicit version should resolve that version. |
@@ -54,19 +54,19 @@ stdout 'v1.0.0\s+v1.0.1\s+v1.1.0' | |||
54 | 54 | ||
55 | # 'go list -m all' should fail. "all" is not meaningful outside of a module. | 55 | # 'go list -m all' should fail. "all" is not meaningful outside of a module. |
56 | ! go list -m all | 56 | ! go list -m all |
57 | stderr 'go: cannot match "all": working directory is not part of a module' | 57 | stderr 'go: cannot match "all": go.mod file not found in current directory or any parent directory; see ''go help modules''$' |
58 | 58 | ||
59 | # 'go list -m <mods> all' should also fail. | 59 | # 'go list -m <mods> all' should also fail. |
60 | ! go list -m example.com/printversion@v1.0.0 all | 60 | ! go list -m example.com/printversion@v1.0.0 all |
61 | stderr 'go: cannot match "all": working directory is not part of a module' | 61 | stderr 'go: cannot match "all": go.mod file not found in current directory or any parent directory; see ''go help modules''$' |
62 | ! stdout 'example.com/version' | 62 | ! stdout 'example.com/version' |
63 | 63 | ||
64 | # 'go list -m' with wildcards should fail. Wildcards match modules in the | 64 | # 'go list -m' with wildcards should fail. Wildcards match modules in the |
65 | # build list, so they aren't meaningful outside a module. | 65 | # build list, so they aren't meaningful outside a module. |
66 | ! go list -m ... | 66 | ! go list -m ... |
67 | stderr 'go: cannot match "...": working directory is not part of a module' | 67 | stderr 'go: cannot match "...": go.mod file not found in current directory or any parent directory; see ''go help modules''$' |
68 | ! go list -m rsc.io/quote/... | 68 | ! go list -m rsc.io/quote/... |
69 | stderr 'go: cannot match "rsc.io/quote/...": working directory is not part of a module' | 69 | stderr 'go: cannot match "rsc.io/quote/...": go.mod file not found in current directory or any parent directory; see ''go help modules''$' |
70 | 70 | ||
71 | 71 | ||
72 | # 'go clean' should skip the current directory if it isn't in a module. | 72 | # 'go clean' should skip the current directory if it isn't in a module. |
@@ -76,20 +76,20 @@ go clean -n | |||
76 | 76 | ||
77 | # 'go mod graph' should fail, since there's no module graph. | 77 | # 'go mod graph' should fail, since there's no module graph. |
78 | ! go mod graph | 78 | ! go mod graph |
79 | stderr 'cannot find main module' | 79 | stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$' |
80 | 80 | ||
81 | # 'go mod why' should fail, since there is no main module to depend on anything. | 81 | # 'go mod why' should fail, since there is no main module to depend on anything. |
82 | ! go mod why -m example.com/version | 82 | ! go mod why -m example.com/version |
83 | stderr 'cannot find main module' | 83 | stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$' |
84 | 84 | ||
85 | # 'go mod edit', 'go mod tidy', and 'go mod fmt' should fail: | 85 | # 'go mod edit', 'go mod tidy', and 'go mod fmt' should fail: |
86 | # there is no go.mod file to edit. | 86 | # there is no go.mod file to edit. |
87 | ! go mod tidy | 87 | ! go mod tidy |
88 | stderr 'cannot find main module' | 88 | stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$' |
89 | ! go mod edit -fmt | 89 | ! go mod edit -fmt |
90 | stderr 'cannot find main module' | 90 | stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$' |
91 | ! go mod edit -require example.com/version@v1.0.0 | 91 | ! go mod edit -require example.com/version@v1.0.0 |
92 | stderr 'cannot find main module' | 92 | stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$' |
93 | 93 | ||
94 | 94 | ||
95 | # 'go mod download' without arguments should report an error. | 95 | # 'go mod download' without arguments should report an error. |
@@ -104,33 +104,33 @@ exists $GOPATH/pkg/mod/cache/download/example.com/printversion/@v/v1.0.0.zip | |||
104 | 104 | ||
105 | # 'go mod download all' should fail. "all" is not meaningful outside of a module. | 105 | # 'go mod download all' should fail. "all" is not meaningful outside of a module. |
106 | ! go mod download all | 106 | ! go mod download all |
107 | stderr 'go: cannot match "all": working directory is not part of a module' | 107 | stderr 'go: cannot match "all": go.mod file not found in current directory or any parent directory; see ''go help modules''$' |
108 | 108 | ||
109 | 109 | ||
110 | # 'go mod vendor' should fail: it starts by clearing the existing vendor | 110 | # 'go mod vendor' should fail: it starts by clearing the existing vendor |
111 | # directory, and we don't know where that is. | 111 | # directory, and we don't know where that is. |
112 | ! go mod vendor | 112 | ! go mod vendor |
113 | stderr 'cannot find main module' | 113 | stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$' |
114 | 114 | ||
115 | 115 | ||
116 | # 'go mod verify' should fail: we have no modules to verify. | 116 | # 'go mod verify' should fail: we have no modules to verify. |
117 | ! go mod verify | 117 | ! go mod verify |
118 | stderr 'cannot find main module' | 118 | stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$' |
119 | 119 | ||
120 | 120 | ||
121 | # 'go get' without arguments implicitly operates on the main module, and thus | 121 | # 'go get' without arguments implicitly operates on the main module, and thus |
122 | # should fail. | 122 | # should fail. |
123 | ! go get | 123 | ! go get |
124 | stderr 'cannot find main module' | 124 | stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$' |
125 | ! go get -u | 125 | ! go get -u |
126 | stderr 'cannot find main module' | 126 | stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$' |
127 | ! go get -u ./needmod | 127 | ! go get -u ./needmod |
128 | stderr 'cannot find main module' | 128 | stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$' |
129 | 129 | ||
130 | # 'go get -u all' upgrades the transitive import graph of the main module, | 130 | # 'go get -u all' upgrades the transitive import graph of the main module, |
131 | # which is empty. | 131 | # which is empty. |
132 | ! go get -u all | 132 | ! go get -u all |
133 | stderr 'go get: cannot match "all": working directory is not part of a module' | 133 | stderr '^go get: cannot match "all": go.mod file not found in current directory or any parent directory; see ''go help modules''$' |
134 | 134 | ||
135 | # 'go get' should check the proposed module graph for consistency, | 135 | # 'go get' should check the proposed module graph for consistency, |
136 | # even though we won't write it anywhere. | 136 | # even though we won't write it anywhere. |
@@ -147,16 +147,16 @@ exists $GOPATH/pkg/mod/example.com/version@v1.0.0 | |||
147 | # 'go build' without arguments implicitly operates on the current directory, and should fail. | 147 | # 'go build' without arguments implicitly operates on the current directory, and should fail. |
148 | cd needmod | 148 | cd needmod |
149 | ! go build | 149 | ! go build |
150 | stderr 'cannot find main module' | 150 | stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$' |
151 | cd .. | 151 | cd .. |
152 | 152 | ||
153 | # 'go build' of a non-module directory should fail too. | 153 | # 'go build' of a non-module directory should fail too. |
154 | ! go build ./needmod | 154 | ! go build ./needmod |
155 | stderr 'cannot find main module' | 155 | stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$' |
156 | 156 | ||
157 | # 'go build' of source files should fail if they import anything outside std. | 157 | # 'go build' of source files should fail if they import anything outside std. |
158 | ! go build -n ./needmod/needmod.go | 158 | ! go build -n ./needmod/needmod.go |
159 | stderr '^needmod[/\\]needmod.go:10:2: no required module provides package example.com/version: working directory is not part of a module$' | 159 | stderr '^needmod[/\\]needmod.go:10:2: no required module provides package example.com/version: go.mod file not found in current directory or any parent directory; see ''go help modules''$' |
160 | 160 | ||
161 | # 'go build' of source files should succeed if they do not import anything outside std. | 161 | # 'go build' of source files should succeed if they do not import anything outside std. |
162 | go build -n -o ignore ./stdonly/stdonly.go | 162 | go build -n -o ignore ./stdonly/stdonly.go |
@@ -179,7 +179,7 @@ go doc fmt | |||
179 | 179 | ||
180 | # 'go doc' should fail for a package path outside a module. | 180 | # 'go doc' should fail for a package path outside a module. |
181 | ! go doc example.com/version | 181 | ! go doc example.com/version |
182 | stderr 'doc: no required module provides package example.com/version: working directory is not part of a module' | 182 | stderr 'doc: no required module provides package example.com/version: go.mod file not found in current directory or any parent directory; see ''go help modules''$' |
183 | 183 | ||
184 | # 'go install' with a version should succeed if all constraints are met. | 184 | # 'go install' with a version should succeed if all constraints are met. |
185 | # See mod_install_pkg_version. | 185 | # See mod_install_pkg_version. |
@@ -194,7 +194,7 @@ stderr '^go install: version is required when current directory is not in a modu | |||
194 | # 'go install' should fail if a source file imports a package that must be | 194 | # 'go install' should fail if a source file imports a package that must be |
195 | # resolved to a module. | 195 | # resolved to a module. |
196 | ! go install ./needmod/needmod.go | 196 | ! go install ./needmod/needmod.go |
197 | stderr 'needmod[/\\]needmod.go:10:2: no required module provides package example.com/version: working directory is not part of a module' | 197 | stderr 'needmod[/\\]needmod.go:10:2: no required module provides package example.com/version: go.mod file not found in current directory or any parent directory; see ''go help modules''$' |
198 | 198 | ||
199 | # 'go install' should succeed with a package in GOROOT. | 199 | # 'go install' should succeed with a package in GOROOT. |
200 | go install cmd/addr2line | 200 | go install cmd/addr2line |
@@ -206,12 +206,12 @@ stderr 'can only use path@version syntax with' | |||
206 | 206 | ||
207 | # 'go run' should fail if a package argument must be resolved to a module. | 207 | # 'go run' should fail if a package argument must be resolved to a module. |
208 | ! go run example.com/printversion | 208 | ! go run example.com/printversion |
209 | stderr '^no required module provides package example.com/printversion: working directory is not part of a module$' | 209 | stderr '^no required module provides package example.com/printversion: go.mod file not found in current directory or any parent directory; see ''go help modules''$' |
210 | 210 | ||
211 | # 'go run' should fail if a source file imports a package that must be | 211 | # 'go run' should fail if a source file imports a package that must be |
212 | # resolved to a module. | 212 | # resolved to a module. |
213 | ! go run ./needmod/needmod.go | 213 | ! go run ./needmod/needmod.go |
214 | stderr '^needmod[/\\]needmod.go:10:2: no required module provides package example.com/version: working directory is not part of a module$' | 214 | stderr '^needmod[/\\]needmod.go:10:2: no required module provides package example.com/version: go.mod file not found in current directory or any parent directory; see ''go help modules''$' |
215 | 215 | ||
216 | 216 | ||
217 | # 'go fmt' should be able to format files outside of a module. | 217 | # 'go fmt' should be able to format files outside of a module. |
diff --git a/libgo/go/cmd/go/testdata/script/mod_tidy_error.txt b/libgo/go/cmd/go/testdata/script/mod_tidy_error.txt index b6c24ceaf75..395537b1a71 100644 --- a/libgo/go/cmd/go/testdata/script/mod_tidy_error.txt +++ b/libgo/go/cmd/go/testdata/script/mod_tidy_error.txt | |||
@@ -4,12 +4,12 @@ env GO111MODULE=on | |||
4 | # 'go mod tidy' and 'go mod vendor' should not hide loading errors. | 4 | # 'go mod tidy' and 'go mod vendor' should not hide loading errors. |
5 | 5 | ||
6 | ! go mod tidy | 6 | ! go mod tidy |
7 | stderr '^issue27063 imports\n\tnonexist: package nonexist is not in GOROOT \(.*\)' | 7 | ! stderr 'package nonexist is not in GOROOT' |
8 | stderr '^issue27063 imports\n\tnonexist.example.com: cannot find module providing package nonexist.example.com' | 8 | stderr '^issue27063 imports\n\tnonexist.example.com: cannot find module providing package nonexist.example.com' |
9 | stderr '^issue27063 imports\n\tissue27063/other imports\n\tother.example.com/nonexist: cannot find module providing package other.example.com/nonexist' | 9 | stderr '^issue27063 imports\n\tissue27063/other imports\n\tother.example.com/nonexist: cannot find module providing package other.example.com/nonexist' |
10 | 10 | ||
11 | ! go mod vendor | 11 | ! go mod vendor |
12 | stderr '^issue27063 imports\n\tnonexist: package nonexist is not in GOROOT \(.*\)' | 12 | ! stderr 'package nonexist is not in GOROOT' |
13 | stderr '^issue27063 imports\n\tnonexist.example.com: cannot find module providing package nonexist.example.com' | 13 | stderr '^issue27063 imports\n\tnonexist.example.com: cannot find module providing package nonexist.example.com' |
14 | stderr '^issue27063 imports\n\tissue27063/other imports\n\tother.example.com/nonexist: cannot find module providing package other.example.com/nonexist' | 14 | stderr '^issue27063 imports\n\tissue27063/other imports\n\tother.example.com/nonexist: cannot find module providing package other.example.com/nonexist' |
15 | 15 | ||
diff --git a/libgo/go/cmd/vendor/modules.txt b/libgo/go/cmd/vendor/modules.txt index e033984956b..10842768a88 100644 --- a/libgo/go/cmd/vendor/modules.txt +++ b/libgo/go/cmd/vendor/modules.txt | |||
@@ -28,7 +28,7 @@ golang.org/x/arch/x86/x86asm | |||
28 | golang.org/x/crypto/ed25519 | 28 | golang.org/x/crypto/ed25519 |
29 | golang.org/x/crypto/ed25519/internal/edwards25519 | 29 | golang.org/x/crypto/ed25519/internal/edwards25519 |
30 | golang.org/x/crypto/ssh/terminal | 30 | golang.org/x/crypto/ssh/terminal |
31 | # golang.org/x/mod v0.4.1 | 31 | # golang.org/x/mod v0.4.2-0.20210302225053-d515b24adc21 |
32 | ## explicit | 32 | ## explicit |
33 | golang.org/x/mod/internal/lazyregexp | 33 | golang.org/x/mod/internal/lazyregexp |
34 | golang.org/x/mod/modfile | 34 | golang.org/x/mod/modfile |
diff --git a/libgo/go/encoding/xml/xml.go b/libgo/go/encoding/xml/xml.go index adaf4daf198..6f9594d7ba7 100644 --- a/libgo/go/encoding/xml/xml.go +++ b/libgo/go/encoding/xml/xml.go | |||
@@ -271,7 +271,7 @@ func NewTokenDecoder(t TokenReader) *Decoder { | |||
271 | // it will return an error. | 271 | // it will return an error. |
272 | // | 272 | // |
273 | // Token implements XML name spaces as described by | 273 | // Token implements XML name spaces as described by |
274 | // https://www.w3.org/TR/REC-xml-names/. Each of the | 274 | // https://www.w3.org/TR/REC-xml-names/. Each of the |
275 | // Name structures contained in the Token has the Space | 275 | // Name structures contained in the Token has the Space |
276 | // set to the URL identifying its name space when known. | 276 | // set to the URL identifying its name space when known. |
277 | // If Token encounters an unrecognized name space prefix, | 277 | // If Token encounters an unrecognized name space prefix, |
@@ -285,16 +285,17 @@ func (d *Decoder) Token() (Token, error) { | |||
285 | if d.nextToken != nil { | 285 | if d.nextToken != nil { |
286 | t = d.nextToken | 286 | t = d.nextToken |
287 | d.nextToken = nil | 287 | d.nextToken = nil |
288 | } else if t, err = d.rawToken(); err != nil { | 288 | } else { |
289 | switch { | 289 | if t, err = d.rawToken(); t == nil && err != nil { |
290 | case err == io.EOF && d.t != nil: | 290 | if err == io.EOF && d.stk != nil && d.stk.kind != stkEOF { |
291 | err = nil | 291 | err = d.syntaxError("unexpected EOF") |
292 | case err == io.EOF && d.stk != nil && d.stk.kind != stkEOF: | 292 | } |
293 | err = d.syntaxError("unexpected EOF") | 293 | return nil, err |
294 | } | 294 | } |
295 | return t, err | 295 | // We still have a token to process, so clear any |
296 | // errors (e.g. EOF) and proceed. | ||
297 | err = nil | ||
296 | } | 298 | } |
297 | |||
298 | if !d.Strict { | 299 | if !d.Strict { |
299 | if t1, ok := d.autoClose(t); ok { | 300 | if t1, ok := d.autoClose(t); ok { |
300 | d.nextToken = t | 301 | d.nextToken = t |
diff --git a/libgo/go/encoding/xml/xml_test.go b/libgo/go/encoding/xml/xml_test.go index efddca43e91..5672ebb375f 100644 --- a/libgo/go/encoding/xml/xml_test.go +++ b/libgo/go/encoding/xml/xml_test.go | |||
@@ -33,30 +33,90 @@ func (t *toks) Token() (Token, error) { | |||
33 | 33 | ||
34 | func TestDecodeEOF(t *testing.T) { | 34 | func TestDecodeEOF(t *testing.T) { |
35 | start := StartElement{Name: Name{Local: "test"}} | 35 | start := StartElement{Name: Name{Local: "test"}} |
36 | t.Run("EarlyEOF", func(t *testing.T) { | 36 | tests := []struct { |
37 | d := NewTokenDecoder(&toks{earlyEOF: true, t: []Token{ | 37 | name string |
38 | start, | 38 | tokens []Token |
39 | start.End(), | 39 | ok bool |
40 | }}) | 40 | }{ |
41 | err := d.Decode(&struct { | 41 | { |
42 | XMLName Name `xml:"test"` | 42 | name: "OK", |
43 | }{}) | 43 | tokens: []Token{ |
44 | if err != nil { | 44 | start, |
45 | t.Error(err) | 45 | start.End(), |
46 | }, | ||
47 | ok: true, | ||
48 | }, | ||
49 | { | ||
50 | name: "Malformed", | ||
51 | tokens: []Token{ | ||
52 | start, | ||
53 | StartElement{Name: Name{Local: "bad"}}, | ||
54 | start.End(), | ||
55 | }, | ||
56 | ok: false, | ||
57 | }, | ||
58 | } | ||
59 | for _, tc := range tests { | ||
60 | for _, eof := range []bool{true, false} { | ||
61 | name := fmt.Sprintf("%s/earlyEOF=%v", tc.name, eof) | ||
62 | t.Run(name, func(t *testing.T) { | ||
63 | d := NewTokenDecoder(&toks{ | ||
64 | earlyEOF: eof, | ||
65 | t: tc.tokens, | ||
66 | }) | ||
67 | err := d.Decode(&struct { | ||
68 | XMLName Name `xml:"test"` | ||
69 | }{}) | ||
70 | if tc.ok && err != nil { | ||
71 | t.Fatalf("d.Decode: expected nil error, got %v", err) | ||
72 | } | ||
73 | if _, ok := err.(*SyntaxError); !tc.ok && !ok { | ||
74 | t.Errorf("d.Decode: expected syntax error, got %v", err) | ||
75 | } | ||
76 | }) | ||
46 | } | 77 | } |
47 | }) | 78 | } |
48 | t.Run("LateEOF", func(t *testing.T) { | 79 | } |
49 | d := NewTokenDecoder(&toks{t: []Token{ | 80 | |
50 | start, | 81 | type toksNil struct { |
51 | start.End(), | 82 | returnEOF bool |
52 | }}) | 83 | t []Token |
53 | err := d.Decode(&struct { | 84 | } |
54 | XMLName Name `xml:"test"` | 85 | |
55 | }{}) | 86 | func (t *toksNil) Token() (Token, error) { |
56 | if err != nil { | 87 | if len(t.t) == 0 { |
57 | t.Error(err) | 88 | if !t.returnEOF { |
89 | // Return nil, nil before returning an EOF. It's legal, but | ||
90 | // discouraged. | ||
91 | t.returnEOF = true | ||
92 | return nil, nil | ||
58 | } | 93 | } |
59 | }) | 94 | return nil, io.EOF |
95 | } | ||
96 | var tok Token | ||
97 | tok, t.t = t.t[0], t.t[1:] | ||
98 | return tok, nil | ||
99 | } | ||
100 | |||
101 | func TestDecodeNilToken(t *testing.T) { | ||
102 | for _, strict := range []bool{true, false} { | ||
103 | name := fmt.Sprintf("Strict=%v", strict) | ||
104 | t.Run(name, func(t *testing.T) { | ||
105 | start := StartElement{Name: Name{Local: "test"}} | ||
106 | bad := StartElement{Name: Name{Local: "bad"}} | ||
107 | d := NewTokenDecoder(&toksNil{ | ||
108 | // Malformed | ||
109 | t: []Token{start, bad, start.End()}, | ||
110 | }) | ||
111 | d.Strict = strict | ||
112 | err := d.Decode(&struct { | ||
113 | XMLName Name `xml:"test"` | ||
114 | }{}) | ||
115 | if _, ok := err.(*SyntaxError); !ok { | ||
116 | t.Errorf("d.Decode: expected syntax error, got %v", err) | ||
117 | } | ||
118 | }) | ||
119 | } | ||
60 | } | 120 | } |
61 | 121 | ||
62 | const testInput = ` | 122 | const testInput = ` |
diff --git a/libgo/go/go/build/build_test.go b/libgo/go/go/build/build_test.go index 490c212642c..1c0dc4692c9 100644 --- a/libgo/go/go/build/build_test.go +++ b/libgo/go/go/build/build_test.go | |||
@@ -614,7 +614,7 @@ func TestImportPackageOutsideModule(t *testing.T) { | |||
614 | ctxt.GOPATH = gopath | 614 | ctxt.GOPATH = gopath |
615 | ctxt.Dir = filepath.Join(gopath, "src/example.com/p") | 615 | ctxt.Dir = filepath.Join(gopath, "src/example.com/p") |
616 | 616 | ||
617 | want := "working directory is not part of a module" | 617 | want := "go.mod file not found in current directory or any parent directory" |
618 | if _, err := ctxt.Import("example.com/p", gopath, FindOnly); err == nil { | 618 | if _, err := ctxt.Import("example.com/p", gopath, FindOnly); err == nil { |
619 | t.Fatal("importing package when no go.mod is present succeeded unexpectedly") | 619 | t.Fatal("importing package when no go.mod is present succeeded unexpectedly") |
620 | } else if errStr := err.Error(); !strings.Contains(errStr, want) { | 620 | } else if errStr := err.Error(); !strings.Contains(errStr, want) { |
diff --git a/libgo/go/golang.org/x/mod/modfile/rule.go b/libgo/go/golang.org/x/mod/modfile/rule.go index c6a189dbe04..f8c93849859 100644 --- a/libgo/go/golang.org/x/mod/modfile/rule.go +++ b/libgo/go/golang.org/x/mod/modfile/rule.go | |||
@@ -125,6 +125,12 @@ func (f *File) AddComment(text string) { | |||
125 | 125 | ||
126 | type VersionFixer func(path, version string) (string, error) | 126 | type VersionFixer func(path, version string) (string, error) |
127 | 127 | ||
128 | // errDontFix is returned by a VersionFixer to indicate the version should be | ||
129 | // left alone, even if it's not canonical. | ||
130 | var dontFixRetract VersionFixer = func(_, vers string) (string, error) { | ||
131 | return vers, nil | ||
132 | } | ||
133 | |||
128 | // Parse parses the data, reported in errors as being from file, | 134 | // Parse parses the data, reported in errors as being from file, |
129 | // into a File struct. It applies fix, if non-nil, to canonicalize all module versions found. | 135 | // into a File struct. It applies fix, if non-nil, to canonicalize all module versions found. |
130 | func Parse(file string, data []byte, fix VersionFixer) (*File, error) { | 136 | func Parse(file string, data []byte, fix VersionFixer) (*File, error) { |
@@ -142,7 +148,7 @@ func ParseLax(file string, data []byte, fix VersionFixer) (*File, error) { | |||
142 | return parseToFile(file, data, fix, false) | 148 | return parseToFile(file, data, fix, false) |
143 | } | 149 | } |
144 | 150 | ||
145 | func parseToFile(file string, data []byte, fix VersionFixer, strict bool) (*File, error) { | 151 | func parseToFile(file string, data []byte, fix VersionFixer, strict bool) (parsed *File, err error) { |
146 | fs, err := parse(file, data) | 152 | fs, err := parse(file, data) |
147 | if err != nil { | 153 | if err != nil { |
148 | return nil, err | 154 | return nil, err |
@@ -150,8 +156,18 @@ func parseToFile(file string, data []byte, fix VersionFixer, strict bool) (*File | |||
150 | f := &File{ | 156 | f := &File{ |
151 | Syntax: fs, | 157 | Syntax: fs, |
152 | } | 158 | } |
153 | |||
154 | var errs ErrorList | 159 | var errs ErrorList |
160 | |||
161 | // fix versions in retract directives after the file is parsed. | ||
162 | // We need the module path to fix versions, and it might be at the end. | ||
163 | defer func() { | ||
164 | oldLen := len(errs) | ||
165 | f.fixRetract(fix, &errs) | ||
166 | if len(errs) > oldLen { | ||
167 | parsed, err = nil, errs | ||
168 | } | ||
169 | }() | ||
170 | |||
155 | for _, x := range fs.Stmt { | 171 | for _, x := range fs.Stmt { |
156 | switch x := x.(type) { | 172 | switch x := x.(type) { |
157 | case *Line: | 173 | case *Line: |
@@ -370,7 +386,7 @@ func (f *File) add(errs *ErrorList, block *LineBlock, line *Line, verb string, a | |||
370 | 386 | ||
371 | case "retract": | 387 | case "retract": |
372 | rationale := parseRetractRationale(block, line) | 388 | rationale := parseRetractRationale(block, line) |
373 | vi, err := parseVersionInterval(verb, &args, fix) | 389 | vi, err := parseVersionInterval(verb, "", &args, dontFixRetract) |
374 | if err != nil { | 390 | if err != nil { |
375 | if strict { | 391 | if strict { |
376 | wrapError(err) | 392 | wrapError(err) |
@@ -397,6 +413,47 @@ func (f *File) add(errs *ErrorList, block *LineBlock, line *Line, verb string, a | |||
397 | } | 413 | } |
398 | } | 414 | } |
399 | 415 | ||
416 | // fixRetract applies fix to each retract directive in f, appending any errors | ||
417 | // to errs. | ||
418 | // | ||
419 | // Most versions are fixed as we parse the file, but for retract directives, | ||
420 | // the relevant module path is the one specified with the module directive, | ||
421 | // and that might appear at the end of the file (or not at all). | ||
422 | func (f *File) fixRetract(fix VersionFixer, errs *ErrorList) { | ||
423 | if fix == nil { | ||
424 | return | ||
425 | } | ||
426 | path := "" | ||
427 | if f.Module != nil { | ||
428 | path = f.Module.Mod.Path | ||
429 | } | ||
430 | var r *Retract | ||
431 | wrapError := func(err error) { | ||
432 | *errs = append(*errs, Error{ | ||
433 | Filename: f.Syntax.Name, | ||
434 | Pos: r.Syntax.Start, | ||
435 | Err: err, | ||
436 | }) | ||
437 | } | ||
438 | |||
439 | for _, r = range f.Retract { | ||
440 | if path == "" { | ||
441 | wrapError(errors.New("no module directive found, so retract cannot be used")) | ||
442 | return // only print the first one of these | ||
443 | } | ||
444 | |||
445 | args := r.Syntax.Token | ||
446 | if args[0] == "retract" { | ||
447 | args = args[1:] | ||
448 | } | ||
449 | vi, err := parseVersionInterval("retract", path, &args, fix) | ||
450 | if err != nil { | ||
451 | wrapError(err) | ||
452 | } | ||
453 | r.VersionInterval = vi | ||
454 | } | ||
455 | } | ||
456 | |||
400 | // isIndirect reports whether line has a "// indirect" comment, | 457 | // isIndirect reports whether line has a "// indirect" comment, |
401 | // meaning it is in go.mod only for its effect on indirect dependencies, | 458 | // meaning it is in go.mod only for its effect on indirect dependencies, |
402 | // so that it can be dropped entirely once the effective version of the | 459 | // so that it can be dropped entirely once the effective version of the |
@@ -491,13 +548,13 @@ func AutoQuote(s string) string { | |||
491 | return s | 548 | return s |
492 | } | 549 | } |
493 | 550 | ||
494 | func parseVersionInterval(verb string, args *[]string, fix VersionFixer) (VersionInterval, error) { | 551 | func parseVersionInterval(verb string, path string, args *[]string, fix VersionFixer) (VersionInterval, error) { |
495 | toks := *args | 552 | toks := *args |
496 | if len(toks) == 0 || toks[0] == "(" { | 553 | if len(toks) == 0 || toks[0] == "(" { |
497 | return VersionInterval{}, fmt.Errorf("expected '[' or version") | 554 | return VersionInterval{}, fmt.Errorf("expected '[' or version") |
498 | } | 555 | } |
499 | if toks[0] != "[" { | 556 | if toks[0] != "[" { |
500 | v, err := parseVersion(verb, "", &toks[0], fix) | 557 | v, err := parseVersion(verb, path, &toks[0], fix) |
501 | if err != nil { | 558 | if err != nil { |
502 | return VersionInterval{}, err | 559 | return VersionInterval{}, err |
503 | } | 560 | } |
@@ -509,7 +566,7 @@ func parseVersionInterval(verb string, args *[]string, fix VersionFixer) (Versio | |||
509 | if len(toks) == 0 { | 566 | if len(toks) == 0 { |
510 | return VersionInterval{}, fmt.Errorf("expected version after '['") | 567 | return VersionInterval{}, fmt.Errorf("expected version after '['") |
511 | } | 568 | } |
512 | low, err := parseVersion(verb, "", &toks[0], fix) | 569 | low, err := parseVersion(verb, path, &toks[0], fix) |
513 | if err != nil { | 570 | if err != nil { |
514 | return VersionInterval{}, err | 571 | return VersionInterval{}, err |
515 | } | 572 | } |
@@ -523,7 +580,7 @@ func parseVersionInterval(verb string, args *[]string, fix VersionFixer) (Versio | |||
523 | if len(toks) == 0 { | 580 | if len(toks) == 0 { |
524 | return VersionInterval{}, fmt.Errorf("expected version after ','") | 581 | return VersionInterval{}, fmt.Errorf("expected version after ','") |
525 | } | 582 | } |
526 | high, err := parseVersion(verb, "", &toks[0], fix) | 583 | high, err := parseVersion(verb, path, &toks[0], fix) |
527 | if err != nil { | 584 | if err != nil { |
528 | return VersionInterval{}, err | 585 | return VersionInterval{}, err |
529 | } | 586 | } |
@@ -631,8 +688,7 @@ func parseVersion(verb string, path string, s *string, fix VersionFixer) (string | |||
631 | } | 688 | } |
632 | } | 689 | } |
633 | if fix != nil { | 690 | if fix != nil { |
634 | var err error | 691 | fixed, err := fix(path, t) |
635 | t, err = fix(path, t) | ||
636 | if err != nil { | 692 | if err != nil { |
637 | if err, ok := err.(*module.ModuleError); ok { | 693 | if err, ok := err.(*module.ModuleError); ok { |
638 | return "", &Error{ | 694 | return "", &Error{ |
@@ -643,19 +699,23 @@ func parseVersion(verb string, path string, s *string, fix VersionFixer) (string | |||
643 | } | 699 | } |
644 | return "", err | 700 | return "", err |
645 | } | 701 | } |
702 | t = fixed | ||
703 | } else { | ||
704 | cv := module.CanonicalVersion(t) | ||
705 | if cv == "" { | ||
706 | return "", &Error{ | ||
707 | Verb: verb, | ||
708 | ModPath: path, | ||
709 | Err: &module.InvalidVersionError{ | ||
710 | Version: t, | ||
711 | Err: errors.New("must be of the form v1.2.3"), | ||
712 | }, | ||
713 | } | ||
714 | } | ||
715 | t = cv | ||
646 | } | 716 | } |
647 | if v := module.CanonicalVersion(t); v != "" { | 717 | *s = t |
648 | *s = v | 718 | return *s, nil |
649 | return *s, nil | ||
650 | } | ||
651 | return "", &Error{ | ||
652 | Verb: verb, | ||
653 | ModPath: path, | ||
654 | Err: &module.InvalidVersionError{ | ||
655 | Version: t, | ||
656 | Err: errors.New("must be of the form v1.2.3"), | ||
657 | }, | ||
658 | } | ||
659 | } | 719 | } |
660 | 720 | ||
661 | func modulePathMajor(path string) (string, error) { | 721 | func modulePathMajor(path string) (string, error) { |
@@ -835,11 +895,8 @@ func (f *File) DropRequire(path string) error { | |||
835 | // AddExclude adds a exclude statement to the mod file. Errors if the provided | 895 | // AddExclude adds a exclude statement to the mod file. Errors if the provided |
836 | // version is not a canonical version string | 896 | // version is not a canonical version string |
837 | func (f *File) AddExclude(path, vers string) error { | 897 | func (f *File) AddExclude(path, vers string) error { |
838 | if !isCanonicalVersion(vers) { | 898 | if err := checkCanonicalVersion(path, vers); err != nil { |
839 | return &module.InvalidVersionError{ | 899 | return err |
840 | Version: vers, | ||
841 | Err: errors.New("must be of the form v1.2.3"), | ||
842 | } | ||
843 | } | 900 | } |
844 | 901 | ||
845 | var hint *Line | 902 | var hint *Line |
@@ -916,17 +973,15 @@ func (f *File) DropReplace(oldPath, oldVers string) error { | |||
916 | // AddRetract adds a retract statement to the mod file. Errors if the provided | 973 | // AddRetract adds a retract statement to the mod file. Errors if the provided |
917 | // version interval does not consist of canonical version strings | 974 | // version interval does not consist of canonical version strings |
918 | func (f *File) AddRetract(vi VersionInterval, rationale string) error { | 975 | func (f *File) AddRetract(vi VersionInterval, rationale string) error { |
919 | if !isCanonicalVersion(vi.High) { | 976 | var path string |
920 | return &module.InvalidVersionError{ | 977 | if f.Module != nil { |
921 | Version: vi.High, | 978 | path = f.Module.Mod.Path |
922 | Err: errors.New("must be of the form v1.2.3"), | ||
923 | } | ||
924 | } | 979 | } |
925 | if !isCanonicalVersion(vi.Low) { | 980 | if err := checkCanonicalVersion(path, vi.High); err != nil { |
926 | return &module.InvalidVersionError{ | 981 | return err |
927 | Version: vi.Low, | 982 | } |
928 | Err: errors.New("must be of the form v1.2.3"), | 983 | if err := checkCanonicalVersion(path, vi.Low); err != nil { |
929 | } | 984 | return err |
930 | } | 985 | } |
931 | 986 | ||
932 | r := &Retract{ | 987 | r := &Retract{ |
@@ -1086,8 +1141,40 @@ func lineRetractLess(li, lj *Line) bool { | |||
1086 | return semver.Compare(vii.High, vij.High) > 0 | 1141 | return semver.Compare(vii.High, vij.High) > 0 |
1087 | } | 1142 | } |
1088 | 1143 | ||
1089 | // isCanonicalVersion tests if the provided version string represents a valid | 1144 | // checkCanonicalVersion returns a non-nil error if vers is not a canonical |
1090 | // canonical version. | 1145 | // version string or does not match the major version of path. |
1091 | func isCanonicalVersion(vers string) bool { | 1146 | // |
1092 | return vers != "" && semver.Canonical(vers) == vers | 1147 | // If path is non-empty, the error text suggests a format with a major version |
1148 | // corresponding to the path. | ||
1149 | func checkCanonicalVersion(path, vers string) error { | ||
1150 | _, pathMajor, pathMajorOk := module.SplitPathVersion(path) | ||
1151 | |||
1152 | if vers == "" || vers != module.CanonicalVersion(vers) { | ||
1153 | if pathMajor == "" { | ||
1154 | return &module.InvalidVersionError{ | ||
1155 | Version: vers, | ||
1156 | Err: fmt.Errorf("must be of the form v1.2.3"), | ||
1157 | } | ||
1158 | } | ||
1159 | return &module.InvalidVersionError{ | ||
1160 | Version: vers, | ||
1161 | Err: fmt.Errorf("must be of the form %s.2.3", module.PathMajorPrefix(pathMajor)), | ||
1162 | } | ||
1163 | } | ||
1164 | |||
1165 | if pathMajorOk { | ||
1166 | if err := module.CheckPathMajor(vers, pathMajor); err != nil { | ||
1167 | if pathMajor == "" { | ||
1168 | // In this context, the user probably wrote "v2.3.4" when they meant | ||
1169 | // "v2.3.4+incompatible". Suggest that instead of "v0 or v1". | ||
1170 | return &module.InvalidVersionError{ | ||
1171 | Version: vers, | ||
1172 | Err: fmt.Errorf("should be %s+incompatible (or module %s/%v)", vers, path, semver.Major(vers)), | ||
1173 | } | ||
1174 | } | ||
1175 | return err | ||
1176 | } | ||
1177 | } | ||
1178 | |||
1179 | return nil | ||
1093 | } | 1180 | } |
diff --git a/libgo/go/golang.org/x/mod/module/module.go b/libgo/go/golang.org/x/mod/module/module.go index c1c5263c427..272baeef176 100644 --- a/libgo/go/golang.org/x/mod/module/module.go +++ b/libgo/go/golang.org/x/mod/module/module.go | |||
@@ -270,7 +270,7 @@ func fileNameOK(r rune) bool { | |||
270 | 270 | ||
271 | // CheckPath checks that a module path is valid. | 271 | // CheckPath checks that a module path is valid. |
272 | // A valid module path is a valid import path, as checked by CheckImportPath, | 272 | // A valid module path is a valid import path, as checked by CheckImportPath, |
273 | // with two additional constraints. | 273 | // with three additional constraints. |
274 | // First, the leading path element (up to the first slash, if any), | 274 | // First, the leading path element (up to the first slash, if any), |
275 | // by convention a domain name, must contain only lower-case ASCII letters, | 275 | // by convention a domain name, must contain only lower-case ASCII letters, |
276 | // ASCII digits, dots (U+002E), and dashes (U+002D); | 276 | // ASCII digits, dots (U+002E), and dashes (U+002D); |
@@ -280,8 +280,9 @@ func fileNameOK(r rune) bool { | |||
280 | // and must not contain any dots. For paths beginning with "gopkg.in/", | 280 | // and must not contain any dots. For paths beginning with "gopkg.in/", |
281 | // this second requirement is replaced by a requirement that the path | 281 | // this second requirement is replaced by a requirement that the path |
282 | // follow the gopkg.in server's conventions. | 282 | // follow the gopkg.in server's conventions. |
283 | // Third, no path element may begin with a dot. | ||
283 | func CheckPath(path string) error { | 284 | func CheckPath(path string) error { |
284 | if err := checkPath(path, false); err != nil { | 285 | if err := checkPath(path, modulePath); err != nil { |
285 | return fmt.Errorf("malformed module path %q: %v", path, err) | 286 | return fmt.Errorf("malformed module path %q: %v", path, err) |
286 | } | 287 | } |
287 | i := strings.Index(path, "/") | 288 | i := strings.Index(path, "/") |
@@ -315,7 +316,7 @@ func CheckPath(path string) error { | |||
315 | // | 316 | // |
316 | // A valid path element is a non-empty string made up of | 317 | // A valid path element is a non-empty string made up of |
317 | // ASCII letters, ASCII digits, and limited ASCII punctuation: - . _ and ~. | 318 | // ASCII letters, ASCII digits, and limited ASCII punctuation: - . _ and ~. |
318 | // It must not begin or end with a dot (U+002E), nor contain two dots in a row. | 319 | // It must not end with a dot (U+002E), nor contain two dots in a row. |
319 | // | 320 | // |
320 | // The element prefix up to the first dot must not be a reserved file name | 321 | // The element prefix up to the first dot must not be a reserved file name |
321 | // on Windows, regardless of case (CON, com1, NuL, and so on). The element | 322 | // on Windows, regardless of case (CON, com1, NuL, and so on). The element |
@@ -326,19 +327,29 @@ func CheckPath(path string) error { | |||
326 | // top-level package documentation for additional information about | 327 | // top-level package documentation for additional information about |
327 | // subtleties of Unicode. | 328 | // subtleties of Unicode. |
328 | func CheckImportPath(path string) error { | 329 | func CheckImportPath(path string) error { |
329 | if err := checkPath(path, false); err != nil { | 330 | if err := checkPath(path, importPath); err != nil { |
330 | return fmt.Errorf("malformed import path %q: %v", path, err) | 331 | return fmt.Errorf("malformed import path %q: %v", path, err) |
331 | } | 332 | } |
332 | return nil | 333 | return nil |
333 | } | 334 | } |
334 | 335 | ||
336 | // pathKind indicates what kind of path we're checking. Module paths, | ||
337 | // import paths, and file paths have different restrictions. | ||
338 | type pathKind int | ||
339 | |||
340 | const ( | ||
341 | modulePath pathKind = iota | ||
342 | importPath | ||
343 | filePath | ||
344 | ) | ||
345 | |||
335 | // checkPath checks that a general path is valid. | 346 | // checkPath checks that a general path is valid. |
336 | // It returns an error describing why but not mentioning path. | 347 | // It returns an error describing why but not mentioning path. |
337 | // Because these checks apply to both module paths and import paths, | 348 | // Because these checks apply to both module paths and import paths, |
338 | // the caller is expected to add the "malformed ___ path %q: " prefix. | 349 | // the caller is expected to add the "malformed ___ path %q: " prefix. |
339 | // fileName indicates whether the final element of the path is a file name | 350 | // fileName indicates whether the final element of the path is a file name |
340 | // (as opposed to a directory name). | 351 | // (as opposed to a directory name). |
341 | func checkPath(path string, fileName bool) error { | 352 | func checkPath(path string, kind pathKind) error { |
342 | if !utf8.ValidString(path) { | 353 | if !utf8.ValidString(path) { |
343 | return fmt.Errorf("invalid UTF-8") | 354 | return fmt.Errorf("invalid UTF-8") |
344 | } | 355 | } |
@@ -357,35 +368,34 @@ func checkPath(path string, fileName bool) error { | |||
357 | elemStart := 0 | 368 | elemStart := 0 |
358 | for i, r := range path { | 369 | for i, r := range path { |
359 | if r == '/' { | 370 | if r == '/' { |
360 | if err := checkElem(path[elemStart:i], fileName); err != nil { | 371 | if err := checkElem(path[elemStart:i], kind); err != nil { |
361 | return err | 372 | return err |
362 | } | 373 | } |
363 | elemStart = i + 1 | 374 | elemStart = i + 1 |
364 | } | 375 | } |
365 | } | 376 | } |
366 | if err := checkElem(path[elemStart:], fileName); err != nil { | 377 | if err := checkElem(path[elemStart:], kind); err != nil { |
367 | return err | 378 | return err |
368 | } | 379 | } |
369 | return nil | 380 | return nil |
370 | } | 381 | } |
371 | 382 | ||
372 | // checkElem checks whether an individual path element is valid. | 383 | // checkElem checks whether an individual path element is valid. |
373 | // fileName indicates whether the element is a file name (not a directory name). | 384 | func checkElem(elem string, kind pathKind) error { |
374 | func checkElem(elem string, fileName bool) error { | ||
375 | if elem == "" { | 385 | if elem == "" { |
376 | return fmt.Errorf("empty path element") | 386 | return fmt.Errorf("empty path element") |
377 | } | 387 | } |
378 | if strings.Count(elem, ".") == len(elem) { | 388 | if strings.Count(elem, ".") == len(elem) { |
379 | return fmt.Errorf("invalid path element %q", elem) | 389 | return fmt.Errorf("invalid path element %q", elem) |
380 | } | 390 | } |
381 | if elem[0] == '.' && !fileName { | 391 | if elem[0] == '.' && kind == modulePath { |
382 | return fmt.Errorf("leading dot in path element") | 392 | return fmt.Errorf("leading dot in path element") |
383 | } | 393 | } |
384 | if elem[len(elem)-1] == '.' { | 394 | if elem[len(elem)-1] == '.' { |
385 | return fmt.Errorf("trailing dot in path element") | 395 | return fmt.Errorf("trailing dot in path element") |
386 | } | 396 | } |
387 | charOK := pathOK | 397 | charOK := pathOK |
388 | if fileName { | 398 | if kind == filePath { |
389 | charOK = fileNameOK | 399 | charOK = fileNameOK |
390 | } | 400 | } |
391 | for _, r := range elem { | 401 | for _, r := range elem { |
@@ -406,7 +416,7 @@ func checkElem(elem string, fileName bool) error { | |||
406 | } | 416 | } |
407 | } | 417 | } |
408 | 418 | ||
409 | if fileName { | 419 | if kind == filePath { |
410 | // don't check for Windows short-names in file names. They're | 420 | // don't check for Windows short-names in file names. They're |
411 | // only an issue for import paths. | 421 | // only an issue for import paths. |
412 | return nil | 422 | return nil |
@@ -444,7 +454,7 @@ func checkElem(elem string, fileName bool) error { | |||
444 | // top-level package documentation for additional information about | 454 | // top-level package documentation for additional information about |
445 | // subtleties of Unicode. | 455 | // subtleties of Unicode. |
446 | func CheckFilePath(path string) error { | 456 | func CheckFilePath(path string) error { |
447 | if err := checkPath(path, true); err != nil { | 457 | if err := checkPath(path, filePath); err != nil { |
448 | return fmt.Errorf("malformed file path %q: %v", path, err) | 458 | return fmt.Errorf("malformed file path %q: %v", path, err) |
449 | } | 459 | } |
450 | return nil | 460 | return nil |
@@ -647,7 +657,7 @@ func EscapePath(path string) (escaped string, err error) { | |||
647 | // Versions are allowed to be in non-semver form but must be valid file names | 657 | // Versions are allowed to be in non-semver form but must be valid file names |
648 | // and not contain exclamation marks. | 658 | // and not contain exclamation marks. |
649 | func EscapeVersion(v string) (escaped string, err error) { | 659 | func EscapeVersion(v string) (escaped string, err error) { |
650 | if err := checkElem(v, true); err != nil || strings.Contains(v, "!") { | 660 | if err := checkElem(v, filePath); err != nil || strings.Contains(v, "!") { |
651 | return "", &InvalidVersionError{ | 661 | return "", &InvalidVersionError{ |
652 | Version: v, | 662 | Version: v, |
653 | Err: fmt.Errorf("disallowed version string"), | 663 | Err: fmt.Errorf("disallowed version string"), |
@@ -706,7 +716,7 @@ func UnescapeVersion(escaped string) (v string, err error) { | |||
706 | if !ok { | 716 | if !ok { |
707 | return "", fmt.Errorf("invalid escaped version %q", escaped) | 717 | return "", fmt.Errorf("invalid escaped version %q", escaped) |
708 | } | 718 | } |
709 | if err := checkElem(v, true); err != nil { | 719 | if err := checkElem(v, filePath); err != nil { |
710 | return "", fmt.Errorf("invalid escaped version %q: %v", v, err) | 720 | return "", fmt.Errorf("invalid escaped version %q: %v", v, err) |
711 | } | 721 | } |
712 | return v, nil | 722 | return v, nil |
diff --git a/libgo/go/time/zoneinfo.go b/libgo/go/time/zoneinfo.go index c3662297c7d..6db94434747 100644 --- a/libgo/go/time/zoneinfo.go +++ b/libgo/go/time/zoneinfo.go | |||
@@ -377,8 +377,10 @@ func tzsetOffset(s string) (offset int, rest string, ok bool) { | |||
377 | neg = true | 377 | neg = true |
378 | } | 378 | } |
379 | 379 | ||
380 | // The tzdata code permits values up to 24 * 7 here, | ||
381 | // although POSIX does not. | ||
380 | var hours int | 382 | var hours int |
381 | hours, s, ok = tzsetNum(s, 0, 24) | 383 | hours, s, ok = tzsetNum(s, 0, 24*7) |
382 | if !ok { | 384 | if !ok { |
383 | return 0, "", false | 385 | return 0, "", false |
384 | } | 386 | } |
@@ -487,7 +489,7 @@ func tzsetRule(s string) (rule, string, bool) { | |||
487 | } | 489 | } |
488 | 490 | ||
489 | offset, s, ok := tzsetOffset(s[1:]) | 491 | offset, s, ok := tzsetOffset(s[1:]) |
490 | if !ok || offset < 0 { | 492 | if !ok { |
491 | return rule{}, "", false | 493 | return rule{}, "", false |
492 | } | 494 | } |
493 | r.time = offset | 495 | r.time = offset |
diff --git a/libgo/go/time/zoneinfo_test.go b/libgo/go/time/zoneinfo_test.go index d543f93e3b7..3e32da02b2e 100644 --- a/libgo/go/time/zoneinfo_test.go +++ b/libgo/go/time/zoneinfo_test.go | |||
@@ -189,22 +189,50 @@ func TestMalformedTZData(t *testing.T) { | |||
189 | } | 189 | } |
190 | } | 190 | } |
191 | 191 | ||
192 | func TestLoadLocationFromTZDataSlim(t *testing.T) { | 192 | var slimTests = []struct { |
193 | // A 2020b slim tzdata for Europe/Berlin | 193 | zoneName string |
194 | tzData := "TZif2\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00TZif2\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00<\x00\x00\x00\x04\x00\x00\x00\x12\xff\xff\xff\xffo\xa2a\xf8\xff\xff\xff\xff\x9b\f\x17`\xff\xff\xff\xff\x9b\xd5\xda\xf0\xff\xff\xff\xff\x9cٮ\x90\xff\xff\xff\xff\x9d\xa4\xb5\x90\xff\xff\xff\xff\x9e\xb9\x90\x90\xff\xff\xff\xff\x9f\x84\x97\x90\xff\xff\xff\xff\xc8\tq\x90\xff\xff\xff\xff\xcc\xe7K\x10\xff\xff\xff\xffͩ\x17\x90\xff\xff\xff\xff\u03a2C\x10\xff\xff\xff\xffϒ4\x10\xff\xff\xff\xffЂ%\x10\xff\xff\xff\xff\xd1r\x16\x10\xff\xff\xff\xffѶ\x96\x00\xff\xff\xff\xff\xd2X\xbe\x80\xff\xff\xff\xffҡO\x10\xff\xff\xff\xff\xd3c\x1b\x90\xff\xff\xff\xff\xd4K#\x90\xff\xff\xff\xff\xd59\xd1 \xff\xff\xff\xff\xd5g\xe7\x90\xff\xff\xff\xffըs\x00\xff\xff\xff\xff\xd6)\xb4\x10\xff\xff\xff\xff\xd7,\x1a\x10\xff\xff\xff\xff\xd8\t\x96\x10\xff\xff\xff\xff\xd9\x02\xc1\x90\xff\xff\xff\xff\xd9\xe9x\x10\x00\x00\x00\x00\x13MD\x10\x00\x00\x00\x00\x143\xfa\x90\x00\x00\x00\x00\x15#\xeb\x90\x00\x00\x00\x00\x16\x13ܐ\x00\x00\x00\x00\x17\x03͐\x00\x00\x00\x00\x17\xf3\xbe\x90\x00\x00\x00\x00\x18㯐\x00\x00\x00\x00\x19Ӡ\x90\x00\x00\x00\x00\x1aÑ\x90\x00\x00\x00\x00\x1b\xbc\xbd\x10\x00\x00\x00\x00\x1c\xac\xae\x10\x00\x00\x00\x00\x1d\x9c\x9f\x10\x00\x00\x00\x00\x1e\x8c\x90\x10\x00\x00\x00\x00\x1f|\x81\x10\x00\x00\x00\x00 lr\x10\x00\x00\x00\x00!\\c\x10\x00\x00\x00\x00\"LT\x10\x00\x00\x00\x00#<E\x10\x00\x00\x00\x00$,6\x10\x00\x00\x00\x00%\x1c'\x10\x00\x00\x00\x00&\f\x18\x10\x00\x00\x00\x00'\x05C\x90\x00\x00\x00\x00'\xf54\x90\x00\x00\x00\x00(\xe5%\x90\x00\x00\x00\x00)\xd5\x16\x90\x00\x00\x00\x00*\xc5\a\x90\x00\x00\x00\x00+\xb4\xf8\x90\x00\x00\x00\x00,\xa4\xe9\x90\x00\x00\x00\x00-\x94ڐ\x00\x00\x00\x00.\x84ː\x00\x00\x00\x00/t\xbc\x90\x00\x00\x00\x000d\xad\x90\x00\x00\x00\x001]\xd9\x10\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x03\x01\x02\x01\x02\x01\x03\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x00\x00\f\x88\x00\x00\x00\x00\x1c \x01\x04\x00\x00\x0e\x10\x00\t\x00\x00*0\x01\rLMT\x00CEST\x00CET\x00CEMT\x00\nCET-1CEST,M3.5.0,M10.5.0/3\n" | 194 | tzData string |
195 | wantName string | ||
196 | wantOffset int | ||
197 | }{ | ||
198 | { | ||
199 | // 2020b slim tzdata for Europe/Berlin. | ||
200 | zoneName: "Europe/Berlin", | ||
201 | tzData: "TZif2\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00TZif2\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00<\x00\x00\x00\x04\x00\x00\x00\x12\xff\xff\xff\xffo\xa2a\xf8\xff\xff\xff\xff\x9b\f\x17`\xff\xff\xff\xff\x9b\xd5\xda\xf0\xff\xff\xff\xff\x9cٮ\x90\xff\xff\xff\xff\x9d\xa4\xb5\x90\xff\xff\xff\xff\x9e\xb9\x90\x90\xff\xff\xff\xff\x9f\x84\x97\x90\xff\xff\xff\xff\xc8\tq\x90\xff\xff\xff\xff\xcc\xe7K\x10\xff\xff\xff\xffͩ\x17\x90\xff\xff\xff\xff\u03a2C\x10\xff\xff\xff\xffϒ4\x10\xff\xff\xff\xffЂ%\x10\xff\xff\xff\xff\xd1r\x16\x10\xff\xff\xff\xffѶ\x96\x00\xff\xff\xff\xff\xd2X\xbe\x80\xff\xff\xff\xffҡO\x10\xff\xff\xff\xff\xd3c\x1b\x90\xff\xff\xff\xff\xd4K#\x90\xff\xff\xff\xff\xd59\xd1 \xff\xff\xff\xff\xd5g\xe7\x90\xff\xff\xff\xffըs\x00\xff\xff\xff\xff\xd6)\xb4\x10\xff\xff\xff\xff\xd7,\x1a\x10\xff\xff\xff\xff\xd8\t\x96\x10\xff\xff\xff\xff\xd9\x02\xc1\x90\xff\xff\xff\xff\xd9\xe9x\x10\x00\x00\x00\x00\x13MD\x10\x00\x00\x00\x00\x143\xfa\x90\x00\x00\x00\x00\x15#\xeb\x90\x00\x00\x00\x00\x16\x13ܐ\x00\x00\x00\x00\x17\x03͐\x00\x00\x00\x00\x17\xf3\xbe\x90\x00\x00\x00\x00\x18㯐\x00\x00\x00\x00\x19Ӡ\x90\x00\x00\x00\x00\x1aÑ\x90\x00\x00\x00\x00\x1b\xbc\xbd\x10\x00\x00\x00\x00\x1c\xac\xae\x10\x00\x00\x00\x00\x1d\x9c\x9f\x10\x00\x00\x00\x00\x1e\x8c\x90\x10\x00\x00\x00\x00\x1f|\x81\x10\x00\x00\x00\x00 lr\x10\x00\x00\x00\x00!\\c\x10\x00\x00\x00\x00\"LT\x10\x00\x00\x00\x00#<E\x10\x00\x00\x00\x00$,6\x10\x00\x00\x00\x00%\x1c'\x10\x00\x00\x00\x00&\f\x18\x10\x00\x00\x00\x00'\x05C\x90\x00\x00\x00\x00'\xf54\x90\x00\x00\x00\x00(\xe5%\x90\x00\x00\x00\x00)\xd5\x16\x90\x00\x00\x00\x00*\xc5\a\x90\x00\x00\x00\x00+\xb4\xf8\x90\x00\x00\x00\x00,\xa4\xe9\x90\x00\x00\x00\x00-\x94ڐ\x00\x00\x00\x00.\x84ː\x00\x00\x00\x00/t\xbc\x90\x00\x00\x00\x000d\xad\x90\x00\x00\x00\x001]\xd9\x10\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x03\x01\x02\x01\x02\x01\x03\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x00\x00\f\x88\x00\x00\x00\x00\x1c \x01\x04\x00\x00\x0e\x10\x00\t\x00\x00*0\x01\rLMT\x00CEST\x00CET\x00CEMT\x00\nCET-1CEST,M3.5.0,M10.5.0/3\n", | ||
202 | wantName: "CET", | ||
203 | wantOffset: 3600, | ||
204 | }, | ||
205 | { | ||
206 | // 2021a slim tzdata for America/Nuuk. | ||
207 | zoneName: "America/Nuuk", | ||
208 | tzData: "TZif3\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00TZif3\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\"\x00\x00\x00\x03\x00\x00\x00\f\xff\xff\xff\xff\x9b\x80h\x00\x00\x00\x00\x00\x13M|P\x00\x00\x00\x00\x143\xfa\x90\x00\x00\x00\x00\x15#\xeb\x90\x00\x00\x00\x00\x16\x13ܐ\x00\x00\x00\x00\x17\x03͐\x00\x00\x00\x00\x17\xf3\xbe\x90\x00\x00\x00\x00\x18㯐\x00\x00\x00\x00\x19Ӡ\x90\x00\x00\x00\x00\x1aÑ\x90\x00\x00\x00\x00\x1b\xbc\xbd\x10\x00\x00\x00\x00\x1c\xac\xae\x10\x00\x00\x00\x00\x1d\x9c\x9f\x10\x00\x00\x00\x00\x1e\x8c\x90\x10\x00\x00\x00\x00\x1f|\x81\x10\x00\x00\x00\x00 lr\x10\x00\x00\x00\x00!\\c\x10\x00\x00\x00\x00\"LT\x10\x00\x00\x00\x00#<E\x10\x00\x00\x00\x00$,6\x10\x00\x00\x00\x00%\x1c'\x10\x00\x00\x00\x00&\f\x18\x10\x00\x00\x00\x00'\x05C\x90\x00\x00\x00\x00'\xf54\x90\x00\x00\x00\x00(\xe5%\x90\x00\x00\x00\x00)\xd5\x16\x90\x00\x00\x00\x00*\xc5\a\x90\x00\x00\x00\x00+\xb4\xf8\x90\x00\x00\x00\x00,\xa4\xe9\x90\x00\x00\x00\x00-\x94ڐ\x00\x00\x00\x00.\x84ː\x00\x00\x00\x00/t\xbc\x90\x00\x00\x00\x000d\xad\x90\x00\x00\x00\x001]\xd9\x10\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\xff\xffπ\x00\x00\xff\xff\xd5\xd0\x00\x04\xff\xff\xe3\xe0\x01\bLMT\x00-03\x00-02\x00\n<-03>3<-02>,M3.5.0/-2,M10.5.0/-1\n", | ||
209 | wantName: "-03", | ||
210 | wantOffset: -10800, | ||
211 | }, | ||
212 | { | ||
213 | // 2021a slim tzdata for Asia/Gaza. | ||
214 | zoneName: "Asia/Gaza", | ||
215 | tzData: "TZif3\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00TZif3\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00s\x00\x00\x00\x05\x00\x00\x00\x15\xff\xff\xff\xff}\xbdJ\xb0\xff\xff\xff\xff\xc8Y\xcf\x00\xff\xff\xff\xff\xc8\xfa\xa6\x00\xff\xff\xff\xff\xc98\x9c\x80\xff\xff\xff\xff\xcc\xe5\xeb\x80\xff\xff\xff\xffͬ\xfe\x00\xff\xff\xff\xff\xce\xc7\x1f\x00\xff\xff\xff\xffϏ\x83\x00\xff\xff\xff\xffЩ\xa4\x00\xff\xff\xff\xffф}\x00\xff\xff\xff\xffҊ׀\xff\xff\xff\xff\xd3e\xb0\x80\xff\xff\xff\xff\xd4l\v\x00\xff\xff\xff\xff\xe86c`\xff\xff\xff\xff\xe8\xf4-P\xff\xff\xff\xff\xea\v\xb9`\xff\xff\xff\xff\xea\xd5`\xd0\xff\xff\xff\xff\xeb\xec\xfa\xf0\xff\xff\xff\xff\xec\xb5m\x00\xff\xff\xff\xff\xed\xcf\u007f\xf0\xff\xff\xff\xff\xee\x97\xf2\x00\xff\xff\xff\xffﰳp\xff\xff\xff\xff\xf0y%\x80\xff\xff\xff\xff\xf1\x91\xe6\xf0\xff\xff\xff\xff\xf2ZY\x00\xff\xff\xff\xff\xf3s\x1ap\xff\xff\xff\xff\xf4;\x8c\x80\xff\xff\xff\xff\xf5U\x9fp\xff\xff\xff\xff\xf6\x1e\x11\x80\xff\xff\xff\xff\xf76\xd2\xf0\xff\xff\xff\xff\xf7\xffE\x00\xff\xff\xff\xff\xf9\x18\x06p\xff\xff\xff\xff\xf9\xe1\xca\x00\xff\xff\xff\xff\xfa\xf99\xf0\xff\xff\xff\xff\xfb'BP\x00\x00\x00\x00\b|\x8b\xe0\x00\x00\x00\x00\b\xfd\xb0\xd0\x00\x00\x00\x00\t\xf6\xea`\x00\x00\x00\x00\n\xa63\xd0\x00\x00\x00\x00\x13\xe9\xfc`\x00\x00\x00\x00\x14![`\x00\x00\x00\x00\x1a\xfa\xc6`\x00\x00\x00\x00\x1b\x8en`\x00\x00\x00\x00\x1c\xbe\xf8\xe0\x00\x00\x00\x00\x1dw|\xd0\x00\x00\x00\x00\x1e\xcc\xff`\x00\x00\x00\x00\x1f`\x99P\x00\x00\x00\x00 \x82\xb1`\x00\x00\x00\x00!I\xb5\xd0\x00\x00\x00\x00\"^\x9e\xe0\x00\x00\x00\x00# ]P\x00\x00\x00\x00$Z0`\x00\x00\x00\x00%\x00?P\x00\x00\x00\x00&\v\xed\xe0\x00\x00\x00\x00&\xd6\xe6\xd0\x00\x00\x00\x00'\xeb\xcf\xe0\x00\x00\x00\x00(\xc0\x03P\x00\x00\x00\x00)\xd4\xec`\x00\x00\x00\x00*\xa9\x1f\xd0\x00\x00\x00\x00+\xbbe\xe0\x00\x00\x00\x00,\x89\x01\xd0\x00\x00\x00\x00-\x9bG\xe0\x00\x00\x00\x00._\xa9P\x00\x00\x00\x00/{)\xe0\x00\x00\x00\x000H\xc5\xd0\x00\x00\x00\x000\xe7\a\xe0\x00\x00\x00\x001dF`\x00\x00\x00\x002A\xc2`\x00\x00\x00\x003D(`\x00\x00\x00\x004!\xa4`\x00\x00\x00\x005$\n`\x00\x00\x00\x006\x01\x86`\x00\x00\x00\x007\x16a`\x00\x00\x00\x008\x06DP\x00\x00\x00\x008\xff}\xe0\x00\x00\x00\x009\xef`\xd0\x00\x00\x00\x00:\xdf_\xe0\x00\x00\x00\x00;\xcfB\xd0\x00\x00\x00\x00<\xbfA\xe0\x00\x00\x00\x00=\xaf$\xd0\x00\x00\x00\x00>\x9f#\xe0\x00\x00\x00\x00?\x8f\x06\xd0\x00\x00\x00\x00@\u007f\x05\xe0\x00\x00\x00\x00A\\\x81\xe0\x00\x00\x00\x00B^\xe7\xe0\x00\x00\x00\x00CA\xb7\xf0\x00\x00\x00\x00D-\xa6`\x00\x00\x00\x00E\x12\xfdP\x00\x00\x00\x00F\x0e\xd9\xe0\x00\x00\x00\x00F\xe8op\x00\x00\x00\x00G\xec\x18\xe0\x00\x00\x00\x00H\xb7\x11\xd0\x00\x00\x00\x00I\xcb\xfa\xe0\x00\x00\x00\x00J\xa0<`\x00\x00\x00\x00K\xad.\x9c\x00\x00\x00\x00La\xbd\xd0\x00\x00\x00\x00M\x94\xf9\x9c\x00\x00\x00\x00N5\xc2P\x00\x00\x00\x00Ot\xdb`\x00\x00\x00\x00P[\x91\xe0\x00\x00\x00\x00QT\xbd`\x00\x00\x00\x00RD\xa0P\x00\x00\x00\x00S4\x9f`\x00\x00\x00\x00TIlP\x00\x00\x00\x00U\x15\xd2\xe0\x00\x00\x00\x00V)\\`\x00\x00\x00\x00V\xf5\xc2\xf0\x00\x00\x00\x00X\x13\xca`\x00\x00\x00\x00Xդ\xf0\x00\x00\x00\x00Y\xf3\xac`\x00\x00\x00\x00Z\xb5\x86\xf0\x00\x00\x00\x00[ӎ`\x00\x00\x00\x00\\\x9dC\xe0\x00\x00\x00\x00]\xb3bP\x00\x00\x00\x00^~w`\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x04\x03\x04\x03\x04\x03\x04\x03\x04\x03\x04\x03\x04\x03\x04\x03\x04\x03\x04\x03\x04\x03\x04\x03\x04\x03\x04\x03\x04\x03\x04\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x00\x00 P\x00\x00\x00\x00*0\x01\x04\x00\x00\x1c \x00\t\x00\x00*0\x01\r\x00\x00\x1c \x00\x11LMT\x00EEST\x00EET\x00IDT\x00IST\x00\nEET-2EEST,M3.4.4/48,M10.4.4/49\n", | ||
216 | wantName: "EET", | ||
217 | wantOffset: 7200, | ||
218 | }, | ||
219 | } | ||
195 | 220 | ||
196 | reference, err := time.LoadLocationFromTZData("Europe/Berlin", []byte(tzData)) | 221 | func TestLoadLocationFromTZDataSlim(t *testing.T) { |
197 | if err != nil { | 222 | for _, test := range slimTests { |
198 | t.Fatal(err) | 223 | reference, err := time.LoadLocationFromTZData(test.zoneName, []byte(test.tzData)) |
199 | } | 224 | if err != nil { |
225 | t.Fatal(err) | ||
226 | } | ||
200 | 227 | ||
201 | d := time.Date(2020, time.October, 29, 15, 30, 0, 0, reference) | 228 | d := time.Date(2020, time.October, 29, 15, 30, 0, 0, reference) |
202 | tzName, tzOffset := d.Zone() | 229 | tzName, tzOffset := d.Zone() |
203 | if want := "CET"; tzName != want { | 230 | if tzName != test.wantName { |
204 | t.Errorf("Zone name == %s, want %s", tzName, want) | 231 | t.Errorf("Zone name == %s, want %s", tzName, test.wantName) |
205 | } | 232 | } |
206 | if want := 3600; tzOffset != want { | 233 | if tzOffset != test.wantOffset { |
207 | t.Errorf("Zone offset == %d, want %d", tzOffset, want) | 234 | t.Errorf("Zone offset == %d, want %d", tzOffset, test.wantOffset) |
235 | } | ||
208 | } | 236 | } |
209 | } | 237 | } |
210 | 238 | ||
@@ -269,7 +297,8 @@ func TestTzsetOffset(t *testing.T) { | |||
269 | {"+08", 8 * 60 * 60, "", true}, | 297 | {"+08", 8 * 60 * 60, "", true}, |
270 | {"-01:02:03", -1*60*60 - 2*60 - 3, "", true}, | 298 | {"-01:02:03", -1*60*60 - 2*60 - 3, "", true}, |
271 | {"01", 1 * 60 * 60, "", true}, | 299 | {"01", 1 * 60 * 60, "", true}, |
272 | {"100", 0, "", false}, | 300 | {"100", 100 * 60 * 60, "", true}, |
301 | {"1000", 0, "", false}, | ||
273 | {"8PDT", 8 * 60 * 60, "PDT", true}, | 302 | {"8PDT", 8 * 60 * 60, "PDT", true}, |
274 | } { | 303 | } { |
275 | off, out, ok := time.TzsetOffset(test.in) | 304 | off, out, ok := time.TzsetOffset(test.in) |
@@ -294,6 +323,7 @@ func TestTzsetRule(t *testing.T) { | |||
294 | {"30/03:00:00", time.Rule{Kind: time.RuleDOY, Day: 30, Time: 3 * 60 * 60}, "", true}, | 323 | {"30/03:00:00", time.Rule{Kind: time.RuleDOY, Day: 30, Time: 3 * 60 * 60}, "", true}, |
295 | {"M4.5.6/03:00:00", time.Rule{Kind: time.RuleMonthWeekDay, Mon: 4, Week: 5, Day: 6, Time: 3 * 60 * 60}, "", true}, | 324 | {"M4.5.6/03:00:00", time.Rule{Kind: time.RuleMonthWeekDay, Mon: 4, Week: 5, Day: 6, Time: 3 * 60 * 60}, "", true}, |
296 | {"M4.5.7/03:00:00", time.Rule{}, "", false}, | 325 | {"M4.5.7/03:00:00", time.Rule{}, "", false}, |
326 | {"M4.5.6/-04", time.Rule{Kind: time.RuleMonthWeekDay, Mon: 4, Week: 5, Day: 6, Time: -4 * 60 * 60}, "", true}, | ||
297 | } { | 327 | } { |
298 | r, out, ok := time.TzsetRule(test.in) | 328 | r, out, ok := time.TzsetRule(test.in) |
299 | if r != test.r || out != test.out || ok != test.ok { | 329 | if r != test.r || out != test.out || ok != test.ok { |
diff --git a/libgo/misc/cgo/testplugin/plugin_test.go b/libgo/misc/cgo/testplugin/plugin_test.go index 9055dbda044..2d991012c82 100644 --- a/libgo/misc/cgo/testplugin/plugin_test.go +++ b/libgo/misc/cgo/testplugin/plugin_test.go | |||
@@ -201,12 +201,11 @@ func TestMethod(t *testing.T) { | |||
201 | // Exported symbol's method must be live. | 201 | // Exported symbol's method must be live. |
202 | goCmd(t, "build", "-buildmode=plugin", "-o", "plugin.so", "./method/plugin.go") | 202 | goCmd(t, "build", "-buildmode=plugin", "-o", "plugin.so", "./method/plugin.go") |
203 | goCmd(t, "build", "-o", "method.exe", "./method/main.go") | 203 | goCmd(t, "build", "-o", "method.exe", "./method/main.go") |
204 | run(t, "./method.exe") | ||
205 | } | ||
204 | 206 | ||
205 | ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | 207 | func TestMethod2(t *testing.T) { |
206 | defer cancel() | 208 | goCmd(t, "build", "-buildmode=plugin", "-o", "method2.so", "./method2/plugin.go") |
207 | cmd := exec.CommandContext(ctx, "./method.exe") | 209 | goCmd(t, "build", "-o", "method2.exe", "./method2/main.go") |
208 | out, err := cmd.CombinedOutput() | 210 | run(t, "./method2.exe") |
209 | if err != nil { | ||
210 | t.Fatalf("%s: %v\n%s", strings.Join(cmd.Args, " "), err, out) | ||
211 | } | ||
212 | } | 211 | } |
diff --git a/libgo/misc/cgo/testplugin/testdata/method2/main.go b/libgo/misc/cgo/testplugin/testdata/method2/main.go new file mode 100644 index 00000000000..6a87e7b6a0f --- /dev/null +++ b/libgo/misc/cgo/testplugin/testdata/method2/main.go | |||
@@ -0,0 +1,32 @@ | |||
1 | // Copyright 2021 The Go Authors. All rights reserved. | ||
2 | // Use of this source code is governed by a BSD-style | ||
3 | // license that can be found in the LICENSE file. | ||
4 | |||
5 | // A type can be passed to a plugin and converted to interface | ||
6 | // there. So its methods need to be live. | ||
7 | |||
8 | package main | ||
9 | |||
10 | import ( | ||
11 | "plugin" | ||
12 | |||
13 | "testplugin/method2/p" | ||
14 | ) | ||
15 | |||
16 | var t p.T | ||
17 | |||
18 | type I interface { M() } | ||
19 | |||
20 | func main() { | ||
21 | pl, err := plugin.Open("method2.so") | ||
22 | if err != nil { | ||
23 | panic(err) | ||
24 | } | ||
25 | |||
26 | f, err := pl.Lookup("F") | ||
27 | if err != nil { | ||
28 | panic(err) | ||
29 | } | ||
30 | |||
31 | f.(func(p.T) interface{})(t).(I).M() | ||
32 | } | ||
diff --git a/libgo/misc/cgo/testplugin/testdata/method2/p/p.go b/libgo/misc/cgo/testplugin/testdata/method2/p/p.go new file mode 100644 index 00000000000..acb526acec9 --- /dev/null +++ b/libgo/misc/cgo/testplugin/testdata/method2/p/p.go | |||
@@ -0,0 +1,9 @@ | |||
1 | // Copyright 2021 The Go Authors. All rights reserved. | ||
2 | // Use of this source code is governed by a BSD-style | ||
3 | // license that can be found in the LICENSE file. | ||
4 | |||
5 | package p | ||
6 | |||
7 | type T int | ||
8 | |||
9 | func (T) M() { println("M") } | ||
diff --git a/libgo/misc/cgo/testplugin/testdata/method2/plugin.go b/libgo/misc/cgo/testplugin/testdata/method2/plugin.go new file mode 100644 index 00000000000..6198e7648ee --- /dev/null +++ b/libgo/misc/cgo/testplugin/testdata/method2/plugin.go | |||
@@ -0,0 +1,11 @@ | |||
1 | // Copyright 2021 The Go Authors. All rights reserved. | ||
2 | // Use of this source code is governed by a BSD-style | ||
3 | // license that can be found in the LICENSE file. | ||
4 | |||
5 | package main | ||
6 | |||
7 | import "testplugin/method2/p" | ||
8 | |||
9 | func main() {} | ||
10 | |||
11 | func F(t p.T) interface{} { return t } | ||