-
Notifications
You must be signed in to change notification settings - Fork 531
/
install.go
84 lines (69 loc) · 2.15 KB
/
install.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package cosmosgen
import (
"context"
"go/ast"
"github.com/ignite/cli/v28/ignite/pkg/errors"
"github.com/ignite/cli/v28/ignite/pkg/goanalysis"
"github.com/ignite/cli/v28/ignite/pkg/gocmd"
)
// DepTools necessary tools to build and run the chain.
func DepTools() []string {
return []string{
// buf build code generation.
"github.com/bufbuild/buf/cmd/buf",
"github.com/cosmos/gogoproto/protoc-gen-gocosmos",
// Go code generation plugin.
"google.golang.org/grpc/cmd/protoc-gen-go-grpc",
"google.golang.org/protobuf/cmd/protoc-gen-go",
"github.com/cosmos/cosmos-proto/cmd/protoc-gen-go-pulsar",
// grpc-gateway plugins.
"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway",
"github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2",
// goimports
"golang.org/x/tools/cmd/goimports",
}
}
// InstallDepTools installs protoc dependencies needed by Cosmos ecosystem.
func InstallDepTools(ctx context.Context, appPath string) error {
if err := gocmd.ModTidy(ctx, appPath); err != nil {
return err
}
err := gocmd.Install(ctx, appPath, DepTools())
if gocmd.IsInstallError(err) {
return errors.New("unable to install dependency tools, run `ignite doctor` and try again")
}
return err
}
// MissingTools find missing tools import indo a *ast.File.
func MissingTools(f *ast.File) (missingTools []string) {
imports := make(map[string]string)
for name, imp := range goanalysis.FormatImports(f) {
imports[imp] = name
}
for _, tool := range DepTools() {
if _, ok := imports[tool]; !ok {
missingTools = append(missingTools, tool)
}
}
return
}
// UnusedTools find unused tools import indo a *ast.File.
func UnusedTools(f *ast.File) (unusedTools []string) {
unused := []string{
// regen protoc plugin
"github.com/regen-network/cosmos-proto/protoc-gen-gocosmos",
// old ignite repo.
"github.com/ignite-hq/cli/ignite/pkg/cmdrunner",
"github.com/ignite-hq/cli/ignite/pkg/cmdrunner/step",
}
imports := make(map[string]string)
for name, imp := range goanalysis.FormatImports(f) {
imports[imp] = name
}
for _, tool := range unused {
if _, ok := imports[tool]; ok {
unusedTools = append(unusedTools, tool)
}
}
return
}