feedback and tweaks

This commit is contained in:
Diego Becciolini 2020-06-30 17:55:45 +01:00 committed by Diego Becciolini
parent 56bb1e29d7
commit 4c62eaf7e5
No known key found for this signature in database
GPG Key ID: 01569F80C7D1F763
3 changed files with 47 additions and 52 deletions

View File

@ -10,12 +10,14 @@ import (
"crypto/sha1"
"encoding/hex"
"errors"
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"os/exec"
"path/filepath"
"strings"
"time"
@ -23,9 +25,18 @@ import (
"github.com/PuerkitoBio/goquery"
)
const buildFlags = "-DSQLITE_ENABLE_UPDATE_DELETE_LIMIT=1"
var (
cFlags = "-DSQLITE_ENABLE_UPDATE_DELETE_LIMIT=1"
cleanup = true
)
func main() {
flag.StringVar(&shellPath, "shell", shellPath, "path to shell executable")
flag.StringVar(&makePath, "make", makePath, "path to make executable")
flag.StringVar(&cFlags, "cflags", cFlags, "sqlite CFLAGS")
flag.BoolVar(&cleanup, "cleanup", cleanup, "cleanup source")
flag.Parse()
err := func() error {
fmt.Println("Go-SQLite3 Upgrade Tool")
@ -46,7 +57,7 @@ func main() {
// Extract Source
baseDir, err := extractZip(source)
if baseDir != "" && !filepath.IsAbs(baseDir) {
if cleanup && baseDir != "" && !filepath.IsAbs(baseDir) {
defer func() {
fmt.Println("Cleaning up source: deleting", baseDir)
os.RemoveAll(baseDir)
@ -57,9 +68,9 @@ func main() {
}
fmt.Println("Extracted sqlite source to", baseDir)
// Build amalgamation files (OS-specific)
fmt.Printf("Starting to generate amalgamation with build flags: %s\n", buildFlags)
if err := buildAmalgamation(baseDir, buildFlags); err != nil {
// Build amalgamation files
fmt.Printf("Starting to generate amalgamation with CFLAGS: %s\n", cFlags)
if err := buildAmalgamation(baseDir, cFlags); err != nil {
return fmt.Errorf("failed to build amalgamation: %v", err)
}
fmt.Println("SQLite3 amalgamation built")
@ -73,7 +84,7 @@ func main() {
return nil
}()
if err != nil {
log.Fatal("Returned with error:", err)
log.Fatalln("Returned with error:", err)
}
}
@ -255,3 +266,27 @@ func patchSource(baseDir, src, dst string, extensions ...string) error {
return nil
}
func buildAmalgamation(baseDir, buildFlags string) error {
configureScript := "./configure"
if cFlags != "" {
configureScript += fmt.Sprintf(" CFLAGS=%q", cFlags)
}
cmd := exec.Command(shellPath, "-c", configureScript)
cmd.Dir = baseDir
out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("configure failed: %v\n\n%s", err, out)
}
fmt.Println("Ran configure successfully")
cmd = exec.Command(makePath, "sqlite3.c")
cmd.Dir = baseDir
out, err = cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("make failed: %v\n\n%s", err, out)
}
fmt.Println("Ran make successfully")
return nil
}

View File

@ -4,31 +4,7 @@
package main
import (
"fmt"
"os/exec"
var (
shellPath = "bash"
makePath = "make"
)
func buildAmalgamation(baseDir, buildFlags string) error {
args := []string{"configure"}
if buildFlags != "" {
args = append(args, "CFLAGS="+buildFlags)
}
cmd := exec.Command("sh", args...)
cmd.Dir = baseDir
out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("configure failed: %v\n\n%s", err, out)
}
fmt.Println("Ran configure successfully")
cmd = exec.Command("make", "sqlite3.c")
cmd.Dir = baseDir
out, err = cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("make failed: %v\n\n%s", err, out)
}
fmt.Println("Ran make successfully")
return nil
}

View File

@ -3,23 +3,7 @@
package main
import (
"fmt"
"os/exec"
var (
shellPath = `c:\msys64\usr\bin\bash.exe`
makePath = `c:\msys64\usr\bin\make.exe`
)
func buildAmalgamation(baseDir, buildFlags string) error {
args := []string{"/f", "Makefile.msc", "sqlite3.c"}
if buildFlags != "" {
args = append(args, "OPTS="+buildFlags)
}
cmd := exec.Command("nmake", args...)
cmd.Dir = baseDir
out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("nmake failed: %v\n\n%s", err, out)
}
fmt.Println("Ran nmake successfully")
return nil
}