setupBinary sets up dgraph binaries in tempBinDir. On Linux a single "dgraph" binary from $GOPATH/bin serves both Docker containers and local commands (bulk/live loader). On non-Linux (macOS) two binaries are placed in tempBinDir: - "dgraph" – a Linux binary for Docker containers, from $GOPAT
()
| 44 | // |
| 45 | // Both are produced by "make install". |
| 46 | func (c *LocalCluster) setupBinary() error { |
| 47 | if err := ensureDgraphClone(); err != nil { |
| 48 | panic(err) |
| 49 | } |
| 50 | |
| 51 | if c.conf.customPlugins { |
| 52 | race := false // Explicit var declaration to avoid confusion on the next line |
| 53 | if err := c.GeneratePlugins(race); err != nil { |
| 54 | return err |
| 55 | } |
| 56 | } |
| 57 | if c.conf.version == localVersion { |
| 58 | gopath := os.Getenv("GOPATH") |
| 59 | if gopath == "" { |
| 60 | return errors.New("GOPATH is not set") |
| 61 | } |
| 62 | |
| 63 | if handled, err := SetupLinuxBinaries(c.tempBinDir, c.conf.version); handled { |
| 64 | return err |
| 65 | } |
| 66 | |
| 67 | if runtime.GOOS == "linux" { |
| 68 | // On Linux $GOPATH/bin/dgraph is both the native and Docker binary. |
| 69 | return copyBinary(filepath.Join(gopath, "bin"), c.tempBinDir, c.conf.version) |
| 70 | } |
| 71 | |
| 72 | // Non-Linux (macOS): need separate Linux and host-native binaries. |
| 73 | // 1. Copy the Linux binary (for Docker containers) as "dgraph". |
| 74 | linuxDir := os.Getenv("LINUX_GOBIN") |
| 75 | if linuxDir == "" { |
| 76 | linuxDir = filepath.Join(gopath, "linux_"+runtime.GOARCH) |
| 77 | } |
| 78 | if err := copyBinary(linuxDir, c.tempBinDir, c.conf.version); err != nil { |
| 79 | return err |
| 80 | } |
| 81 | |
| 82 | // 2. Copy the host-native binary (for local bulk/live commands) as |
| 83 | // hostBinaryFileName (see load.go). |
| 84 | hostSrc := filepath.Join(gopath, "bin", buildvars.BinaryName.Get()) |
| 85 | |
| 86 | hostDst := filepath.Join(c.tempBinDir, hostBinaryFileName) |
| 87 | if err := copyFile(hostSrc, hostDst); err != nil { |
| 88 | return errors.Wrapf(err, "error copying host-native binary from [%v] to [%v]", hostSrc, hostDst) |
| 89 | } |
| 90 | return nil |
| 91 | } |
| 92 | |
| 93 | binaryPath := filepath.Join(binariesPath, fmt.Sprintf(binaryNameFmt, c.conf.version)) |
| 94 | |
| 95 | // First check without lock (fast path) |
| 96 | isFileThere, err := fileExists(binaryPath) |
| 97 | if err != nil { |
| 98 | return err |
| 99 | } |
| 100 | if isFileThere { |
| 101 | return copyBinary(binariesPath, c.tempBinDir, c.conf.version) |
| 102 | } |
| 103 |
no test coverage detected