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: clean paths before checking whether command line files are in same directory #47392

Closed
Gerrard-YNWA opened this issue Jul 26, 2021 · 6 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@Gerrard-YNWA
Copy link

Gerrard-YNWA commented Jul 26, 2021

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

$ go version
go version go1.16.5 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="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/gerrard/Library/Caches/go-build"
GOENV="/Users/gerrard/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/gerrard/workspace/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/gerrard/workspace/go"
GOPRIVATE=""
GOPROXY="https://goproxy.io"
GOROOT="/usr/local/Cellar/go/1.16.5/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.16.5/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16.5"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/gerrard/workspace/aispeech/code/pasc-server/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/yy/1gf6d2mn3vv0270568dg6l7c0000gn/T/go-build2904605194=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I typed go test manually to run test in terminal and got the error.

$ go test ./test/e2e/foo_test.go test/e2e/e2e.go
named files must all be in one directory; have ./test/e2e/ and test/e2e/

What did you expect to see?

Treat ./test/e2e/ and test/e2e/ as same dir

What did you see instead?

It seems that the internal load package use the filepath.Split in GoFilesPackage function to the ensure all named files must all be in one directory.

But filepath.Split only does the split and does not normalized the result.

I'm not sure whether we can replace it with filepath.Dir and get rid of the such error prompt?

@seankhliao
Copy link
Member

test/e2e refers to a package whos fully qualified import path is test/e2e, all directory arguments need to begin with ./

@Gerrard-YNWA
Copy link
Author

Hi @seankhliao thanks for reply. Yes, I agree test/e2e refers to a package.

What I expected here is to normalized dir name for better comparison which has no relationship with package's import path.

From GoFilesPackage, dir will be covered by the absolute path eventually.

@seankhliao
Copy link
Member

The problem is test/e2e refers to the (non-existent) package test/e2e in the standard library, not the one in your module, which is why ./ is required to disambiguate being passed a package pattern and a directory pattern. While the specific example of test/e2e is unlikely to appear in the standard library, the same cannot be said for other patterns

@jayconrod jayconrod changed the title cmd/go: automatically normalize directory name instead of prompting error? cmd/go: clean paths before checking whether command line files are in same directory Jul 26, 2021
@jayconrod jayconrod reopened this Jul 26, 2021
@jayconrod jayconrod added the NeedsFix The path to resolution is known, but the work has not been done. label Jul 26, 2021
@jayconrod jayconrod added this to the Unplanned milestone Jul 26, 2021
@jayconrod
Copy link
Contributor

I think this is a valid (but lower priority issue). The go command uses the .go suffix on the arguments to decide that this is a list of files that should be compiled together, rather than a list of import or directory paths for packages.

It makes sense to require that those files are in the same directory, but it seems fine to pass the arguments through filepath.Clean before checking.

@Gerrard-YNWA
Copy link
Author

Hi @jayconrod, yes, that's what I really expected! I have send a pr to fix this.

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/337629 mentions this issue: cmd/go: clean paths before checking same directory

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

Successfully merging a pull request may close this issue.

4 participants