list.go raw

   1  package loader
   2  
   3  import (
   4  	"os"
   5  	"os/exec"
   6  	"path/filepath"
   7  	"strings"
   8  
   9  	"moxie/compileopts"
  10  	"moxie/goenv"
  11  )
  12  
  13  // List returns a ready-to-run *exec.Cmd for running the `go list` command with
  14  // the configuration used for Moxie.
  15  func List(config *compileopts.Config, extraArgs, pkgs []string) (*exec.Cmd, error) {
  16  	goroot, err := GetCachedGoroot(config)
  17  	if err != nil {
  18  		return nil, err
  19  	}
  20  	args := append([]string{"list"}, extraArgs...)
  21  	if len(config.BuildTags()) != 0 {
  22  		args = append(args, "-tags", strings.Join(config.BuildTags(), " "))
  23  	}
  24  	args = append(args, pkgs...)
  25  	cmd := exec.Command(filepath.Join(goenv.Get("GOROOT"), "bin", "go"), args...)
  26  	cmd.Env = append(os.Environ(), "GOROOT="+goroot, "GOOS="+config.GOOS(), "GOARCH="+config.GOARCH(), "CGO_ENABLED=1")
  27  	if config.Options.Directory != "" {
  28  		cmd.Dir = config.Options.Directory
  29  	}
  30  	return cmd, nil
  31  }
  32