Skip to content

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

@lnshi

Description

@lnshi

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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions