From f5b60801a5a706984571bdc25cc228be793f61e0 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Thu, 29 Nov 2018 15:13:37 +0100 Subject: [PATCH] integration/rpctest: make exec path compatible with modules With the use of go modules, the btcdPkgPath will no longer be `github.com/btcsuite/btcd`, but end with a version string (e.g. btcd@v0.0.0-20181129140220-beb77e89572a). This trips up build.ImportDir, which will return a ImportPath of ".", since this package cannot be found in the go path. There are probably several ways of fixing this, by clever string magic, but seems easiest to just hardcode the btcd package name. --- integration/rpctest/btcd.go | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/integration/rpctest/btcd.go b/integration/rpctest/btcd.go index 3c875197..29642c84 100644 --- a/integration/rpctest/btcd.go +++ b/integration/rpctest/btcd.go @@ -6,7 +6,6 @@ package rpctest import ( "fmt" - "go/build" "os/exec" "path/filepath" "runtime" @@ -44,24 +43,14 @@ func btcdExecutablePath() (string, error) { return "", err } - // Determine import path of this package. Not necessarily btcsuite/btcd if - // this is a forked repo. - _, rpctestDir, _, ok := runtime.Caller(1) - if !ok { - return "", fmt.Errorf("Cannot get path to btcd source code") - } - btcdPkgPath := filepath.Join(rpctestDir, "..", "..", "..") - btcdPkg, err := build.ImportDir(btcdPkgPath, build.FindOnly) - if err != nil { - return "", fmt.Errorf("Failed to build btcd: %v", err) - } - // Build btcd and output an executable in a static temp path. outputPath := filepath.Join(testDir, "btcd") if runtime.GOOS == "windows" { outputPath += ".exe" } - cmd := exec.Command("go", "build", "-o", outputPath, btcdPkg.ImportPath) + cmd := exec.Command( + "go", "build", "-o", outputPath, "github.com/btcsuite/btcd", + ) err = cmd.Run() if err != nil { return "", fmt.Errorf("Failed to build btcd: %v", err)