Граф коммитов

73 Коммитов

Автор SHA1 Сообщение Дата
Michael Matloob 3a5865c020 modfile: rename directory directive to use
For golang/go#48257

Change-Id: I9cbb222c93a066717595bec14ff26f2902ef05d9
Reviewed-on: https://go-review.googlesource.com/c/mod/+/359412
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-11-02 18:19:07 +00:00
Jay Conrod c96bc1413d x/mod: update requirement on x/crypto
x/mod does not seem to be affected by this CVE (which is for
x/crypto/ssh), but let's update anyway.

Fixes golang/go#48943

Change-Id: I13f957a354d6f0260ae9fd586b6218151182909c
Reviewed-on: https://go-review.googlesource.com/c/mod/+/355630
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-10-13 18:00:41 +00:00
Koichi Shiraishi ecfafd6fa8 semver: remove unused err field
The err field is assigned in the parse function but never used on another function.

Change-Id: I1ea5fa922776c2c83f5269724f856e8d667f43b4
Reviewed-on: https://go-review.googlesource.com/c/mod/+/353749
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Trust: Jay Conrod <jayconrod@google.com>
Trust: Michael Knyszek <mknyszek@google.com>
2021-10-04 17:47:04 +00:00
HowJMay dd30a601dd module: accept trailing slash in MatchPrefixPattern
Trailing slash of glob was not accepted in MatchPrefixPattern. This
CL starts to accept the trailing slash.

Change-Id: I25e385ffe3a6901d2f475b86507d3e3091a32183
GitHub-Last-Rev: 5dbe41e545
GitHub-Pull-Request: golang/mod#5
Reviewed-on: https://go-review.googlesource.com/c/mod/+/351319
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
Trust: Jay Conrod <jayconrod@google.com>
2021-09-23 17:38:02 +00:00
Jay Conrod 37dd689102 modfile: in SetRequireSeparateIndirect, convert lines to blocks
When reading go.mod, SetRequireSeparateIndirect will insert new
requirements into the last uncommented direct-only or indirect-only
block OR line. If the last such statement is a line,
SetRequireSeparateIndirect converts it to a block before inserting new
requirements. Cleanup will convert it back to a line later if no
requirements are inserted.

For golang/go#47733

Change-Id: Id8ee3b0ce2d005488ddb3d9a5349115bd93938e7
Reviewed-on: https://go-review.googlesource.com/c/mod/+/348576
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
2021-09-13 21:58:16 +00:00
Jay Conrod 4be982bcc4 modfile: in SetRequireSeparateIndirect, arrange requirements consistently
SetRequireSeparateIndirect now makes a stronger attempt to keep
automatically added requirements in two blocks: one containing only
direct requirements and one containing only indirect
requirements. SetRequireSeparateIndirect will find or add these two
blocks (commented blocks are left alone). New requirements are added
to one of these two blocks. Existing requirements may be moved between
these two blocks if their markings change.

SetRequireSeparateIndirect attempts to preserve existing structure in
the file by not adding requirements to or moving requirements from
blocks with block-level comments and blocks other than the last
uncommented direct-only and indirect-only block.

As an exception to aid with migration, if the file contains a single
uncommented block of requirements (as would the be the case if the
user started with a 1.16 go.mod file, changed the go directive to
1.17, then ran 'go mod tidy'), SetRequireSeparateIndirect will split
the block into direct-only and indirect-only blocks.

This is a change in behavior, but it has no semantic effect, and it
should result in cleaner, more stable go.mod files.

For golang/go#47563
For golang/go#47733

Change-Id: Ifa20bb084c6bdaf1e00140600380857de8afa320
Reviewed-on: https://go-review.googlesource.com/c/mod/+/343431
Trust: Jay Conrod <jayconrod@google.com>
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
2021-09-02 22:33:49 +00:00
Jean de Klerk 1b1db11ec8 zip: add ErrUnrecognizedVCS error, allowing fallback behavior
Add ErrUnrecognizedVCS, which allows calling functions (such as gorelease) to
fallback: usually to CreateFromDir.

