Skip to content

Commit c7e9172

Browse files
committed
go/build: handle and warn of duplicate GOPATH entries
R=golang-dev, alex.brainman CC=golang-dev https://golang.org/cl/5519050
1 parent 7478bb9 commit c7e9172

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/pkg/go/build/path.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ func init() {
157157
Path = []*Tree{t}
158158
}
159159

160+
Loop:
160161
for _, p := range filepath.SplitList(os.Getenv("GOPATH")) {
161162
if p == "" {
162163
continue
@@ -166,6 +167,21 @@ func init() {
166167
log.Printf("invalid GOPATH %q: %v", p, err)
167168
continue
168169
}
170+
171+
// Check for dupes.
172+
// TODO(alexbrainman): make this correct under windows (case insensitive).
173+
for _, t2 := range Path {
174+
if t2.Path != t.Path {
175+
continue
176+
}
177+
if t2.Goroot {
178+
log.Printf("GOPATH is the same as GOROOT: %q", t.Path)
179+
} else {
180+
log.Printf("duplicate GOPATH entry: %q", t.Path)
181+
}
182+
continue Loop
183+
}
184+
169185
Path = append(Path, t)
170186
gcImportArgs = append(gcImportArgs, "-I", t.PkgDir())
171187
ldImportArgs = append(ldImportArgs, "-L", t.PkgDir())

0 commit comments

Comments
 (0)