1 // Copyright 2018 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
12 // GOPATH is the exporter that produces GOPATH layouts.
13 // Each "module" is put in it's own GOPATH entry to help test complex cases.
14 // Given the two files
15 // golang.org/repoa#a/a.go
16 // golang.org/repob#b/b.go
17 // You would get the directory layout
18 // /sometemporarydirectory
31 // GOPATH would be set to
32 // /sometemporarydirectory/repoa;/sometemporarydirectory/repob
33 // and the working directory would be
34 // /sometemporarydirectory/repoa/src
38 All = append(All, GOPATH)
43 func (gopath) Name() string {
47 func (gopath) Filename(exported *Exported, module, fragment string) string {
48 return filepath.Join(gopathDir(exported, module), "src", module, fragment)
51 func (gopath) Finalize(exported *Exported) error {
52 exported.Config.Env = append(exported.Config.Env, "GO111MODULE=off")
54 for module := range exported.written {
56 gopath += string(filepath.ListSeparator)
58 dir := gopathDir(exported, module)
60 if module == exported.primary {
61 exported.Config.Dir = filepath.Join(dir, "src")
64 exported.Config.Env = append(exported.Config.Env, "GOPATH="+gopath)
68 func gopathDir(exported *Exported, module string) string {
69 dir := path.Base(module)
70 if versionSuffixRE.MatchString(dir) {
71 dir = path.Base(path.Dir(module)) + "_" + dir
73 return filepath.Join(exported.temp, dir)