Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: document that generate processes packages in command line order #19762

Open
myitcv opened this issue Mar 29, 2017 · 4 comments
Open

cmd/go: document that generate processes packages in command line order #19762

myitcv opened this issue Mar 29, 2017 · 4 comments

Comments

@myitcv
Copy link
Member

@myitcv myitcv commented Mar 29, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.8 linux/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/myitcv/mgo/src/modelogiq.com/g/_vendor:/home/myitcv/mgo"
GORACE=""
GOROOT="/home/myitcv/gos"
GOTOOLDIR="/home/myitcv/gos/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build675075507=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

go generate accepts a number of packages as arguments, packages on which to run go generate. go generate -help makes no mention of the order in which those packages will be go generate-d

The lack of any mention on the order of execution might well be intentional...

But in any case I'd like to propose we define the order and document it (this issue could conceivably be a proposal, very happy to redo as such)

The use case stems a use case where go generate-ors end up parsing dependencies in order to make decisions on their output. In this context, having go generate run in reverse dependency order (there's probably a more precise term?) on the set of packages provided as arguments avoids the need to re-run go generate multiple times (which incidentally is the current alternative, clearly not ideal)

What did you expect to see?

"Expect" is not the correct word here... because the order is unspecified I can't reasonably have an expectation. More a "hope" perhaps that:

go generate should run in reverse-dependency order on the set of packages passed to it as arguments.

What did you see instead?

It runs in an unspecified order.

cc @robpike perhaps?

@ALTree ALTree added this to the Go1.10 milestone Jul 18, 2017
@rsc rsc modified the milestones: Go1.10, Go1.11 Dec 1, 2017
@rsc

This comment has been minimized.

Copy link
Contributor

@rsc rsc commented Apr 18, 2018

It runs in the same order as go list: sorted by identifying import path.
Documenting this is fine.
Changing it is not.

@rsc rsc changed the title cmd/go: generate does not specify order of execution for package arguments cmd/go: document that generate processes packages sorted by import path Apr 18, 2018
@rsc rsc added NeedsFix and removed NeedsDecision labels Apr 18, 2018
@rsc

This comment has been minimized.

Copy link
Contributor

@rsc rsc commented Apr 18, 2018

Actually the order of "go list" is "as listed on the command line".
Wildcards expand in sorted order within the command line
but that doesn't matter much here.

@rsc rsc changed the title cmd/go: document that generate processes packages sorted by import path cmd/go: document that generate processes packages in command line order Apr 18, 2018
@myitcv

This comment has been minimized.

Copy link
Member Author

@myitcv myitcv commented Apr 18, 2018

Documenting this is fine. Changing it is not.

Makes total sense.

@ianlancetaylor ianlancetaylor modified the milestones: Go1.11, Go1.12 Jul 6, 2018
@agnivade agnivade added the Suggested label Dec 11, 2018
@andybons andybons modified the milestones: Go1.12, Go1.13 Feb 12, 2019
@andybons andybons modified the milestones: Go1.13, Go1.14 Jul 8, 2019
@bcmills bcmills modified the milestones: Go1.14, Unplanned Sep 18, 2019
@tpaschalis

This comment has been minimized.

Copy link

@tpaschalis tpaschalis commented Sep 26, 2019

So, if I get this right, generate runs in the same order as list, that is "as listed on the command line".

The current documentation says (https://golang.org/pkg/cmd/go/internal/generate/) as much :

Generate processes packages in the order given on the command line,
one at a time. If the command line lists .go files from a single directory,
they are treated as a single package. Within a package, generate processes the
source files in a package in file name order, one at a time.

I think the behavior is already explained in the docs.
Is there anything to be changed, should this be documented in another place as well, or should the issue be closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
9 participants
You can’t perform that action at this time.