Skip to content

Commit

Permalink
/utils/doltgres_builder: kinda working
Browse files Browse the repository at this point in the history
  • Loading branch information
coffeegoddd committed Jan 5, 2024
1 parent ed1b72d commit 944c604
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 33 deletions.
34 changes: 13 additions & 21 deletions utils/doltgres_builder/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"
"flag"
"fmt"
"log"
"os"
Expand All @@ -11,30 +10,23 @@ import (
)

func main() {
flag.Parse()
if len(os.Args) < 1 {
printHelpAndExit()
}
parserScriptPath := os.Args[1]
commitList := os.Args[2:]
commitList := os.Args[1:]
if len(commitList) < 1 {
printHelpAndExit()
helpStr := "doltgres-builder takes DoltgreSQL commit shas or tags as arguments\n" +
"and builds corresponding binaries to a path specified\n" +
"by DOLTGRES_BIN\n" +
"If DOLTGRES_BIN is not set, ./doltgresBin will be used\n" +
"usage: doltgres-builder dccba46 4bad226 ...\n" +
"usage: doltgres-builder v0.19.0 v0.22.6 ...\n" +
"set DEBUG=1 to run in debug mode\n"
fmt.Print(helpStr)
os.Exit(2)
}
err := builder.Run(context.Background(), parserScriptPath, commitList)

err := builder.Run(context.Background(), commitList)
if err != nil {
log.Fatal(err)
}
os.Exit(0)
}

func printHelpAndExit() {
helpStr := "doltgres-builder takes DoltgreSQL commit shas or tags as arguments\n" +
"and builds corresponding binaries to a path specified\n" +
"by DOLTGRES_BIN\n" +
"If DOLTGRES_BIN is not set, ./doltgresBin will be used\n" +
"usage: doltgres-builder /path/to/parser/build/script dccba46 4bad226 ...\n" +
"usage: doltgres-builder /path/to/parser/build/script v0.19.0 v0.22.6 ...\n" +
"set DEBUG=1 to run in debug mode\n"
fmt.Print(helpStr)
os.Exit(2)
os.Exit(0)
}
27 changes: 15 additions & 12 deletions utils/doltgres_builder/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ package doltgres_builder
import (
"context"
"fmt"
builder "github.com/dolthub/dolt/go/performance/utils/dolt_builder"
"golang.org/x/sync/errgroup"
"os"
"os/signal"
"path/filepath"
"runtime"
"sync"
"syscall"

builder "github.com/dolthub/dolt/go/performance/utils/dolt_builder"
"golang.org/x/sync/errgroup"
)

const envDoltgresBin = "DOLTGRES_BIN"

func Run(parentCtx context.Context, parserScriptPath string, commitList []string) error {
func Run(parentCtx context.Context, commitList []string) error {
doltgresBin, err := getDoltgresBin()
if err != nil {
return err
Expand Down Expand Up @@ -65,7 +66,7 @@ func Run(parentCtx context.Context, parserScriptPath string, commitList []string
for _, commit := range commitList {
commit := commit // https://golang.org/doc/faq#closures_and_goroutines
g.Go(func() error {
return buildBinaries(ctx, parserScriptPath, tempDir, repoDir, doltgresBin, commit)
return buildBinaries(ctx, tempDir, repoDir, doltgresBin, commit)
})
}

Expand Down Expand Up @@ -113,8 +114,8 @@ func getDoltgresBin() (string, error) {
return doltgresBin, nil
}

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

commitDir := filepath.Join(doltBinDir, commit)
commitDir := filepath.Join(doltgresBinDir, commit)
if err := os.MkdirAll(commitDir, os.ModePerm); err != nil {
return err
}

parserScriptPath := filepath.Join(checkoutDir, "postgres", "parser", "build.sh")

command, err := goBuild(ctx, parserScriptPath, checkoutDir, commitDir)
if err != nil {
return err
Expand Down Expand Up @@ -162,9 +165,9 @@ func goBuild(ctx context.Context, parserScriptPath, source, dest string) (string

// doltgresVersion prints doltgres version of binary
func doltgresVersion(ctx context.Context, dir, command string) error {
doltVersion := builder.ExecCommand(ctx, command, "version")
doltVersion.Stderr = os.Stderr
doltVersion.Stdout = os.Stdout
doltVersion.Dir = dir
return doltVersion.Run()
doltgresVersion := builder.ExecCommand(ctx, command, "version")
doltgresVersion.Stderr = os.Stderr
doltgresVersion.Stdout = os.Stdout
doltgresVersion.Dir = dir
return doltgresVersion.Run()
}

0 comments on commit 944c604

Please sign in to comment.