Skip to content

Commit

Permalink
feat: add GNOROOT environment variables
Browse files Browse the repository at this point in the history
Adds the ability to obtain the root directory from the GNOROOT environment variable. If this variable is not set, the root directory is then guessed using the go list command.

Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com>
  • Loading branch information
gfanton committed Aug 2, 2023
1 parent 3ade982 commit 844d58c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion gnovm/cmd/gno/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,16 @@ func fmtDuration(d time.Duration) string {
}

func guessRootDir() string {
// try to get the root directory from the GNOROOT environment variable.
if rootdir := os.Getenv("GNOROOT"); rootdir != "" {
return filepath.Clean(rootdir)
}

// if GNOROOT is not set, try to guess the root directory using the `go list` command.
cmd := exec.Command("go", "list", "-m", "-mod=mod", "-f", "{{.Dir}}", "github.com/gnolang/gno")
out, err := cmd.CombinedOutput()
if err != nil {
log.Fatal("can't guess --root-dir, please fill it manually.")
log.Fatal("can't guess --root-dir, please fill it manually or define the GNOROOT environment variable globally.")
}
rootDir := strings.TrimSpace(string(out))
return rootDir
Expand Down

0 comments on commit 844d58c

Please sign in to comment.