aboutsummaryrefslogtreecommitdiff
path: root/go/packages/packagestest/modules.go
diff options
context:
space:
mode:
Diffstat (limited to 'go/packages/packagestest/modules.go')
-rw-r--r--go/packages/packagestest/modules.go28
1 files changed, 10 insertions, 18 deletions
diff --git a/go/packages/packagestest/modules.go b/go/packages/packagestest/modules.go
index e393cdca0..8bf830ad4 100644
--- a/go/packages/packagestest/modules.go
+++ b/go/packages/packagestest/modules.go
@@ -6,17 +6,16 @@ package packagestest
import (
"archive/zip"
- "bytes"
+ "context"
"fmt"
"io/ioutil"
"os"
- "os/exec"
"path"
"path/filepath"
"regexp"
"strings"
- "golang.org/x/tools/go/packages"
+ "golang.org/x/tools/internal/gocommand"
)
// Modules is the exporter that produces module layouts.
@@ -170,7 +169,14 @@ func (modules) Finalize(exported *Exported) error {
// Run go mod download to recreate the mod cache dir with all the extra
// stuff in cache. All the files created by Export should be recreated.
- if err := invokeGo(exported.Config, "mod", "download"); err != nil {
+ inv := gocommand.Invocation{
+ Verb: "mod",
+ Args: []string{"download"},
+ Env: exported.Config.Env,
+ BuildFlags: exported.Config.BuildFlags,
+ WorkingDir: exported.Config.Dir,
+ }
+ if _, err := inv.Run(context.Background()); err != nil {
return err
}
return nil
@@ -237,20 +243,6 @@ func writeModuleProxy(dir, module, ver string, files map[string]string) error {
return nil
}
-func invokeGo(cfg *packages.Config, args ...string) error {
- stdout := new(bytes.Buffer)
- stderr := new(bytes.Buffer)
- cmd := exec.Command("go", args...)
- cmd.Env = append(append([]string{}, cfg.Env...), "PWD="+cfg.Dir)
- cmd.Dir = cfg.Dir
- cmd.Stdout = stdout
- cmd.Stderr = stderr
- if err := cmd.Run(); err != nil {
- return fmt.Errorf("go %v: %s: %s", args, err, stderr)
- }
- return nil
-}
-
func modCache(exported *Exported) string {
return filepath.Join(exported.temp, "modcache/pkg/mod")
}