-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.go
61 lines (56 loc) · 1.61 KB
/
commands.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package build
import (
"context"
"fmt"
"os"
"os/exec"
"path/filepath"
"github.com/outofforest/build"
"github.com/outofforest/libexec"
"github.com/samber/lo"
"github.com/sei-protocol/build/pkg/tools"
"github.com/sei-protocol/build/pkg/tools/golang"
)
// Commands is the list of standard commands useful for every environment.
var Commands = map[string]build.Command{
"enter": {
Description: "Enters the environment",
Fn: enter,
},
"build/me": {
Description: "Rebuilds the builder",
Fn: func(ctx context.Context, deps build.DepsFunc) error {
return golang.Build(ctx, deps, golang.BuildConfig{
Platform: tools.PlatformLocal,
PackagePath: "build/cmd/builder",
BinOutputPath: filepath.Join("bin", ".cache", filepath.Base(lo.Must(os.Executable()))),
})
},
},
"tools/setup": {
Description: "Installs all the tools for the host operating system",
Fn: tools.EnsureAll,
},
"tools/verify": {
Description: "Verifies the checksums of all the tools",
Fn: tools.VerifyChecksums,
},
}
func enter(ctx context.Context, deps build.DepsFunc) error {
bash := exec.Command("bash")
bash.Env = append(os.Environ(),
"PS1=("+build.GetName(ctx)+`) [\u@\h \W]\$ `,
fmt.Sprintf("PATH=%s:%s:%s",
filepath.Join(lo.Must(filepath.EvalSymlinks(lo.Must(filepath.Abs(".")))), "bin"),
filepath.Join(tools.VersionDir(ctx, tools.PlatformLocal), "bin"),
os.Getenv("PATH")),
)
bash.Stdin = os.Stdin
bash.Stdout = os.Stdout
bash.Stderr = os.Stderr
err := libexec.Exec(ctx, bash)
if bash.ProcessState != nil && bash.ProcessState.ExitCode() != 0 {
return nil
}
return err
}