Updates golang/go#37413

Change-Id: I846f72b1ce22bfc699e8cd83b28ea4529e73d6e9
Reviewed-on: https://go-review.googlesource.com/c/mod/+/345730
Trust: Jean de Klerk <deklerk@google.com>
Run-TryBot: Jean de Klerk <deklerk@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2021-08-30 21:46:25 +00:00
Michael Matloob 4029241eb1 [dev.cmdgo] modfile: parser changes for workfile proposal
This change adds interfaces to the mod package to support parsing
and representing go.work files, including WorkFile for the file as a
whole, Directory for directory statements, and ParseWork for parsing
go.work files.

This code is mostly a lightly modified version of the parsing
code for mod files.

This is meant to support the workspaces proposal and if the proposal
is accepted it's expected theinterface will likely change.

For #45713

Change-Id: I5df6fe4acba1dbe86bc3e3fba40a04fbb4d678e4
Reviewed-on: https://go-review.googlesource.com/c/mod/+/336089
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
(cherry picked from commit e41a6a4f3b)
Reviewed-on: https://go-review.googlesource.com/c/mod/+/324764
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-08-27 16:34:34 +00:00
Tobias Klauser 607370acc0 module: use strings.ContainsRune in fileNameOK
As suggested by Ian for similar code on CL 326010.

Change-Id: I7c6ca4191481daf253eba5f12e7079f5c3522e88
Reviewed-on: https://go-review.googlesource.com/c/mod/+/327029
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-08-16 07:22:36 +00:00
Jean de Klerk 98d530ac93 zip: add CreateFromVCS, which creates a module zip from vcs
Updates golang/go#37413

Change-Id: I5ea07a6e4eedc6cb215e4893944f1ab215ea8f2b
Reviewed-on: https://go-review.googlesource.com/c/mod/+/330769
Trust: Jean de Klerk <deklerk@google.com>
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Jean de Klerk <deklerk@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2021-08-13 17:45:30 +00:00
Jean de Klerk 154199deab zip: add bit more information about what checkFiles does
This CL adds a headstone to checkFiles in the form of additional documentation,
which should hopefully help future developers.

Change-Id: I7957766fc78da45007cbb4e7e3ed59ad2bada4c5
Reviewed-on: https://go-review.googlesource.com/c/mod/+/338669
Trust: Jean de Klerk <deklerk@google.com>
Run-TryBot: Jean de Klerk <deklerk@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2021-08-02 15:30:50 +00:00
Bryan C. Mills 0f08993efd modfile: add SetRequireSeparateIndirect
The new method is a variant of SetRequire, but adds new indirect
dependencies only in indirect-only blocks, and does not add new direct
dependencies to existing indirect-only blocks.

For golang/go#45965

Change-Id: I6730b586396658e710e4bf2afcf64fb2c827203f
Reviewed-on: https://go-review.googlesource.com/c/mod/+/325971
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2021-06-08 19:03:19 +00:00
Bryan C. Mills 22458ad575 modfile: factor out methods for changing Require properties
For golang/go#45965

Change-Id: I331d068d115b145239933da0d8341a1627124935
Reviewed-on: https://go-review.googlesource.com/c/mod/+/325970
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2021-06-08 19:00:12 +00:00
Bryan C. Mills 9eb10b1d3e modfile: make marking for removal a method on Line instead of FileSyntax
The act of marking a line for removal intentionally does not depend on
the rest of the syntax tree, in order to avoid quadratic behavior.
Make that property more explicit by defining it as a method on Line
rather than FileSyntax.

For golang/go#45965

Change-Id: I475625eddf57396411a3fb73eaedd624dd7af3d6
Reviewed-on: https://go-review.googlesource.com/c/mod/+/325969
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2021-06-08 18:59:50 +00:00
Bryan C. Mills 6e4e729686 modfile: clean up SetRequire
I started this change by expanding the documentation and tests for
SetRequire. Unfortunately, the tests failed when the existing
contents included duplicates of a module path:

    --- FAIL: TestSetRequire/existing_duplicate (0.00s)
        rule_test.go:1011: after Cleanup, len(Require) = 3; want 1
    --- FAIL: TestSetRequire/existing_duplicate_multi (0.00s)
        rule_test.go:1011: after Cleanup, len(Require) = 3; want 1

So then I fixed the detected bug, by updating the Line entries
(possibly marking them for removal) in the same loop that updates the
Require entries. (We don't need to loop over f.Syntax.Stmt separately
to remove deleted entries because f.Syntax.Cleanup already does that.)

For golang/go#45965

Change-Id: I1b665c0832112de2c4273628f266dc3d966fefdd
Reviewed-on: https://go-review.googlesource.com/c/mod/+/325230
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2021-06-08 18:58:56 +00:00
Bryan C. Mills ad21a28c14 modfile: document (*File).*Require methods
For golang/go#45965

Change-Id: If3c7255f44adc81b69e8109a5d9d62f116579bbd
Reviewed-on: https://go-review.googlesource.com/c/mod/+/323171
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2021-05-27 20:17:44 +00:00
Bryan C. Mills e953053505 modfile: remove end-of-line comments in removeLine
I added this test case while updating documentation for
golang/go#45965, and it failed. This CL fixes the behavior,
and the next CL in the stack documents it.

For golang/go#45965

Change-Id: Ia68dbd33530eec138745c6e291b096a9fa1e1d58
Reviewed-on: https://go-review.googlesource.com/c/mod/+/323170
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2021-05-27 20:16:58 +00:00
Russ Cox 6088ed88ce modfile: be less strict about go version syntax in dependency go.mod files
It is unclear what the future holds for the go line in go.mod files.
Perhaps at some point we will switch to semver numbering.
Perhaps at some point we will allow specifying minor versions
or even betas and release candidates.
Those kinds of changes are difficult today because the go line
is parsed in dependency modules, meaning that older
versions of the Go toolchain need to understand newer go lines.

This CL makes that case - parsing a go line in a dependency's
go.mod file - a bit more lax about how to find the version.
It allows a leading v and any trailing non-digit-prefixed string
after the MAJOR.MINOR section.

There are no concrete plans to make use of any of these changes,
but if in the future we want to make them, having a few Go releases
under out belt that will accept the syntax in dependencies will
make any changes significantly easier.

See also CL 317690 in the main repo.

Change-Id: I7c7733c62259b3f25683ed618bc4918c98061396
Reviewed-on: https://go-review.googlesource.com/c/mod/+/317689
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-05-12 18:23:55 +00:00
komuW 67f1c1edc2 modfile: take into account that // indirect comments may not be well formatted
When there is an // indirect comment next to a dependency that is not actually indirect;
go mod tidy should remove it.
This was not the case when the //indirect comment was badly formatted.

We now check whether such a comment exists irrespective of the formatting.

Updates golang/go#45932

Change-Id: I6a7dca23059a0aca6f8f940da975a0d79f701571
GitHub-Last-Rev: b884ee1a3e
GitHub-Pull-Request: golang/mod#3
Reviewed-on: https://go-review.googlesource.com/c/mod/+/316569
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Trust: Bryan C. Mills <bcmills@google.com>
Trust: Jay Conrod <jayconrod@google.com>
2021-05-04 18:10:20 +00:00
Ian Lance Taylor fb786b187e module: accept leading dash in a file path
For golang/go#45447

Change-Id: I38b13bc912851aa9b6cdeb851330a5ed97b743ac
Reviewed-on: https://go-review.googlesource.com/c/mod/+/316629
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2021-05-04 15:48:41 +00:00
Bryan C. Mills 4435ecfe48 go.mod: upgrade to go 1.17
This change was produced using 'go mod tidy -go=1.17'
with a go command built at CL 315210.

