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: build constraint of 'ignore' is special for modules? #29598

Closed
myitcv opened this issue Jan 7, 2019 · 3 comments
Closed

cmd/go: build constraint of 'ignore' is special for modules? #29598

myitcv opened this issue Jan 7, 2019 · 3 comments
Labels
Documentation FrozenDueToAge GoCommand cmd/go modules NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@myitcv
Copy link
Member

myitcv commented Jan 7, 2019

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

> go version
[stdout]
go version go1.12beta1 linux/amd64

Does this issue reproduce with the latest release?

Yes; testing with the beta ahead of the 1.12 release.

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

go env Output
> go env
[stdout]
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/myitcv/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="$WORK/gopath"
GOPROXY="http://127.0.0.1:40043/mod"
GORACE=""
GOROOT="/home/myitcv/gos"
GOTMPDIR=""
GOTOOLDIR="/home/myitcv/gos/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="$WORK/go.mod"
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 -fmessage-length=0 -fdebug-prefix-map=$WORK/tmp/go-build168896432=/tmp/go-build -gno-record-gcc-switches"

What did you do?

# no build constraint
go list
go mod tidy
grep 'fruit.com v1.0.0' go.mod

# build constraint of other
cp mod.go.other mod.go
go mod tidy
grep 'fruit.com v1.0.0' go.mod

# build constraint of ignore
cp mod.go.ignore mod.go
go mod tidy
grep 'fruit.com v1.0.0' go.mod


-- go.mod --
module mod

-- mod.go --
package mod

import _ "fruit.com/fruit"

-- mod.go.ignore --
// +build ignore

package mod

import _ "fruit.com/fruit"

-- mod.go.other --
// +build other

package mod

import _ "fruit.com/fruit"

using the following module definition:

# mod/fruit.com_v1.0.0.txt 
-- .mod --
module fruit.com

-- .info --
{"Version":"v1.0.0","Time":"2018-10-22T18:45:39Z"}

-- go.mod --
module fruit.com

-- fruit/fruit.go --
package fruit

What did you expect to see?

A passing test.

What did you see instead?

--- FAIL: TestScripts (0.04s)
    --- FAIL: TestScripts/script (0.23s)
        testscript.go:193:
            # no build constraint (0.107s)
            # build constraint of other (0.021s)
            # build constraint of ignore (0.032s)
            > cp mod.go.ignore mod.go
            > go mod tidy
            > grep 'fruit.com v1.0.0' go.mod
            [go.mod]
            module mod

            go 1.12

            FAIL: testdata/script.txt:17: no match for `fruit.com v1.0.0` found in go.mod

I wasn't aware that the ignore build constraint was special but judging from the above it appears to be.

ignore is described as being conventional, but not that it carries any special semantics.

The cmd/go docs also don't appear to make mention of this special case.

Assuming this is the intended behaviour, I think it would be worth updating the docs to call this out. I just spent a good few mins trying to track down a go mod tidy bug that in fact turned out to be an instance of a file with a // +build ignore constraint.

cc @bcmills

FYI @mvdan @rogpeppe

@bcmills bcmills added Documentation modules NeedsFix The path to resolution is known, but the work has not been done. labels Jan 7, 2019
@bcmills bcmills added this to the Go1.13 milestone Jan 7, 2019
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/167159 mentions this issue: all: add go.mod

gopherbot pushed a commit to golang/talks that referenced this issue Mar 13, 2019
Commands run:
	sed -i 's;// +build OMIT;// +build ignore,OMIT;' $(grep -l OMIT -r)
	go mod init
	go mod edit -go=1.11
	go mod tidy
	go list -m all
	go test ./...

Updates golang/go#30228
Updates golang/go#29598

Change-Id: I3d0a4787c1158572bed8dd3785ff02e16d1cc1f3
Reviewed-on: https://go-review.googlesource.com/c/talks/+/167159
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
@andybons andybons modified the milestones: Go1.13, Go1.14 Jul 8, 2019
@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
@dmitshur dmitshur added the GoCommand cmd/go label Jul 22, 2020
awels added a commit to awels/containerized-data-importer that referenced this issue Aug 13, 2020
…ps-update will not ignore it

and properly vendor in code-generator. But using the build tag will cause the build to not
generate a binary for this file.

// +build ignore is special apparently
golang/go#29598

Signed-off-by: Alexander Wels <awels@redhat.com>
awels added a commit to awels/containerized-data-importer that referenced this issue Aug 13, 2020
make deps-update will not ignore it and properly vendor in code-generator.
Buy using the +build tag will cause the build to not include this code
during a build unless the codegen tag is used.

// +build ignore is special apparently
golang/go#29598

Signed-off-by: Alexander Wels <awels@redhat.com>
awels added a commit to awels/containerized-data-importer that referenced this issue Aug 13, 2020
make deps-update will not ignore it and properly vendor in k8s.io/code-generator.
By using the +build tag will cause the build to not include this code
during a build unless the codegen tag is used.

// +build ignore is special apparently
golang/go#29598

Signed-off-by: Alexander Wels <awels@redhat.com>
kubevirt-bot pushed a commit to kubevirt/containerized-data-importer that referenced this issue Aug 13, 2020
make deps-update will not ignore it and properly vendor in k8s.io/code-generator.
By using the +build tag will cause the build to not include this code
during a build unless the codegen tag is used.

// +build ignore is special apparently
golang/go#29598

Signed-off-by: Alexander Wels <awels@redhat.com>
@AlekSi
Copy link
Contributor

AlekSi commented Jul 31, 2021

https://golang.org/ref/mod#go-mod-tidy now says this:

There is one exception: the ignore build tag is not enabled, so a file with the build constraint // +build ignore will not be considered.

@jayconrod
Copy link
Contributor

Since this is now documented in https://golang.org/ref/mod#go-mod-tidy, let's close this.

We'll need to be careful to document this for other commands that load the full import graph the way that go mod tidy does. For now, that's only https://golang.org/ref/mod#go-mod-vendor, which does mention this.

@golang golang locked and limited conversation to collaborators Aug 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge GoCommand cmd/go modules NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

8 participants