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: ignore build tags for fmt, vet #4007

Closed
gopherbot opened this issue Aug 25, 2012 · 11 comments
Closed

cmd/go: ignore build tags for fmt, vet #4007

gopherbot opened this issue Aug 25, 2012 · 11 comments
Milestone

Comments

@gopherbot
Copy link

by jimteeuwen:

go fmt ignores .go files which have a '+build ...' comment defined in them, but only if
they reside in a sub-package.

A simple example:

    $ cat test/a.go
    package test
    func F(){}

    $ cat test/b.go    
    // +build foo
    
    package test
    func T(){}

    $ go fmt ./...
    test/a.go

If I remove the build tag comment, go fmt picks up b.go as it should.
This happens in go 1.0.2 and tip. The command works correctly when
go fmt is invoked in the same directory as the source files.

What is the expected output?
test/a.go
test/b.go

What do you see instead?
test/a.go

Which operating system are you using?
64-bit Arch Linux (kernel 3.4.9-1-ARCH)

Which version are you using?  (run 'go version')
'devel' and 'go1.0.2'. Both have the same behaviour.
@robpike
Copy link
Contributor

robpike commented Aug 27, 2012

Comment 1:

Labels changed: added priority-soon, removed priority-triage.

Owner changed to @griesemer.

@griesemer
Copy link
Contributor

Comment 2:

This is an issue with the go command rather than gofmt. Using gofmt directly works fine:
gofmt -l -w *.go .

Owner changed to @rsc.

@minux
Copy link
Member

minux commented Aug 27, 2012

Comment 3:

this is because the cmd/go doesn't ignore build tags when doing 'go fmt'.

@rsc
Copy link
Contributor

rsc commented Sep 12, 2012

Comment 4:

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Sep 12, 2012

Comment 5:

Labels changed: added go1.1.

@rsc
Copy link
Contributor

rsc commented Dec 9, 2012

Comment 6:

Sure, let's try this.

@rsc
Copy link
Contributor

rsc commented Dec 10, 2012

Comment 7:

Labels changed: added size-m.

@rsc
Copy link
Contributor

rsc commented Jan 31, 2013

Comment 8:

This issue was closed by revision 8b6534b.

Status changed to Fixed.

@gopherbot
Copy link
Author

Comment 9:

Has this resurfaced?
$ mkdir z && cd z && echo -e '// +build nope\n\npackage  foo'  >bar.go && go fmt -n .
can't load package: package .: no buildable Go source files in /home/tv/tmp/z

@rsc
Copy link
Contributor

rsc commented Mar 12, 2014

Comment 10:

no, it is working. the go command requires that there be at least one
non-ignored go file in a directory. echo package foo >baz.go and then run
go fmt -n .

@adg
Copy link
Contributor

adg commented Mar 12, 2014

Comment 11:

Issue #7478 has been merged into this issue.

@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
@rsc rsc removed their assignment Jun 22, 2022
This issue was closed.
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

6 participants