This activates lazy loading, and updates the go.mod file to maintain
the lazy-loading invariants (namely, including an explicit requirement
for every package transitively imported by the main module).

Note that this does *not* prevent users with earlier go versions from
successfully building packages from this module.

For golang/go#36460

Change-Id: If672eca0dad61b3f6050a94c758d605b6586cbc3
Reviewed-on: https://go-review.googlesource.com/c/mod/+/316113
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2021-05-03 18:30:26 +00:00
Jay Conrod 858fdbee9c modfile: parse deprecation notices in module comments
Deprecation notices start with "Deprecated:" at the beginning of a
line and run until the end of the paragraph.

This CL reuses text extraction code for retraction rationale, so the
same rules apply: comment text may be from the comments above a
"module" directive or as a suffix on the same line.

For golang/go#40357

Change-Id: Id5524149c6bbda3effc64c6b668b701b5cf428af
Reviewed-on: https://go-review.googlesource.com/c/mod/+/301089
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
2021-04-09 13:44:25 +00:00
Jay Conrod 244d49f99a modfile: clarify documentation for Parse
Fixes golang/go#45149

Change-Id: Ie76f4b46964a99015bcd5c8166c26b25bc61ce72
Reviewed-on: https://go-review.googlesource.com/c/mod/+/308452
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Jay Conrod <jayconrod@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-04-08 20:03:56 +00:00
Jay Conrod 1cc8812c17 semver: add ByVersion and Sort for sorting semantic version lists
For golang/go#44969

Change-Id: I148a18b676061cd8ea481c3f5130d0792c0b5233
Reviewed-on: https://go-review.googlesource.com/c/mod/+/304151
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-03-23 21:51:54 +00:00
Jay Conrod 6b0bea43eb module: move pseudo-version functions into module
For golang/go#44969

Change-Id: Ie094d59140764b7f1cffb879d99a13da23a977da
Reviewed-on: https://go-review.googlesource.com/c/mod/+/304150
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-03-23 21:51:50 +00:00
Jay Conrod 19d50cac98 module: add InvalidPathError
CheckPath, CheckImportPath, and CheckFilePath now return this error.

To be used in CL 297634.

Change-Id: Ibc4af7c5593f35216ab3ade0b024971061b8cf97
Reviewed-on: https://go-review.googlesource.com/c/mod/+/297891
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-03-10 18:58:34 +00:00
Bryan C. Mills d6ab96f244 module: allow '+' in package import paths (but not module paths)
For golang/go#44776.

Change-Id: I1bc3df2800a1765296c5164aa8bece495d8f9221
Reviewed-on: https://go-review.googlesource.com/c/mod/+/300149
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2021-03-09 22:22:12 +00:00
Jay Conrod c8bb1bd8a2 module: allow leading dots in import path elements
These were always disallowed, but the restriction wasn't enforced in
most cases until Go 1.16. That's broken more projects than we hoped.

This change allows leading dots in import path elements. Leading dots
are still not allowed in module path elements. Leading dots were
always allowed in file path elements. Trailing dots are still
forbidden in all cases.

For golang/go#43985

Change-Id: Id9cf728a341931565ab9e81f600b2341aa178683
Reviewed-on: https://go-review.googlesource.com/c/mod/+/297089
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-03-01 14:47:19 +00:00
Jay Conrod 66bf157bf5 modfile: defer fixing versions in retract directives
VersionFixers require both a path and a version: if the version is
non-canonical (like a branch name), they generally need the path to
look up the proper version. This is fine for require, replace, and
exclude directives, since the path is specified with each version. For
retract directives, the path comes from the module directive, which
may appear later in the file. Previously, we just used the empty
string, but this breaks reasonable implementations.

