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: defaultGOPATH cannot handle the confiliction correctly #18863

Closed
hirochachacha opened this issue Jan 31, 2017 · 9 comments
Closed

go/build: defaultGOPATH cannot handle the confiliction correctly #18863

hirochachacha opened this issue Jan 31, 2017 · 9 comments
Milestone

Comments

@hirochachacha
Copy link
Contributor

Please answer these questions before submitting your issue. Thanks!

What did you do?

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

package main

import (
	"fmt"
	"go/build"
)

func main() {
	fmt.Println(build.Default.GOPATH)
}

then,
$GOROOT="$HOME/go" GOPATH="" go run c.go:


$GOROOT="$HOME/go/" GOPATH="" go run c.go:

/Users/hiro/go

What did you expect to see?

same outputs

What did you see instead?

different outputs

Does this issue reproduce with the latest release (go1.7.5)?

IIUC, default go path is introduced in go1.8.

System details

go version devel +3e55059 Mon Jan 30 20:38:03 2017 +0000 darwin/amd64
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/hiro/.go"
GORACE=""
GOROOT="/Users/hiro/go"
GOTOOLDIR="/Users/hiro/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/wq/dwn8hs0x7njbzty9f68y61700000gn/T/go-build575104841=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
GOROOT/bin/go version: go version devel +3e55059 Mon Jan 30 20:38:03 2017 +0000 darwin/amd64
GOROOT/bin/go tool compile -V: compile version devel +3e55059 Mon Jan 30 20:38:03 2017 +0000 X:framepointer
uname -v: Darwin Kernel Version 16.3.0: Thu Nov 17 20:23:58 PST 2016; root:xnu-3789.31.2~1/RELEASE_X86_64
ProductName:	Mac OS X
ProductVersion:	10.12.2
BuildVersion:	16C67
lldb --version: lldb-360.1.70
gdb --version: GNU gdb (GDB) 7.12
@gopherbot
Copy link
Contributor

CL https://golang.org/cl/36073 mentions this issue.

@rakyll rakyll added this to the Go1.9 milestone Jan 31, 2017
@rakyll
Copy link
Contributor

rakyll commented Jan 31, 2017

If GOROOT is being corrupted due to the mishandling, we should consider fixing this in 1.8.

/cc @bradfitz

@rakyll rakyll modified the milestones: Go1.8Maybe, Go1.9 Jan 31, 2017
@bradfitz
Copy link
Contributor

That one-line change might be okay. I'd prefer to see a test, though, at which point it's more than one line.

I'll let @rsc decide.

@davecheney
Copy link
Contributor

Assigning "" to an environment variable does not unset it.

package main

import (
        "fmt"
        "os"
)

func main() {
        fmt.Println(os.LookupEnv("GOPATH"))
}
deadwood(~/src) % go run printenv.go
/home/dfc true
deadwood(~/src) % unset GOPATH
deadwood(~/src) % go run printenv.go
 false
deadwood(~/src) % env GOPATH="" go run printenv.go                                                                             
 true

@hirochachacha
Copy link
Contributor Author

@davecheney

go/build/build.go uses:

func envOr(name, def string) string {
	s := os.Getenv(name)
	if s == "" {
		return def
	}
	return s
}

I cannot judge this is WAI or an another subtle bug, though.

@davecheney
Copy link
Contributor

davecheney commented Jan 31, 2017 via email

@gopherbot
Copy link
Contributor

CL https://golang.org/cl/36427 mentions this issue.

@rsc rsc modified the milestones: Go1.8, Go1.8Maybe Feb 7, 2017
@rsc rsc reopened this Feb 7, 2017
@rsc
Copy link
Contributor

rsc commented Feb 7, 2017

Cherry-pick to release branch pending.

@gopherbot
Copy link
Contributor

CL https://golang.org/cl/36536 mentions this issue.

gopherbot pushed a commit that referenced this issue Feb 7, 2017
…TH=GOROOT

Fixes #18863.

Change-Id: I0723563cd23728b0d43ebcc25979bf8d21e2a72c
Reviewed-on: https://go-review.googlesource.com/36427
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-on: https://go-review.googlesource.com/36536
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
@rsc rsc closed this as completed Feb 7, 2017
@golang golang locked and limited conversation to collaborators Feb 7, 2018
@rsc rsc removed their assignment Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants