forked from sourcegraph/srclib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
env.go
43 lines (38 loc) · 1.11 KB
/
env.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package srclib
import (
"log"
"os"
"os/user"
"path/filepath"
"strings"
)
var (
// Path is SRCLIBPATH, a colon-separated list of directories that lists
// places to look for srclib toolchains and cache build data. It is
// initialized from the SRCLIBPATH environment variable; if empty, it
// defaults to $HOME/.srclib.
Path = os.Getenv("SRCLIBPATH")
// CacheDir stores cached build results. It is initialized from the
// SRCLIBCACHE environment variable; if empty, it defaults to DIR/.cache,
// where DIR is the first entry in Path (SRCLIBPATH).
CacheDir = os.Getenv("SRCLIBCACHE")
)
func init() {
if Path == "" {
user, err := user.Current()
if err != nil {
log.Fatal(err)
}
if user.HomeDir == "" {
log.Fatalf("Fatal: No SRCLIBPATH and current user %q has no home directory.", user.Username)
}
Path = filepath.Join(user.HomeDir, ".srclib")
if err := os.Setenv("SRCLIBPATH", Path); err != nil {
log.Fatalf("Fatal: Could not set SRCLIBPATH environment variable to %q.", Path)
}
}
if CacheDir == "" {
dirs := strings.SplitN(Path, ":", 2)
CacheDir = filepath.Join(dirs[0], ".cache")
}
}