Skip to content

Commit

Permalink
Merge pull request #6 from foxcpp/master
Browse files Browse the repository at this point in the history
Don't use /bin/sh to wrap commands
  • Loading branch information
jondot authored Mar 30, 2019
2 parents effaf26 + bdacadf commit d86d47d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func main() {
kingpin.Parse()
weight := pkg.NewGoWeight()
if *buildTags != "" {
weight.BuildArgs = "-tags " + *buildTags
weight.BuildCmd = append(weight.BuildCmd, "-tags", *buildTags)
}

work := weight.BuildCurrent()
Expand Down
13 changes: 8 additions & 5 deletions pkg/goweight.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (

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

func run(cmd string) string {
out, err := exec.Command("sh", "-c", cmd).Output()
func run(cmd []string) string {
out, err := exec.Command(cmd[0], cmd[1:]...).CombinedOutput()
if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -48,16 +48,19 @@ type ModuleEntry struct {
SizeHuman string `json:"size_human"`
}
type GoWeight struct {
BuildArgs string
BuildCmd []string
}

func NewGoWeight() *GoWeight {
return &GoWeight{}
return &GoWeight{
BuildCmd: []string{"go", "build","-o", "goweight-bin-target", "-work", "-a"},
}
}

func (g *GoWeight) BuildCurrent() string {
return strings.Split(strings.TrimSpace(run("go build -o goweight-bin-target "+g.BuildArgs+" -work -a 2>&1 && rm goweight-bin-target")), "=")[1]
return strings.Split(strings.TrimSpace(run(g.BuildCmd)), "=")[1]
}

func (g *GoWeight) Process(work string) []*ModuleEntry {

files, err := zglob.Glob(work + "**/importcfg")
Expand Down

0 comments on commit d86d47d

Please sign in to comment.