mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-01 17:47:46 +00:00
c810628a20
There were a few problems with the go/packages package. While it is more
or less designed for our purpose, it didn't work quite well as it didn't
provide access to indirectly imported packages (most importantly the
runtime package). This led to a workaround that sometimes broke
`tinygo test`.
This PR contains a number of related changes:
* It uses `go list` directly to retrieve the list of packages/files to
compile, instead of relying on the go/packages package.
* It replaces our custom TestMain replace code with the standard code
for running tests (generated by `go list`).
* It adds a dummy runtime/pprof package and modifies the testing
package, to get tests to run again with the code generated by
`go list`.
31 lines
817 B
Go
31 lines
817 B
Go
package loader
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
|
|
"github.com/tinygo-org/tinygo/compileopts"
|
|
)
|
|
|
|
// List returns a ready-to-run *exec.Cmd for running the `go list` command with
|
|
// the configuration used for TinyGo.
|
|
func List(config *compileopts.Config, extraArgs, pkgs []string) (*exec.Cmd, error) {
|
|
goroot, err := GetCachedGoroot(config)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
args := append([]string{"list"}, extraArgs...)
|
|
if len(config.BuildTags()) != 0 {
|
|
args = append(args, "-tags", strings.Join(config.BuildTags(), " "))
|
|
}
|
|
args = append(args, pkgs...)
|
|
cgoEnabled := "0"
|
|
if config.CgoEnabled() {
|
|
cgoEnabled = "1"
|
|
}
|
|
cmd := exec.Command("go", args...)
|
|
cmd.Env = append(os.Environ(), "GOROOT="+goroot, "GOOS="+config.GOOS(), "GOARCH="+config.GOARCH(), "CGO_ENABLED="+cgoEnabled)
|
|
return cmd, nil
|
|
}
|