github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/loader/list.go (about) 1 package loader 2 3 import ( 4 "os" 5 "os/exec" 6 "path/filepath" 7 "strings" 8 9 "github.com/tinygo-org/tinygo/compileopts" 10 "github.com/tinygo-org/tinygo/goenv" 11 ) 12 13 // List returns a ready-to-run *exec.Cmd for running the `go list` command with 14 // the configuration used for TinyGo. 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 }