Skip to content

Commit bf62110

Browse files
committed
conflict
2 parents 0759801 + 561379f commit bf62110

File tree

8 files changed

+42
-12
lines changed

8 files changed

+42
-12
lines changed

changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66

77
- Added the flag `--no-default-module` to the command `starport app` to prevent scaffolding a default module when creating a new app
88

9+
## `v0.16.1`
10+
11+
### Features:
12+
13+
- Ensure that CLI operates fine even if the installation directory (bin) of Go programs is not configured properly.
14+
915
## `v0.16.0`
1016

1117
### Features:

starport/cmd/cmd.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
flag "github.com/spf13/pflag"
1010
"github.com/tendermint/starport/starport/pkg/clispinner"
1111
"github.com/tendermint/starport/starport/pkg/events"
12+
"github.com/tendermint/starport/starport/pkg/goenv"
1213
"github.com/tendermint/starport/starport/services/chain"
1314
"github.com/tendermint/starport/starport/services/networkbuilder"
1415
)
@@ -28,6 +29,9 @@ func New() *cobra.Command {
2829
Short: "A developer tool for building Cosmos SDK blockchains",
2930
SilenceUsage: true,
3031
SilenceErrors: true,
32+
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
33+
return goenv.ConfigurePath()
34+
},
3135
}
3236
c.AddCommand(NewDocs())
3337
c.AddCommand(NewApp())

starport/pkg/cmdrunner/cmdrunner.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,7 @@ func (r *Runner) newCommand(step *step.Step) Executor {
219219
command.Stderr = stderr
220220
command.Dir = dir
221221
command.Env = append(os.Environ(), step.Env...)
222-
command.Env = append(command.Env, os.ExpandEnv(
223-
fmt.Sprintf("PATH=$PATH:%s", goenv.GetGOBIN()),
224-
))
222+
command.Env = append(command.Env, fmt.Sprintf("PATH=%s", goenv.Path()))
225223

226224
// If a custom stdin is provided it will be as the stdin for the command
227225
if stdin != nil {

starport/pkg/goenv/goenv.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package goenv
33

44
import (
5+
"fmt"
56
"go/build"
67
"os"
78
"path/filepath"
@@ -10,12 +11,32 @@ import (
1011
const (
1112
// GOBIN is the env var for GOBIN.
1213
GOBIN = "GOBIN"
14+
15+
// GOPATH is the env var for GOPATH.
16+
GOPATH = "GOPATH"
1317
)
1418

15-
// GetGOBIN returns the path of where Go binaries are installed.
16-
func GetGOBIN() string {
19+
const (
20+
binDir = "bin"
21+
)
22+
23+
// Bin returns the path of where Go binaries are installed.
24+
func Bin() string {
1725
if binPath := os.Getenv(GOBIN); binPath != "" {
1826
return binPath
1927
}
20-
return filepath.Join(build.Default.GOPATH, "bin")
28+
if goPath := os.Getenv(GOPATH); goPath != "" {
29+
return filepath.Join(goPath, binDir)
30+
}
31+
return filepath.Join(build.Default.GOPATH, binDir)
32+
}
33+
34+
// Path returns $PATH with correct go bin configuration set.
35+
func Path() string {
36+
return os.ExpandEnv(fmt.Sprintf("$PATH:%s", Bin()))
37+
}
38+
39+
// ConfigurePath configures the env with correct $PATH that has go bin setup.
40+
func ConfigurePath() error {
41+
return os.Setenv("PATH", Path())
2142
}

starport/pkg/localfs/save.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ func SaveTemp(f fs.FS) (path string, cleanup func(), err error) {
2929
}
3030

3131
// SaveBytesTemp saves data bytes to a temporary file location at path.
32-
func SaveBytesTemp(data []byte, perm os.FileMode) (path string, cleanup func(), err error) {
33-
f, err := os.CreateTemp("", "")
32+
func SaveBytesTemp(data []byte, prefix string, perm os.FileMode) (path string, cleanup func(), err error) {
33+
f, err := os.CreateTemp("", prefix)
3434
if err != nil {
3535
return
3636
}

starport/pkg/nodetime/nodetime.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,14 @@ func Binary() []byte {
7171

7272
// Command setups the nodetime binary and returns the command needed to execute c.
7373
func Command(c CommandName) (command []string, cleanup func(), err error) {
74-
path, cleanup, err := localfs.SaveBytesTemp(Binary(), 0755)
74+
cs := string(c)
75+
path, cleanup, err := localfs.SaveBytesTemp(Binary(), cs, 0755)
7576
if err != nil {
7677
return nil, nil, err
7778
}
7879
command = []string{
7980
path,
80-
string(c),
81+
cs,
8182
}
8283
return command, cleanup, nil
8384
}

starport/pkg/protoc/protoc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func Generate(ctx context.Context, outDir, protoPath string, includePaths, proto
3939
}
4040

4141
// setup protoc and global protos.
42-
protocPath, cleanup, err := localfs.SaveBytesTemp(binary, 0755)
42+
protocPath, cleanup, err := localfs.SaveBytesTemp(binary, "protoc", 0755)
4343
if err != nil {
4444
return err
4545
}

starport/services/chain/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (c *Chain) buildSteps() (steps step.Steps, err error) {
112112
))
113113

114114
addInstallStep := func(binaryName, mainPath string) {
115-
installPath := filepath.Join(goenv.GetGOBIN(), binaryName)
115+
installPath := filepath.Join(goenv.Bin(), binaryName)
116116

117117
steps.Add(step.New(step.NewOptions().
118118
Add(

0 commit comments

Comments
 (0)