mirror of https://github.com/mattn/go-sqlite3.git
feedback and tweaks
This commit is contained in:
parent
56bb1e29d7
commit
4c62eaf7e5
|
@ -10,12 +10,14 @@ import (
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -23,9 +25,18 @@ import (
|
||||||
"github.com/PuerkitoBio/goquery"
|
"github.com/PuerkitoBio/goquery"
|
||||||
)
|
)
|
||||||
|
|
||||||
const buildFlags = "-DSQLITE_ENABLE_UPDATE_DELETE_LIMIT=1"
|
var (
|
||||||
|
cFlags = "-DSQLITE_ENABLE_UPDATE_DELETE_LIMIT=1"
|
||||||
|
cleanup = true
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
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 {
|
err := func() error {
|
||||||
fmt.Println("Go-SQLite3 Upgrade Tool")
|
fmt.Println("Go-SQLite3 Upgrade Tool")
|
||||||
|
|
||||||
|
@ -46,7 +57,7 @@ func main() {
|
||||||
|
|
||||||
// Extract Source
|
// Extract Source
|
||||||
baseDir, err := extractZip(source)
|
baseDir, err := extractZip(source)
|
||||||
if baseDir != "" && !filepath.IsAbs(baseDir) {
|
if cleanup && baseDir != "" && !filepath.IsAbs(baseDir) {
|
||||||
defer func() {
|
defer func() {
|
||||||
fmt.Println("Cleaning up source: deleting", baseDir)
|
fmt.Println("Cleaning up source: deleting", baseDir)
|
||||||
os.RemoveAll(baseDir)
|
os.RemoveAll(baseDir)
|
||||||
|
@ -57,9 +68,9 @@ func main() {
|
||||||
}
|
}
|
||||||
fmt.Println("Extracted sqlite source to", baseDir)
|
fmt.Println("Extracted sqlite source to", baseDir)
|
||||||
|
|
||||||
// Build amalgamation files (OS-specific)
|
// Build amalgamation files
|
||||||
fmt.Printf("Starting to generate amalgamation with build flags: %s\n", buildFlags)
|
fmt.Printf("Starting to generate amalgamation with CFLAGS: %s\n", cFlags)
|
||||||
if err := buildAmalgamation(baseDir, buildFlags); err != nil {
|
if err := buildAmalgamation(baseDir, cFlags); err != nil {
|
||||||
return fmt.Errorf("failed to build amalgamation: %v", err)
|
return fmt.Errorf("failed to build amalgamation: %v", err)
|
||||||
}
|
}
|
||||||
fmt.Println("SQLite3 amalgamation built")
|
fmt.Println("SQLite3 amalgamation built")
|
||||||
|
@ -73,7 +84,7 @@ func main() {
|
||||||
return nil
|
return nil
|
||||||
}()
|
}()
|
||||||
if err != 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
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -4,31 +4,7 @@
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
var (
|
||||||
"fmt"
|
shellPath = "bash"
|
||||||
"os/exec"
|
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
|
|
||||||
}
|
|
||||||
|
|
|
@ -3,23 +3,7 @@
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
var (
|
||||||
"fmt"
|
shellPath = `c:\msys64\usr\bin\bash.exe`
|
||||||
"os/exec"
|
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
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue