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

Suddenly go build doesn't respect '// +build ignore' flag #28687

Closed
lnshi opened this issue Nov 9, 2018 · 3 comments
Closed

Suddenly go build doesn't respect '// +build ignore' flag #28687

lnshi opened this issue Nov 9, 2018 · 3 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@lnshi
Copy link

lnshi commented Nov 9, 2018

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

$ go version
go version go1.10.3 darwin/amd64

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/leonard/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/leonard/go_projects"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.10.3/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.10.3/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/xw/fjl2c85x0psg7nm1sth8y_m40000gn/T/go-build892466275=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Just use the command env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o attacker main.go to build one of my single package to executable binary.

But since I don't want to include this package in my production release, so i use the // +build ignore to ignore it, only when i need to run above build command i remove the // +build ignore flag.

Previously the // +build ignore was working as expected, i mean if i run above command with it i will run into error that "the source was ignored.. bla bla", if i want to build it then i need to remove the // +build ignore, but now with the // +build ignore there, i still can build it!!!, totally cannot recall what was changed to cause this.

What did you expect to see?

With the // +build ignore i should not able to build the source.

What did you see instead?

Even with the // +build ignore there i am still able not build the source and roll out the executable binary!

// +build ignore

package main

import (
	"flag"
	"fmt"
	"math/rand"
	"runtime"
	"sync"
	"time"
@mvdan
Copy link
Member

mvdan commented Nov 9, 2018

I use // +build ignore in my projects and it hasn't broken for me. Please provide a full Go program to reproduce this bug, and clear steps to do so.

Also note that you don't need to remove the build ignore line when you do go build somefile.go. Files can only be ignored when one is building an entire package; the lines don't take effect when one is specifying what files to build.

@mvdan
Copy link
Member

mvdan commented Nov 9, 2018

Also note that the latest Go version is 1.11, not 1.10. Have you tried that?

@mvdan mvdan added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Nov 9, 2018
@lnshi
Copy link
Author

lnshi commented Nov 9, 2018

oh, then i think my report is misinformation, i remember i always build this package(single go file actually) with command env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o attacker main.go, maybe i remembered wrongly.

when i omit the main.go in above command i am able to see the familiar error i remembered before: can't load package: bla bla ...: build constraints exclude all Go files bla bla

I am gonna close this.

Thanks a lot for the clarification.

@lnshi lnshi closed this as completed Nov 9, 2018
@golang golang locked and limited conversation to collaborators Nov 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants