MCPcopy
hub / github.com/dgraph-io/dgraph / setupBinary

Method setupBinary

dgraphtest/image.go:46–124  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

44//
45// Both are produced by "make install".
46func (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

Callers 2

setupBeforeClusterMethod · 0.95
mountBinaryFunction · 0.80

Calls 10

GeneratePluginsMethod · 0.95
ensureDgraphCloneFunction · 0.85
copyBinaryFunction · 0.85
copyFileFunction · 0.85
runGitCheckoutFunction · 0.85
buildDgraphBinaryFunction · 0.85
fileExistsFunction · 0.70
GetMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected