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: go.mod cannot be in drive root folder on Windows #51506

Closed
cwmos opened this issue Mar 5, 2022 · 10 comments
Closed

cmd/go: go.mod cannot be in drive root folder on Windows #51506

cwmos opened this issue Mar 5, 2022 · 10 comments
Assignees
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Milestone

Comments

@cwmos
Copy link

cwmos commented Mar 5, 2022

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

go version go1.17.8 windows/amd64

Does this issue reproduce with the latest release?

I believe this is the latest stable release.

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

go env Output
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\XXX\AppData\Local\go-build
set GOENV=C:\Users\XXX\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\XXX\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\XXX\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.17.8
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\XXX\AppData\Local\Temp\go-build3973278424=/tmp/go-build -gno-record-gcc-switches

What did you do?

I placed my go.mod file in the root folder of a drive and placed my main package in a subfolder. I then ran "go build" in the subfolder.

What did you expect to see?

I expected my program to compile

What did you see instead?

The go compiler outputed this error:

directory . outside available modules
@cwmos cwmos changed the title go.mod cannot be in driver root folder on Windows go.mod cannot be in drive root folder on Windows Mar 5, 2022
@cwmos cwmos changed the title go.mod cannot be in drive root folder on Windows go/compile: go.mod cannot be in drive root folder on Windows Mar 6, 2022
@ALTree ALTree changed the title go/compile: go.mod cannot be in drive root folder on Windows go/go: go.mod cannot be in drive root folder on Windows Mar 6, 2022
@ALTree ALTree added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows modules labels Mar 6, 2022
@ALTree ALTree added this to the Unplanned milestone Mar 6, 2022
@bcmills bcmills modified the milestones: Unplanned, Backlog Mar 8, 2022
@bcmills
Copy link
Member

bcmills commented May 11, 2022

@cwmos, it's possible that this may have been fixed by the change to str.TrimFilePathPrefix in CL 396694. Could you try a go built from head (see https://go.dev/doc/install/source) or gotip and check whether it still reproduces?

@bcmills bcmills added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label May 11, 2022
@cwmos
Copy link
Author

cwmos commented May 11, 2022

I tried with gotip and there is still the same issue. The error message has changed to:

directory . outside main module or its selected dependencies

@bcmills bcmills added help wanted and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels May 12, 2022
@mattn
Copy link
Member

mattn commented May 12, 2022

I'm trying this with HEAD.

image

@cwmos
Copy link
Author

cwmos commented May 12, 2022

@mattn , you need to build in a subfolder
Untitled

@mattn
Copy link
Member

mattn commented May 12, 2022

I could repro.

@gopherbot
Copy link

Change https://go.dev/cl/405934 mentions this issue: cmd/go/internal/modload: check path prefix with correct module root.

@mattn
Copy link
Member

mattn commented May 12, 2022

When go.mod is located on root directory, go compiler check the module prefix with C:\\ and C:\foo.

@seankhliao seankhliao changed the title go/go: go.mod cannot be in drive root folder on Windows cmd/go: go.mod cannot be in drive root folder on Windows Jul 19, 2022
@gopherbot
Copy link

Change https://go.dev/cl/463178 mentions this issue: cmd/go: use Join functions instead of adding path separators to strings

@gopherbot
Copy link

Change https://go.dev/cl/463176 mentions this issue: cmd/go/internal/str: fix PathPrefix functions for root directories

gopherbot pushed a commit that referenced this issue Jan 25, 2023
For #51506.
For #50807.

Change-Id: I4c0ae85a2103ac4f07351a4f01ce24fa02f03104
Reviewed-on: https://go-review.googlesource.com/c/go/+/463176
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
@bcmills bcmills self-assigned this Jan 26, 2023
@bcmills bcmills modified the milestones: Backlog, Go1.21 Jan 26, 2023
@bcmills
Copy link
Member

bcmills commented Jan 31, 2023

Confirmed that this appears to be fixed by testing manually on a gomote instance:

gopher@SERVER-2016-V8- C:\subdir>type ..\go.mod
module root

go 1.21

gopher@SERVER-2016-V8- C:\subdir>go env GOMOD
C:\go.mod

gopher@SERVER-2016-V8- C:\subdir>go build

(Please let me know if you can reproduce it again at HEAD.)

johanbrandhorst pushed a commit to Pryz/go that referenced this issue Feb 12, 2023
Adding a file path separator is incorrect for a file path that may be
the root directory on a Unix platform (such as in a container or
chroot).

Adding a path separator is incorrect for a package path prefix that
may be the empty string (as in the "std" module in GOROOT/src).

And in both cases, a Join function is arguably clearer and simpler
anyway.

Fixes golang#51506 (maybe).

Change-Id: Id816930811ad5e4d1fbd206cddf219ecd4ad39a2
Reviewed-on: https://go-review.googlesource.com/c/go/+/463178
Reviewed-by: Russ Cox <rsc@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
@golang golang locked and limited conversation to collaborators Jan 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Projects
None yet
Development

No branches or pull requests

5 participants