-
Notifications
You must be signed in to change notification settings - Fork 2
/
btcd.go
63 lines (53 loc) · 1.75 KB
/
btcd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) 2017 The btcsuite developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package rpctest
import (
"os/exec"
"path/filepath"
"runtime"
"sync"
"github.com/pkt-cash/PKT-FullNode/btcutil/er"
)
var (
// compileMtx guards access to the executable path so that the project is
// only compiled once.
compileMtx sync.Mutex
// executablePath is the path to the compiled executable. This is the empty
// string until pktd is compiled. This should not be accessed directly;
// instead use the function pktdExecutablePath().
executablePath string
)
// pktdExecutablePath returns a path to the pktd executable to be used by
// rpctests. To ensure the code tests against the most up-to-date version of
// pktd, this method compiles pktd the first time it is called. After that, the
// generated binary is used for subsequent test harnesses. The executable file
// is not cleaned up, but since it lives at a static path in a temp directory,
// it is not a big deal.
func pktdExecutablePath() (string, er.R) {
compileMtx.Lock()
defer compileMtx.Unlock()
// If pktd has already been compiled, just use that.
if len(executablePath) != 0 {
return executablePath, nil
}
testDir, err := baseDir()
if err != nil {
return "", err
}
// Build pktd and output an executable in a static temp path.
outputPath := filepath.Join(testDir, "pktd")
if runtime.GOOS == "windows" {
outputPath += ".exe"
}
cmd := exec.Command(
"go", "build", "-o", outputPath, "github.com/pkt-cash/PKT-FullNode",
)
err = er.E(cmd.Run())
if err != nil {
return "", er.Errorf("Failed to build pktd: %v", err)
}
// Save executable path so future calls do not recompile.
executablePath = outputPath
return executablePath, nil
}