Skip to content

Commit

Permalink
Clean-up.
Browse files Browse the repository at this point in the history
  • Loading branch information
udhos committed Jun 6, 2020
1 parent acd440b commit 2cff6af
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions basc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,21 @@ func gofmt(output string) error {
return cmd.Run()
}

func gomodinit(dir string) error {
_, err := os.Stat("go.mod")
if err == nil {
log.Printf("%s: build: go.mod exists in dir: %s", me, dir)
return nil
}

cmdModInit := exec.Command("go", "mod", "init", dir)
cmdModInit.Stdin = os.Stdin
cmdModInit.Stdout = os.Stdout
cmdModInit.Stderr = os.Stderr

return cmdModInit.Run()
}

func buildGo(dir, baslibModule string, getFlags []string, output string) error {
log.Printf("%s: build: dir=%s baslibModule=%s output=%s", me, dir, baslibModule, output)
log.Printf("%s: build: entering dir=%s", me, dir)
Expand All @@ -184,19 +199,19 @@ func buildGo(dir, baslibModule string, getFlags []string, output string) error {
return errChdir
}

_, err := os.Stat("go.mod")
if os.IsNotExist(err) {
cmdModInit := exec.Command("go", "mod", "init", dir)
cmdModInit.Stdin = os.Stdin
cmdModInit.Stdout = os.Stdout
cmdModInit.Stderr = os.Stderr
if errModInit := cmdModInit.Run(); errModInit != nil {
return errModInit
}
} else {
log.Printf("%s: build: go.mod exists", me)
//
// go mod init dir
//

errModInit := gomodinit(dir)
if errModInit != nil {
return errModInit
}

//
// go get baslibModule
//

args := []string{"get"}
args = append(args, getFlags...)
args = append(args, baslibModule)
Expand All @@ -209,6 +224,10 @@ func buildGo(dir, baslibModule string, getFlags []string, output string) error {
return errGet
}

//
// go build
//

args = []string{"build"}

if output != "" {
Expand Down

0 comments on commit 2cff6af

Please sign in to comment.