Skip to content

Commit

Permalink
feat: pass environment to go compiler
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Stewart <christian@aperture.us>
  • Loading branch information
paralin committed Apr 10, 2024
1 parent 624b44a commit b2cada6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ vendor/
dist/
goweight
.vscode/
.aider*
11 changes: 6 additions & 5 deletions pkg/goweight.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package pkg

import (
"io/ioutil"
"log"
"os"
"os/exec"
Expand All @@ -16,8 +15,10 @@ import (

var moduleRegex = regexp.MustCompile("packagefile (.*)=(.*)")

func run(cmd []string) string {
out, err := exec.Command(cmd[0], cmd[1:]...).CombinedOutput()
func run(cmd []string, env []string) string {
c := exec.Command(cmd[0], cmd[1:]...)
c.Env = append(os.Environ(), env...)
out, err := c.CombinedOutput()
if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -59,7 +60,7 @@ func NewGoWeight() *GoWeight {
}

func (g *GoWeight) BuildCurrent() string {
d := strings.Split(strings.TrimSpace(run(g.BuildCmd)), "\n")[0]
d := strings.Split(strings.TrimSpace(run(g.BuildCmd, nil)), "\n")[0]
return strings.Split(strings.TrimSpace(d), "=")[1]
}

Expand All @@ -71,7 +72,7 @@ func (g *GoWeight) Process(work string) []*ModuleEntry {
}

allLines := funk.Uniq(funk.FlattenDeep(funk.Map(files, func(file string) []string {
f, err := ioutil.ReadFile(file)
f, err := os.ReadFile(file)
if err != nil {
return []string{}
}
Expand Down

0 comments on commit b2cada6

Please sign in to comment.