Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## `v0.16.1`

### Features:

- Ensure that CLI operates fine even if installation directory (bin) of Go programs is not configured properly.

## `v0.16.0`

### Features:
Expand Down
4 changes: 4 additions & 0 deletions starport/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
flag "github.com/spf13/pflag"
"github.com/tendermint/starport/starport/pkg/clispinner"
"github.com/tendermint/starport/starport/pkg/events"
"github.com/tendermint/starport/starport/pkg/goenv"
"github.com/tendermint/starport/starport/services/chain"
"github.com/tendermint/starport/starport/services/networkbuilder"
)
Expand All @@ -28,6 +29,9 @@ func New() *cobra.Command {
Short: "A developer tool for building Cosmos SDK blockchains",
SilenceUsage: true,
SilenceErrors: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return goenv.ConfigurePath()
},
}
c.AddCommand(NewDocs())
c.AddCommand(NewApp())
Expand Down
4 changes: 1 addition & 3 deletions starport/pkg/cmdrunner/cmdrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,7 @@ func (r *Runner) newCommand(step *step.Step) Executor {
command.Stderr = stderr
command.Dir = dir
command.Env = append(os.Environ(), step.Env...)
command.Env = append(command.Env, os.ExpandEnv(
fmt.Sprintf("PATH=$PATH:%s", goenv.GetGOBIN()),
))
command.Env = append(command.Env, fmt.Sprintf("PATH=%s", goenv.Path()))

// If a custom stdin is provided it will be as the stdin for the command
if stdin != nil {
Expand Down
27 changes: 24 additions & 3 deletions starport/pkg/goenv/goenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package goenv

import (
"fmt"
"go/build"
"os"
"path/filepath"
Expand All @@ -10,12 +11,32 @@ import (
const (
// GOBIN is the env var for GOBIN.
GOBIN = "GOBIN"

// GOPATH is the env var for GOPATH.
GOPATH = "GOPATH"
)

// GetGOBIN returns the path of where Go binaries are installed.
func GetGOBIN() string {
const (
binDir = "bin"
)

// Bin returns the path of where Go binaries are installed.
func Bin() string {
if binPath := os.Getenv(GOBIN); binPath != "" {
return binPath
}
return filepath.Join(build.Default.GOPATH, "bin")
if goPath := os.Getenv(GOPATH); goPath != "" {
return filepath.Join(goPath, binDir)
}
return filepath.Join(build.Default.GOPATH, binDir)
}

// Path returns $PATH with correct go bin configuration set.
func Path() string {
return os.ExpandEnv(fmt.Sprintf("$PATH:%s", Bin()))
}

// ConfigurePath configures the env with correct $PATH that has go bin setup.
func ConfigurePath() error {
return os.Setenv("PATH", Path())
}
2 changes: 1 addition & 1 deletion starport/services/chain/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (c *Chain) buildSteps() (steps step.Steps, err error) {
))

addInstallStep := func(binaryName, mainPath string) {
installPath := filepath.Join(goenv.GetGOBIN(), binaryName)
installPath := filepath.Join(goenv.Bin(), binaryName)

steps.Add(step.New(step.NewOptions().
Add(
Expand Down