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: go build -n prints to both stderr and stdout #12913

Closed
alexflint opened this issue Oct 13, 2015 · 10 comments
Closed

cmd/go: go build -n prints to both stderr and stdout #12913

alexflint opened this issue Oct 13, 2015 · 10 comments
Milestone

Comments

@alexflint
Copy link

go version go1.5 darwin/amd64

go build -n prints the commands that would be executed to stderr, but it prints comments showing package names to stdout.

So for example, stderr looks like:

$ go build -n -p=1 ./... > /dev/null
mkdir -p ...
mkdir -p ...
/usr/local/go/pkg/tool/darwin_amd64/compile -o $WORK/github.com/kiteco/kiteco/kite-golib/awsutil.a -trimpath $WORK -p github.com/kiteco/kiteco/kite-golib/awsutil -complete -buildid 7663b4f5d089fba431b4f7afe76077cc3339efe3 -D _/Users/alex/Code/go/src/github.com/kiteco/kiteco/kite-golib/awsutil -I $WORK -I /Users/alex/Code/go/pkg/darwin_amd64 -pack ./cache.go ./checksum.go ./io.go ./s3.go
...

whereas stdout looks like

$ go build -n -p=1 ./... 2> /dev/null

#
# github.com/kiteco/kiteco/kite-golib/awsutil
#


#
# github.com/kiteco/kiteco/kite-golib/fileutil
#

...

This makes it difficult to match up the helpful package name comments with the commands to which they pertain. I was expecting that either both would be printed to stderr or both would be printed to stdout.

@adg adg changed the title go build -n prints to both stderr and stdout cmd/go: go build -n prints to both stderr and stdout Oct 13, 2015
@adg
Copy link
Contributor

adg commented Oct 13, 2015

I think the correct thing is to print them all to stdout.

@rakyll
Copy link
Contributor

rakyll commented Oct 13, 2015

The current behavior is intentional. The pragma comments are additional bits to inform humans. Shouldn't the machines always consume the stderr?

@adg
Copy link
Contributor

adg commented Oct 13, 2015

Stderr was invented to convey messages to humans, not machines. The machine-readable output should be sent to stdout so that it can be easily piped into another program or file.

In this case, if I'm running go build -n I expect the output to be a series of shell commands. Any errors that occur in producing that output should be sent to stderr.

@rakyll
Copy link
Contributor

rakyll commented Oct 13, 2015

Sorry, s/stderr/stdout.

The use of two different streams is intentional and you can always 2>&1. I don't think there is anything wrong with the current behavior.

@adg
Copy link
Contributor

adg commented Oct 13, 2015

The commands are printed to stderr. I think they should be printed to stdout. The pragmas can also be printed to stdout as they are just shell comments.

@rakyll
Copy link
Contributor

rakyll commented Oct 13, 2015

gomobile prints commands and comments both to stderr. Regardless of what the final decision, at least, we need to be consistent and apply the same convention to gomobile.

(FWIW, the only justification to write to stderr might be able to diff between -v vs -n and -v vs -x prints. I don't have background about the current behavior and would like to have more context. -n is used to test the tools and I don't think the informative comments are a necessity there and they are written to stdout just like the other verbose output.)

@adg
Copy link
Contributor

adg commented Oct 13, 2015

I'm not sure if we have made a policy decision about stdout/stderr, but if
not I am happy to make one. I'll investigate.

On 13 October 2015 at 16:38, rakyll notifications@github.com wrote:

gomobile prints commands and comments both to stderr. Regardless of what
the final decision, at least, we need to be consistent and apply the same
convention to gomobile.

(FWIW, the only justification to write to stderr might be able to diff
between -v vs -n and -v vs -x prints. I don't have background about the
current behavior and would like to have more context. -n is used to test
the tools and I don't think the informative comments are a necessity there
and they are written to stdout just like the other verbose output.)


Reply to this email directly or view it on GitHub
#12913 (comment).

@adg
Copy link
Contributor

adg commented Oct 16, 2015

I don't really have a strong opinion on whether the -n output should go to stdout or stderr. I'd err on the side of stdout. But I do agree with the issue reporter that the output should be sent to one or the other, and not both (interleaved).

Can @rsc advise?

@rsc
Copy link
Contributor

rsc commented Oct 23, 2015

It is in no way intentional that the output is split between stdout and stderr.

Originally it was all to stdout. CL 7393073 moved the bulk of the output to stderr. The # block print was missed. The fix is to change

fmt.Printf("\n#\n# %s\n#\n\n", a.p.ImportPath)

to use b.print like everything else. Thanks.

@rsc rsc added this to the Go1.6 milestone Oct 23, 2015
@gopherbot
Copy link

CL https://golang.org/cl/16737 mentions this issue.

@golang golang locked and limited conversation to collaborators Nov 10, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants