MCPcopy Create free account
hub / github.com/ddev/ddev / ResolveDdevBinary

Function ResolveDdevBinary

pkg/testsetup/ddevbin.go:17–47  ·  view source on GitHub ↗

ResolveDdevBinary returns the DDEV binary that tests should execute. If DDEV_BINARY_FULLPATH is set, it is used directly. Otherwise the binary is built from source via `make`.

()

Source from the content-addressed store, hash-verified

15// If DDEV_BINARY_FULLPATH is set, it is used directly. Otherwise the binary
16// is built from source via `make`.
17func ResolveDdevBinary() (string, error) {
18 if bin := os.Getenv("DDEV_BINARY_FULLPATH"); bin != "" {
19 if !fileutil.FileExists(bin) {
20 return "", fmt.Errorf("DDEV_BINARY_FULLPATH=%s does not exist", bin)
21 }
22 return bin, nil
23 }
24
25 repoRoot, err := findRepoRoot()
26 if err != nil {
27 return "", fmt.Errorf("failed to locate repository root: %w", err)
28 }
29
30 binaryName := "ddev"
31 if runtime.GOOS == "windows" {
32 binaryName += ".exe"
33 }
34 binaryPath := filepath.Join(repoRoot, ".gotmp", "bin", runtime.GOOS+"_"+runtime.GOARCH, binaryName)
35
36 cmd := osexec.Command("make")
37 cmd.Dir = repoRoot
38 cmd.Stdout = os.Stdout
39 cmd.Stderr = os.Stderr
40 if err := cmd.Run(); err != nil {
41 return "", fmt.Errorf("`make` failed: %w", err)
42 }
43 if !fileutil.FileExists(binaryPath) {
44 return "", fmt.Errorf("`make` succeeded but %s was not found", binaryPath)
45 }
46 return binaryPath, nil
47}
48
49// MustResolveDdevBinary returns the test DDEV binary or aborts the current test process.
50func MustResolveDdevBinary() string {

Callers 1

MustResolveDdevBinaryFunction · 0.85

Calls 4

FileExistsFunction · 0.92
findRepoRootFunction · 0.85
ErrorfMethod · 0.80
CommandMethod · 0.80

Tested by

no test coverage detected