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: does not find packages under GOPATH when run from GOROOT\src directory on windows #38148

Closed
alexbrainman opened this issue Mar 29, 2020 · 2 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@alexbrainman
Copy link
Member

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

go version devel +5aef51a729 Sun Mar 29 02:01:34 2020 +0000 windows/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output

set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Alex\AppData\Local\go-build
set GOENV=C:\Users\Alex\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=c:\users\alex\dev
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\users\alex\dev\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\users\alex\dev\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
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 -fmessage-length=0 -fdebug-prefix-map=C:\Users\Alex\AppData\Local\Temp\go-build421324630=/tmp/go-build -gno-record-gcc-switches

What did you do?

c:\>cd %GOROOT%\src

c:\Users\Alex\dev\go\src>type %GOPATH%\src\a\main.go
package main

import (
        "fmt"
)

func main() {
        fmt.Println("Hello")
}

c:\Users\Alex\dev\go\src>go build -o %TMP%\a.exe a && %TMP%\a.exe
package a: cannot find package "." in:
        c:\Users\Alex\dev\go\src\a

c:\Users\Alex\dev\go\src>

What did you expect to see?

I expected my program in package a in my GOPATH directory to build.

What did you see instead?

I see the error above.

This used to work, but was broken by

0fc89a72edc2c73651f7f6841b1146af723f517f is the first bad commit
commit 0fc89a72edc2c73651f7f6841b1146af723f517f
Author: Bryan C. Mills <bcmills@google.com>
Date:   Wed Feb 20 18:25:37 2019 -0500

    cmd,std: add go.mod files

    Updates #30241
    Updates #30228

    Change-Id: Ida0fe8263bf44e0498fed2048e22283ba5716835
    Reviewed-on: https://go-review.googlesource.com/c/go/+/164622
    Run-TryBot: Bryan C. Mills <bcmills@google.com>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    Reviewed-by: Jay Conrod <jayconrod@google.com>

@bcmills @jayconrod let me know, if you need help to debug this.

Thank you.

Alex

@bcmills
Copy link
Contributor

bcmills commented Mar 30, 2020

GOROOT/src is a module (the std module, to be specific).

As of Go 1.13, if the working directory is within a module, cmd/go uses module mode (rather than GOPATH mode) by default.

So this seems to be working as designed. If you want to build in GOPATH mode, either run the go command from outside of a module, or set GO111MODULE=off explicitly.

@bcmills bcmills added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Mar 30, 2020
@alexbrainman
Copy link
Member Author

So this seems to be working as designed. If you want to build in GOPATH mode, either run the go command from outside of a module, or set GO111MODULE=off explicitly.

You are correct. My Linux shell is configured with GO111MODULE=off. But I don't have GO111MODULE=off set on my Windows computer. That is why they are different. Setting GO111MODULE=off on Windows makes the command above work as I expected it.

Sorry to waste your time. Closing the issue.

Alex

@golang golang locked and limited conversation to collaborators Apr 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants