Skip to content

Commit 53c4ba1

Browse files
committed
feedback and tweaks
1 parent fa4b879 commit 53c4ba1

File tree

3 files changed

+45
-50
lines changed

3 files changed

+45
-50
lines changed

upgrade/upgrade.go

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,33 @@ import (
1010
"crypto/sha1"
1111
"encoding/hex"
1212
"errors"
13+
"flag"
1314
"fmt"
1415
"io"
1516
"io/ioutil"
1617
"log"
1718
"net/http"
1819
"os"
20+
"os/exec"
1921
"path/filepath"
2022
"strings"
2123
"time"
2224

2325
"github.com/PuerkitoBio/goquery"
2426
)
2527

26-
const buildFlags = "-DSQLITE_ENABLE_UPDATE_DELETE_LIMIT=1"
28+
var (
29+
cFlags = "-DSQLITE_ENABLE_UPDATE_DELETE_LIMIT=1"
30+
cleanup = true
31+
)
2732

2833
func main() {
34+
flag.StringVar(&shellPath, "shell", shellPath, "path to shell executable")
35+
flag.StringVar(&makePath, "make", makePath, "path to make executable")
36+
flag.StringVar(&cFlags, "cflags", cFlags, "sqlite CFLAGS")
37+
flag.BoolVar(&cleanup, "cleanup", cleanup, "cleanup source")
38+
flag.Parse()
39+
2940
err := func() error {
3041
fmt.Println("Go-SQLite3 Upgrade Tool")
3142

@@ -38,7 +49,7 @@ func main() {
3849

3950
// Extract Source
4051
baseDir, err := extractZip(source)
41-
if baseDir != "" && !filepath.IsAbs(baseDir) {
52+
if cleanup && baseDir != "" && !filepath.IsAbs(baseDir) {
4253
defer func() {
4354
fmt.Println("Cleaning up source: deleting", baseDir)
4455
os.RemoveAll(baseDir)
@@ -50,8 +61,8 @@ func main() {
5061
fmt.Println("Extracted sqlite source to", baseDir)
5162

5263
// Build amalgamation files (OS-specific)
53-
fmt.Printf("Starting to generate amalgamation with build flags: %s\n", buildFlags)
54-
if err := buildAmalgamation(baseDir, buildFlags); err != nil {
64+
fmt.Printf("Starting to generate amalgamation with CFLAGS: %s\n", cFlags)
65+
if err := buildAmalgamation(baseDir, cFlags); err != nil {
5566
return fmt.Errorf("failed to build amalgamation: %v", err)
5667
}
5768
fmt.Println("SQLite3 amalgamation built")
@@ -247,3 +258,27 @@ func patchSource(baseDir, src, dst string, extensions ...string) error {
247258

248259
return nil
249260
}
261+
262+
func buildAmalgamation(baseDir, buildFlags string) error {
263+
configureScript := "./configure"
264+
if cFlags != "" {
265+
configureScript += fmt.Sprintf(" CFLAGS=%q", cFlags)
266+
}
267+
cmd := exec.Command(shellPath, "-c", configureScript)
268+
cmd.Dir = baseDir
269+
out, err := cmd.CombinedOutput()
270+
if err != nil {
271+
return fmt.Errorf("configure failed: %v\n\n%s", err, out)
272+
}
273+
fmt.Println("Ran configure successfully")
274+
275+
cmd = exec.Command(makePath, "sqlite3.c")
276+
cmd.Dir = baseDir
277+
out, err = cmd.CombinedOutput()
278+
if err != nil {
279+
return fmt.Errorf("make failed: %v\n\n%s", err, out)
280+
}
281+
fmt.Println("Ran make successfully")
282+
283+
return nil
284+
}

upgrade/upgrade_unix.go

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,7 @@
44

55
package main
66

7-
import (
8-
"fmt"
9-
"os/exec"
7+
var (
8+
shellPath = "bash"
9+
makePath = "make"
1010
)
11-
12-
func buildAmalgamation(baseDir, buildFlags string) error {
13-
args := []string{"configure"}
14-
if buildFlags != "" {
15-
args = append(args, "CFLAGS="+buildFlags)
16-
}
17-
cmd := exec.Command("sh", args...)
18-
cmd.Dir = baseDir
19-
out, err := cmd.CombinedOutput()
20-
if err != nil {
21-
return fmt.Errorf("configure failed: %v\n\n%s", err, out)
22-
}
23-
fmt.Println("Ran configure successfully")
24-
25-
cmd = exec.Command("make", "sqlite3.c")
26-
cmd.Dir = baseDir
27-
out, err = cmd.CombinedOutput()
28-
if err != nil {
29-
return fmt.Errorf("make failed: %v\n\n%s", err, out)
30-
}
31-
fmt.Println("Ran make successfully")
32-
33-
return nil
34-
}

upgrade/upgrade_windows.go

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,7 @@
33

44
package main
55

6-
import (
7-
"fmt"
8-
"os/exec"
6+
var (
7+
shellPath = `c:\msys64\usr\bin\bash.exe`
8+
makePath = `c:\msys64\usr\bin\make.exe`
99
)
10-
11-
func buildAmalgamation(baseDir, buildFlags string) error {
12-
args := []string{"/f", "Makefile.msc", "sqlite3.c"}
13-
if buildFlags != "" {
14-
args = append(args, "OPTS="+buildFlags)
15-
}
16-
cmd := exec.Command("nmake", args...)
17-
cmd.Dir = baseDir
18-
out, err := cmd.CombinedOutput()
19-
if err != nil {
20-
return fmt.Errorf("nmake failed: %v\n\n%s", err, out)
21-
}
22-
fmt.Println("Ran nmake successfully")
23-
24-
return nil
25-
}

0 commit comments

Comments
 (0)