GoPLS Viewer

Home|gopls/go/packages/packagestest/gopath.go
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
5package packagestest
6
7import (
8    "path"
9    "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
42var GOPATH = gopath{}
43
44func init() {
45    All = append(AllGOPATH)
46}
47
48type gopath struct{}
49
50func (gopathName() string {
51    return "GOPATH"
52}
53
54func (gopathFilename(exported *Exportedmodulefragment stringstring {
55    return filepath.Join(gopathDir(exportedmodule), "src"modulefragment)
56}
57
58func (gopathFinalize(exported *Exportederror {
59    exported.Config.Env = append(exported.Config.Env"GO111MODULE=off")
60    gopath := ""
61    for module := range exported.written {
62        if gopath != "" {
63            gopath += string(filepath.ListSeparator)
64        }
65        dir := gopathDir(exportedmodule)
66        gopath += dir
67        if module == exported.primary {
68            exported.Config.Dir = filepath.Join(dir"src")
69        }
70    }
71    exported.Config.Env = append(exported.Config.Env"GOPATH="+gopath)
72    return nil
73}
74
75func gopathDir(exported *Exportedmodule stringstring {
76    dir := path.Base(module)
77    if versionSuffixRE.MatchString(dir) {
78        dir = path.Base(path.Dir(module)) + "_" + dir
79    }
80    return filepath.Join(exported.tempdir)
81}
82
MembersX
gopath
gopath.Filename.module
gopath.Filename.fragment
gopath.Finalize.gopath
init
gopath.Name
gopath.Filename
gopath.Finalize.exported
gopathDir
path
gopath.Finalize
gopath.Finalize.RangeStmt_1465.module
gopath.Filename.exported
gopath.Finalize.RangeStmt_1465.BlockStmt.dir
gopathDir.exported
gopathDir.module
gopathDir.dir
Members
X