| 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. |
| 4 | |
| 5 | package packagestestscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/ |
| 6 | |
| 7 | import ( |
| 8 | "pathscip-go gomod github.com/golang/go/src go1.25.0 path/" |
| 9 | "path/filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/" |
| 10 | ) |
| 11 | |
| 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 | // |
| 16 | // golang.org/repoa#a/a.go |
| 17 | // golang.org/repob#b/b.go |
| 18 | // |
| 19 | // You would get the directory layout |
| 20 | // |
| 21 | // /sometemporarydirectory |
| 22 | // ├── repoa |
| 23 | // │ └── src |
| 24 | // │ └── golang.org |
| 25 | // │ └── repoa |
| 26 | // │ └── a |
| 27 | // │ └── a.go |
| 28 | // └── repob |
| 29 | // └── src |
| 30 | // └── golang.org |
| 31 | // └── repob |
| 32 | // └── b |
| 33 | // └── b.go |
| 34 | // |
| 35 | // GOPATH would be set to |
| 36 | // |
| 37 | // /sometemporarydirectory/repoa;/sometemporarydirectory/repob |
| 38 | // |
| 39 | // and the working directory would be |
| 40 | // |
| 41 | // /sometemporarydirectory/repoa/src |
| 42 | var GOPATHscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/GOPATH. = gopathscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/gopath#{} |
| 43 | |
| 44 | type gopathscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/gopath# struct{} |
| 45 | |
| 46 | func (gopathscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/gopath#) Namescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/gopath#Name().() string { |
| 47 | return "GOPATH" |
| 48 | } |
| 49 | |
| 50 | func (gopathscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/gopath#) Filenamescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/gopath#Filename().(exported *Exportedscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/Exported#, module, fragment string) string { |
| 51 | return filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Join().(gopathDirscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/gopathDir().(exported, module), "src", module, fragment) |
| 52 | } |
| 53 | |
| 54 | func (gopathscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/gopath#) Finalizescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/gopath#Finalize().(exported *Exportedscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/Exported#) error { |
| 55 | exported.Configscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/Exported#Config..Envscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/packages`/Config#Env. = append(exported.Configscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/Exported#Config..Envscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/packages`/Config#Env., "GO111MODULE=off") |
| 56 | gopath := "" |
| 57 | for module := range exported.writtenscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/Exported#written. { |
| 58 | if gopath != "" { |
| 59 | gopath += string(filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.ListSeparatorscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/ListSeparator.) |
| 60 | } |
| 61 | dir := gopathDirscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/gopathDir().(exported, module) |
| 62 | gopath += dir |
| 63 | if module == exported.primaryscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/Exported#primary. { |
| 64 | exported.Configscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/Exported#Config..Dirscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/packages`/Config#Dir. = filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Join().(dir, "src") |
| 65 | } |
| 66 | } |
| 67 | exported.Configscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/Exported#Config..Envscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/packages`/Config#Env. = append(exported.Configscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/Exported#Config..Envscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/packages`/Config#Env., "GOPATH="+gopath) |
| 68 | return nil |
| 69 | } |
| 70 | |
| 71 | func gopathDirscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/gopathDir().(exported *Exportedscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/Exported#, module string) string { |
| 72 | dir := pathscip-go gomod github.com/golang/go/src go1.25.0 path/.Basescip-go gomod github.com/golang/go/src go1.25.0 path/Base().(module) |
| 73 | if versionSuffixREscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/versionSuffixRE..MatchStringscip-go gomod github.com/golang/go/src go1.25.0 regexp/Regexp#MatchString().(dir) { |
| 74 | dir = pathscip-go gomod github.com/golang/go/src go1.25.0 path/.Basescip-go gomod github.com/golang/go/src go1.25.0 path/Base().(pathscip-go gomod github.com/golang/go/src go1.25.0 path/.Dirscip-go gomod github.com/golang/go/src go1.25.0 path/Dir().(module)) + "_" + dir |
| 75 | } |
| 76 | return filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Join().(exported.tempscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/Exported#temp., dir) |
| 77 | } |