Skip to content

Commit 944c604

Browse files
committed
/utils/doltgres_builder: kinda working
1 parent ed1b72d commit 944c604

File tree

2 files changed

+28
-33
lines changed

2 files changed

+28
-33
lines changed

Diff for: utils/doltgres_builder/cmd/main.go

+13-21
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"context"
5-
"flag"
65
"fmt"
76
"log"
87
"os"
@@ -11,30 +10,23 @@ import (
1110
)
1211

1312
func main() {
14-
flag.Parse()
15-
if len(os.Args) < 1 {
16-
printHelpAndExit()
17-
}
18-
parserScriptPath := os.Args[1]
19-
commitList := os.Args[2:]
13+
commitList := os.Args[1:]
2014
if len(commitList) < 1 {
21-
printHelpAndExit()
15+
helpStr := "doltgres-builder takes DoltgreSQL commit shas or tags as arguments\n" +
16+
"and builds corresponding binaries to a path specified\n" +
17+
"by DOLTGRES_BIN\n" +
18+
"If DOLTGRES_BIN is not set, ./doltgresBin will be used\n" +
19+
"usage: doltgres-builder dccba46 4bad226 ...\n" +
20+
"usage: doltgres-builder v0.19.0 v0.22.6 ...\n" +
21+
"set DEBUG=1 to run in debug mode\n"
22+
fmt.Print(helpStr)
23+
os.Exit(2)
2224
}
23-
err := builder.Run(context.Background(), parserScriptPath, commitList)
25+
26+
err := builder.Run(context.Background(), commitList)
2427
if err != nil {
2528
log.Fatal(err)
2629
}
27-
os.Exit(0)
28-
}
2930

30-
func printHelpAndExit() {
31-
helpStr := "doltgres-builder takes DoltgreSQL commit shas or tags as arguments\n" +
32-
"and builds corresponding binaries to a path specified\n" +
33-
"by DOLTGRES_BIN\n" +
34-
"If DOLTGRES_BIN is not set, ./doltgresBin will be used\n" +
35-
"usage: doltgres-builder /path/to/parser/build/script dccba46 4bad226 ...\n" +
36-
"usage: doltgres-builder /path/to/parser/build/script v0.19.0 v0.22.6 ...\n" +
37-
"set DEBUG=1 to run in debug mode\n"
38-
fmt.Print(helpStr)
39-
os.Exit(2)
31+
os.Exit(0)
4032
}

Diff for: utils/doltgres_builder/run.go

+15-12
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@ package doltgres_builder
33
import (
44
"context"
55
"fmt"
6-
builder "github.com/dolthub/dolt/go/performance/utils/dolt_builder"
7-
"golang.org/x/sync/errgroup"
86
"os"
97
"os/signal"
108
"path/filepath"
119
"runtime"
1210
"sync"
1311
"syscall"
12+
13+
builder "github.com/dolthub/dolt/go/performance/utils/dolt_builder"
14+
"golang.org/x/sync/errgroup"
1415
)
1516

1617
const envDoltgresBin = "DOLTGRES_BIN"
1718

18-
func Run(parentCtx context.Context, parserScriptPath string, commitList []string) error {
19+
func Run(parentCtx context.Context, commitList []string) error {
1920
doltgresBin, err := getDoltgresBin()
2021
if err != nil {
2122
return err
@@ -65,7 +66,7 @@ func Run(parentCtx context.Context, parserScriptPath string, commitList []string
6566
for _, commit := range commitList {
6667
commit := commit // https://golang.org/doc/faq#closures_and_goroutines
6768
g.Go(func() error {
68-
return buildBinaries(ctx, parserScriptPath, tempDir, repoDir, doltgresBin, commit)
69+
return buildBinaries(ctx, tempDir, repoDir, doltgresBin, commit)
6970
})
7071
}
7172

@@ -113,8 +114,8 @@ func getDoltgresBin() (string, error) {
113114
return doltgresBin, nil
114115
}
115116

116-
// buildBinaries builds a dolt binary at the given commit and stores it in the doltBin
117-
func buildBinaries(ctx context.Context, parserScriptPath, tempDir, repoDir, doltBinDir, commit string) error {
117+
// buildBinaries builds a doltgres binary at the given commit and stores it in the doltgresBin
118+
func buildBinaries(ctx context.Context, tempDir, repoDir, doltgresBinDir, commit string) error {
118119
checkoutDir := filepath.Join(tempDir, commit)
119120
if err := os.MkdirAll(checkoutDir, os.ModePerm); err != nil {
120121
return err
@@ -125,11 +126,13 @@ func buildBinaries(ctx context.Context, parserScriptPath, tempDir, repoDir, dolt
125126
return err
126127
}
127128

128-
commitDir := filepath.Join(doltBinDir, commit)
129+
commitDir := filepath.Join(doltgresBinDir, commit)
129130
if err := os.MkdirAll(commitDir, os.ModePerm); err != nil {
130131
return err
131132
}
132133

134+
parserScriptPath := filepath.Join(checkoutDir, "postgres", "parser", "build.sh")
135+
133136
command, err := goBuild(ctx, parserScriptPath, checkoutDir, commitDir)
134137
if err != nil {
135138
return err
@@ -162,9 +165,9 @@ func goBuild(ctx context.Context, parserScriptPath, source, dest string) (string
162165

163166
// doltgresVersion prints doltgres version of binary
164167
func doltgresVersion(ctx context.Context, dir, command string) error {
165-
doltVersion := builder.ExecCommand(ctx, command, "version")
166-
doltVersion.Stderr = os.Stderr
167-
doltVersion.Stdout = os.Stdout
168-
doltVersion.Dir = dir
169-
return doltVersion.Run()
168+
doltgresVersion := builder.ExecCommand(ctx, command, "version")
169+
doltgresVersion.Stderr = os.Stderr
170+
doltgresVersion.Stdout = os.Stdout
171+
doltgresVersion.Dir = dir
172+
return doltgresVersion.Run()
170173
}

0 commit comments

Comments
 (0)