With this change, we leave retracted versions alone until the file has
been completely parsed, then we apply the version fixer to each
retract directive. We report an error if retract is used without a
module directive.

For golang/go#44494

Change-Id: I99b7b8b55941c1fde4ee56161acfe854bcaf948d
Reviewed-on: https://go-review.googlesource.com/c/mod/+/296130
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-02-25 16:03:41 +00:00
Bryan C. Mills 66f6d92cab modfile: check canonicalness against the relevant module path, not abstract semver
In CL 279394 we started validating that versions in "exclude" and
"retract" directives are canonical. Unfortunately, we use the semver
package's notion of canonicalness, and the semver package doesn't know
anything about +incompatible versions or major-version suffixes.

The resulting error messages also don't indicate an appropriate fix if
the problem is that the user forgot either the "+incompatible" suffix
on the version string or the "/vN" suffix on the module path.

This change corrects both of those problems by validating the version
against the corresponding module path. (For "exclude" directives, that
is the module path to be excluded; for "retract" directives, it is the
module declared in the "module" directive of the same go.mod file.)

For golang/go#44497

Change-Id: I39732d79c3ab3a43bb1fb8905062fe6cb26d3edc
Reviewed-on: https://go-review.googlesource.com/c/mod/+/295089
Trust: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
2021-02-23 20:29:49 +00:00
Tom Zierbock 6ce8bb3f08 cmd/go: validating version format in mod edit
Version strings set by -retract and -exclude are not canonicalized
by go mod commands. This change adds validation to go mod edit to
prevent invalid version strings from being added to the go.mod file.

For golang/go#43280

Change-Id: I3708b7a09111a56effac1fe1165122772e3f2d75
Reviewed-on: https://go-review.googlesource.com/c/mod/+/279394
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Trust: Michael Matloob <matloob@golang.org>
2021-01-14 18:10:11 +00:00
Jay Conrod bc388b264a README: convert to Markdown and add pkg.go.dev tag
Change-Id: Ie721c15613a716517e163186e952b888664282f2
Reviewed-on: https://go-review.googlesource.com/c/mod/+/275194
Trust: Jay Conrod <jayconrod@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
2020-12-03 23:18:14 +00:00
Jay Conrod 3bfbaada29 semver: deprecate semver.Max
There are a number of calls to semver.Max in the wild, so let's not
delete it yet.

For golang/go#32700

Change-Id: I515b05f174195d1b82a931b92e21b83c370ef7c7
Reviewed-on: https://go-review.googlesource.com/c/mod/+/269357
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-11-12 14:17:40 +00:00
Michael Matloob ce943fd024 module: reject Windows shortnames as path components
This backports golang.org/cl/154102 to reduce the differences between
the path checking done for import paths by the go command, and
module.CheckImportPath

For golang/go#29230

Change-Id: I1b03de85e560504b5ddb32ebdaf6d7e4384f992c
Reviewed-on: https://go-review.googlesource.com/c/mod/+/250920
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-08-28 18:31:25 +00:00
Michael Matloob b857d93e83 module: reject "+" in CheckPath and CheckImportPath
"+" was allowed in some vcs regular expressions, but doesn't seem
to be used in practice anymore. Stop accepting it in import paths.
This is being submitted early in the Go 1.16 cycle so that if a
usage is detected it can be reverted. See the discussion in
golang.org/issue/31376 for more details.

For golang/go#31376

Change-Id: I392fcdcf829886bd0a28450ba5e399e64dd01559
Reviewed-on: https://go-review.googlesource.com/c/mod/+/250919
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-08-28 15:38:31 +00:00
Jay Conrod 3d8fd711ab zip: add CheckFiles, CheckDir, and CheckZip
These functions may be used to check whether the files in an abstract
list, a directory, or a module zip file satisfy the module name and
size constraints listed in the package documentation. Each function
returns a CheckedFiles record that lists valid, omitted, and invalid
files, as well as any size-related error for the whole set of
files. The omitted and invalid lists have an error for each file,
saying why it was omitted or invalid.

Create, CreateFromDir, and Unzip are now implemented using these
functions (or common code). They now return errors based on
CheckedFiles errors. Most error messages won't change, but if multiple
files are invalid, they will be all be listed instead of just the
first one.

Fixes golang/go#36058
Updates golang/go#39091

Change-Id: I9d4d508288bbd821f93423e712232d8a68356529
Reviewed-on: https://go-review.googlesource.com/c/mod/+/235597
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
2020-08-26 18:53:02 +00:00
Jay Conrod c0d644d00a modfile: support retract directive and version intervals
This CL adds support for parsing and programmatically adding and
removing a new directive, "retract", as described in golang/go#24031.

The "retract" directive comes in two forms:

    retract v1.0.0           // single version
    retract [v1.1.0, v1.2.0] // closed interval

Updates golang/go#24031

Change-Id: I1236c7d89e7674abf694e49e9b4869b14a59fac0
Reviewed-on: https://go-review.googlesource.com/c/mod/+/228039
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2020-08-24 16:22:28 +00:00
Jay Conrod 89ce4c7ba8 modfile: remove trailing newline from comment tokens
In v0.2.0, the go.mod lexer removed trailing LF bytes from comment
tokens. This regressed in v0.3.0. Documentation on Comment.Token says
the trailing newline should not be included.

This CL fixes the lexer to strip trailing newlines again. It will now
strip both LF and CRLF newlines. It also includes a test to ensure
comments are attached at the right place in the syntax tree with the
right content.

Fixes golang/go#39913

Change-Id: I7fba0ed3c85f0a3c23fefc6b7fecfe6df7777aea
Reviewed-on: https://go-review.googlesource.com/c/mod/+/240557
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2020-07-06 16:06:32 +00:00
Rob Findley 0b26df4a22 module: add a MatchPrefixPatterns function, for matching GOPRIVATE, etc.
This CL exposes a new MatchPrefixPatterns function, extracted from
GlobsMatchPath in src/cmd/go/internal/str. Tool authors can use this to
identify non-public modules by matching against GOPRIVATE, as is
explicitly suggested by `go help module-private`.

Fixes golang/go#38725

Change-Id: I5be79b49c2c13f2d68c7421a06747a297f48f21a
Reviewed-on: https://go-review.googlesource.com/c/mod/+/239797
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2020-06-25 14:17:48 +00:00
Jay Conrod 859b3ef565 modfile: scan ASCII brackets and commas as separate tokens
The characters '( ) [ ] { } ,' are now scanned as separate tokens,
even when they are preceded by non-whitespace "identifier"
characters. Previously, '( )' were scanned like this when preceded by
whitespace, but they could be in the middle of an identifier
token. None of these characters are allowed in module paths or
versions. They are allowed within file paths, so file paths containing
them will need to be quoted in the future. Using these characters
should not break ParseLax, since replace directives (the only directive
that allows files paths) are ignored by ParseLax.

Additionally, '(' is only treated as the beginning of a block if it
appears at the end of the line or is immediately followed by ')' at the
end of the line. ')' is treated as the end of a block if it
appears within a block at the beginning of a line.

Fixes golang/go#38167
Updates golang/go#38144
Updates golang/go#24031

Change-Id: I5a7fb522163802c3723d289cf0fbc5856ca075ec
Reviewed-on: https://go-review.googlesource.com/c/mod/+/226639
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-04-29 17:28:58 +00:00
Jay Conrod 60cb782965 modfile: add retract directives to TestParseLax
Old versions of modfile before CL 228039 should be able to parse and
ignore retract directives with version intervals.

Updates golang/go#24031

Change-Id: I0f35261997c0704a785ea8467dc5ed0738549966
Reviewed-on: https://go-review.googlesource.com/c/mod/+/230697
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-04-29 17:26:32 +00:00
Jay Conrod 2addee1ccf zip: in TestVCS, skip instead of failing after VCS error
The underlying package doesn't interact with VCS. The test just does
this to simulate what the go command does. A VCS failure indicates a
problem with the test environment, not with the code being tested.

Fixes golang/go#38466

Change-Id: I1c36f7c9c644b22e01fa073a5d8a58c9a3893145
Reviewed-on: https://go-review.googlesource.com/c/mod/+/228397
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-04-15 21:51:25 +00:00
Jared Allard b1723bd057 modfile: be more clear about go field format
Makes it more clear about the `go` format in `go.mod`. I've seen people get pretty confused about that error message.

Change-Id: Ia1d3dd4250edc9b8fbd159c93c68498d7e8fa783
GitHub-Last-Rev: 5e24006775
GitHub-Pull-Request: golang/mod#2
Reviewed-on: https://go-review.googlesource.com/c/mod/+/226438
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2020-03-30 19:38:11 +00:00
Bryan C. Mills e5e73c1b9c zip: document isVendoredPackage false-positives
I had thought that the known bug in isVendoredPackage was strictly
conservative, but it turns out not to be.

Updates golang/go#37397
Updates golang/go#31562

Change-Id: I60f6062c41ec2d116766930f751d7df083535355
Reviewed-on: https://go-review.googlesource.com/c/mod/+/220657
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2020-02-24 19:41:23 +00:00
Jay Conrod b0a8b1272e zip: fix staticcheck errors
Reported by dmitshur in a comment in CL 202042.

Change-Id: I913bd87d9a17a9cf19ac869f8b7166b05e839758
Reviewed-on: https://go-review.googlesource.com/c/mod/+/218237
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2020-02-07 14:47:22 +00:00
Jay Conrod 76efd80997 modfile: add package documentation
Fixes golang/go#36757

Change-Id: I674edfabed7f4bb54c909eda56ca4a87b037fe83
Reviewed-on: https://go-review.googlesource.com/c/mod/+/216842
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2020-01-29 20:16:24 +00:00
Jay Conrod accd165b16 modfile: return structured errors from Parse and ParseLax
Parse and ParseLax now return an ErrorList, which is a slice of Errors
that satisfies the error interface. Each Error now contains a file
name and position. The verb and module path fields are optional.

Fixes golang/go#36486

Change-Id: I2a244c8753cfce4bb290ddb8bcea5ee73c45f79f
Reviewed-on: https://go-review.googlesource.com/c/mod/+/214430
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rohan Challa <rohan@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2020-01-21 19:02:30 +00:00
Katie Hockman ed3ec21bb8 sumdb/note: remove draft comment
Change-Id: Ie46caf623e8244a5b53ad5a51d1f3a8801d1711d
Reviewed-on: https://go-review.googlesource.com/c/mod/+/213120
Reviewed-by: Jay Conrod <jayconrod@google.com>
2020-01-02 17:33:45 +00:00
Fazlul Shahriar 331c550502 zip: skip symlink test on Plan 9
Fixes golang/go#36041

Change-Id: I7b65ca053e994c56d6a354133daff81bcadd7220
Reviewed-on: https://go-review.googlesource.com/c/mod/+/210397
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-12-09 13:42:35 +00:00
Jay Conrod 788aebd067 modfile: replace empty comments when adding indirect
When we add an "indirect" token to a line with an empty comment (only
whitespace after //), we should replace the comment text.

In CL 208273, we inserted "indirect;". The isIndirect predicate returns
false for "// indirect;" because there's only one word. When
modload.WriteGoMod is called multiple times (as it is in
'go mod tidy'), this caused us to write "// indirect; indirect".

Updates golang/go#35737

Change-Id: Ic2531a61ab15df7a0d4462ea3b1d25753d06d1d1
Reviewed-on: https://go-review.googlesource.com/c/mod/+/208671
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2019-11-26 16:19:57 +00:00