From 367d7151ce25bce7137de4cb436d5017f1f53c24 Mon Sep 17 00:00:00 2001 From: gfanton <8671905+gfanton@users.noreply.github.com> Date: Tue, 1 Aug 2023 19:35:15 +0200 Subject: [PATCH] feat: add GNO_ROOT_DIR environment variables This PR adds the ability to obtain the root directory from the GNO_ROOT_DIR 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> --- gnovm/cmd/gno/util.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gnovm/cmd/gno/util.go b/gnovm/cmd/gno/util.go index 1bbdb968c45..3de742d2a5a 100644 --- a/gnovm/cmd/gno/util.go +++ b/gnovm/cmd/gno/util.go @@ -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