Skip to content

go.mod: split the indirect packages#2331

Merged
tonistiigi merged 1 commit into
moby:masterfrom
zchee:gomod-fmt-117
Sep 3, 2021
Merged

go.mod: split the indirect packages#2331
tonistiigi merged 1 commit into
moby:masterfrom
zchee:gomod-fmt-117

Conversation

@zchee
Copy link
Copy Markdown
Contributor

@zchee zchee commented Aug 25, 2021

Split the indirect packages of go.mod.

After go1.17, all indirect packages are listed in the go.mod file.

In addition, has been introduced the ability to list indirect packages separately.
Split the indirect package to make the dependency packages clearer.


This pull request is no-op to codes, just formatted.

@tonistiigi
Copy link
Copy Markdown
Member

Are there some links we can read up on about this being the recommended way to layout go.mod now?

@zchee
Copy link
Copy Markdown
Contributor Author

zchee commented Aug 25, 2021

@tonistiigi I will look for it later, but at least it is specified out below.

https://golang.org/ref/mod#go-mod-file-go

At go 1.17 or higher:

  • The go.mod file includes an explicit require directive for each module that provides any package transitively imported by a package or test in the main module. (At go 1.16 and lower, an indirect dependency is included only if minimal version selection would otherwise select a different version.) This extra information enables module graph pruning and lazy module loading.
  • Because there may be many more // indirect dependencies than in previous go versions, indirect dependencies are recorded in a separate block within the go.mod file.

Actually,

indirect dependencies are recorded in a separate block within the go.mod file.


That means, as a premise, when go.mod go directive is go1.17:
If you adding some dependency package with go get, and already separated blocks, will same result to the this pull request.
This behavior has become a specification of the go command.

See also: https://golang.org/ref/mod#graph-pruning

@zchee
Copy link
Copy Markdown
Contributor Author

zchee commented Aug 25, 2021

@tonistiigi Also,

https://golang.org/doc/go1.17#go-command

Because the number of explicit requirements may be substantially larger in an expanded Go 1.17 go.mod file, the newly-added requirements on indirect dependencies in a go 1.17 module are maintained in a separate require block from the block containing direct dependencies.

Copy link
Copy Markdown
Member

@tonistiigi tonistiigi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

@tonistiigi tonistiigi mentioned this pull request Sep 2, 2021
@tonistiigi
Copy link
Copy Markdown
Member

@zchee This needs rebase

After go1.17, all indirect packages are listed in the go.mod file.

In addition, has been introduced the ability to list indirect packages separately.
Split the indirect packages to make the dependency packages clearer.

Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
@zchee
Copy link
Copy Markdown
Contributor Author

zchee commented Sep 3, 2021

@tonistiigi done

@tonistiigi tonistiigi merged commit 9b010e7 into moby:master Sep 3, 2021
@zchee zchee deleted the gomod-fmt-117 branch September 3, 2021 18:39
Comment thread go.mod
Comment on lines +93 to +94
// snappy: updated for go1.17 support
github.com/golang/snappy v0.0.4-0.20210608040537-544b4180ac70 // indirect
Copy link
Copy Markdown
Member

@thaJeztah thaJeztah Sep 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know if the second require block is ignored by older go version, or is it also used?

The thing that surprised me a bit is that some of these // indirect were not automatically created by go mod, but were manually added to force using a more current version.

I think this import for example (based on the comment) is a manual override, but also github.com/cpuguy83/go-md2man/v2, and some others. I'd have expected go to only put the "automatically collected" imports in the second block, but to keep the "manual overrides" to be in the first block.

Copy link
Copy Markdown
Contributor Author

@zchee zchee Sep 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thaJeztah make sense. will check go1.17 go mod behavior and send PR again

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thaJeztah created PR: #2348

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants