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

go/build: file name build constraints incorrect when name contains dots #46662

Open
knusbaum opened this issue Jun 9, 2021 · 2 comments · May be fixed by #46663
Open

go/build: file name build constraints incorrect when name contains dots #46662

knusbaum opened this issue Jun 9, 2021 · 2 comments · May be fixed by #46663
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@knusbaum
Copy link
Contributor

knusbaum commented Jun 9, 2021

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

$ go version
go version go1.16.4 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/kyle.nusbaum/Library/Caches/go-build"
GOENV="/Users/kyle.nusbaum/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/kyle.nusbaum/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/kyle.nusbaum/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/kyle.nusbaum/sdk/go1.16.4"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/kyle.nusbaum/sdk/go1.16.4/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16.4"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/kyle.nusbaum/Documents/CodeBase/go/src/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 -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/8x/bn6z9tk109n_hvbhl8fwdmpw0000gn/T/go-build558940160=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I created a .go file which contained dots in the name along with a _GOOS extension (e.g. file.name_darwin.go)

What did you expect to see?

I expected this file to be compiled only when GOOS=darwin

Please see this example, which I expect to compile but does not:
https://github.com/knusbaum/goissue/

What did you see instead?

The error that appears:

% go build
# github.com/knusbaum/goissue
./my.name.result_linux.go:3:6: Result redeclared in this block
	previous declaration at ./my.name.result_darwin.go:3:15

Additional information

The build constraint documentation says this:

 If a file's name, after stripping the extension and a possible _test suffix, matches any of the following patterns:

*_GOOS
*_GOARCH
*_GOOS_GOARCH

Wherever a file's "extension" is mentioned in the Go documentation, it means whatever comes after the final . in the file name. This is also what path.Ext documents and computes.

However, the os/arch-matching code takes the extension from the first instance of . rather than the last, as the documentation would lead me to expect.

This places requirements for using the os/arch constraints in file names that are not documented anywhere and are inconsistent with the way Go code and documentation usually deals with file extensions.

knusbaum added a commit to knusbaum/go-1 that referenced this issue Jun 9, 2021
Previously, goodOSArchFile trimmed the file name's extension from the first
instance of "." in the name. This resulted in strange behavior when
compiling files with dots in their names.

This change causes goodOSArchFile to trim the file name's extension from
the final instance of ".", as path.Ext suggests should happen.

Fixes golang#46662
@gopherbot
Copy link

Change https://golang.org/cl/326249 mentions this issue: go/build: trim filename extension starting at the final dot

@cherrymui cherrymui added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 9, 2021
@cherrymui cherrymui added this to the Backlog milestone Jun 9, 2021
@cherrymui
Copy link
Member

cc @rsc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants