Skip to content

Commit

Permalink
fix(softfloat/gen): add gitRoot function to determine repository root…
Browse files Browse the repository at this point in the history
… path
  • Loading branch information
omarsy committed Jan 27, 2025
1 parent ae874a2 commit 4ecec67
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions gnovm/pkg/gnolang/internal/softfloat/gen/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"fmt"
"log"
"os"
Expand Down Expand Up @@ -82,13 +83,32 @@ func processSoftFloat64TestFile() {
}
}

func gitRoot() (string, error) {
wd, err := os.Getwd()
if err != nil {
return "", err
}
p := wd
for {
if s, e := os.Stat(filepath.Join(p, ".git")); e == nil && s.IsDir() {
return p, nil
}

if strings.HasSuffix(p, string(filepath.Separator)) {
return "", errors.New("root git not found")
}

p = filepath.Dir(p)
}
}

func gofumpt() {
rootPath, err := exec.Command("git", "rev-parse", "--show-toplevel").Output()
rootPath, err := gitRoot()
if err != nil {
log.Fatal("error git rev-parse:", err)
log.Fatal("error finding git root:", err)
}

cmd := exec.Command("go", "run", "-modfile", filepath.Join(strings.TrimSpace(string(rootPath)), "misc/devdeps/go.mod"), "mvdan.cc/gofumpt", "-w", ".")
cmd := exec.Command("go", "run", "-modfile", filepath.Join(strings.TrimSpace(rootPath), "misc/devdeps/go.mod"), "mvdan.cc/gofumpt", "-w", ".")
_, err = cmd.Output()
if err != nil {
log.Fatal("error gofumpt:", err)
Expand Down

0 comments on commit 4ecec67

Please sign in to comment.