Make kvfile index the default if SQLite isn't available.

We now work out of the box, with no external dependencies.

Change-Id: I8d0cedb33518e418a7ff28cdb22f9ba9ef400d6f
This commit is contained in:
Brad Fitzpatrick 2013-08-25 12:57:51 -05:00
parent 87451bb5bd
commit 46020e1551
2 changed files with 32 additions and 41 deletions

50
make.go
View File

@ -43,9 +43,11 @@ import (
"time"
)
var haveSQLite = checkHaveSQLite()
var (
embedResources = flag.Bool("embed_static", true, "Whether to embed the closure library.")
wantSQLite = flag.Bool("sqlite", true, "Whether you want SQLite in your build. If you don't have any other database, you generally do.")
sql = flag.Bool("sqlite", haveSQLite, "Whether you want SQLite in your build.")
all = flag.Bool("all", false, "Force rebuild of everything (go install -a)")
verbose = flag.Bool("v", false, "Verbose mode")
targets = flag.String("targets", "", "Optional comma-separated list of targets (i.e go packages) to build and install. Empty means all. Example: camlistore.org/server/camlistored,camlistore.org/cmd/camput")
@ -75,15 +77,25 @@ func main() {
verifyCamlistoreRoot(camRoot)
if runtime.GOOS != *buildOS || runtime.GOARCH != *buildARCH {
if *wantSQLite {
if *sql {
log.Fatalf("SQLite isn't available when cross-compiling to another OS. Set --sqlite=false.")
}
}
sql := *wantSQLite && haveSQLite()
if *sql && !haveSQLite {
log.Printf("SQLite not found. Either install it, or run make.go with --sqlite=false")
switch runtime.GOOS {
case "darwin":
log.Printf("On OS X, run 'brew install sqlite3 pkg-config'. Get brew from http://mxcl.github.io/homebrew/")
case "linux":
log.Printf("On Linux, run 'sudo apt-get install libsqlite3-dev' or equivalent.")
case "windows":
log.Printf("SQLite is not easy on windows. Please see http://camlistore.org/docs/server-config#windows")
}
os.Exit(2)
}
buildBaseDir := "build-gopath"
if !sql {
if !*sql {
buildBaseDir += "-nosqlite"
}
@ -99,24 +111,11 @@ func main() {
if *verbose {
log.Printf("Camlistore version = %s", version)
log.Printf("SQLite available: %v", sql)
log.Printf("SQLite included: %v", *sql)
log.Printf("Temporary source: %s", buildSrcDir)
log.Printf("Output binaries: %s", binDir)
}
if !sql && *wantSQLite {
log.Printf("SQLite not found. Either install it, or run make.go with --sqlite=false")
switch runtime.GOOS {
case "darwin":
log.Printf("On OS X, run 'brew install sqlite3 pkg-config'. Get brew from http://mxcl.github.io/homebrew/")
case "linux":
log.Printf("On Linux, run 'sudo apt-get install libsqlite3-dev' or equivalent.")
case "windows":
log.Printf("SQLite is not easy on windows. Please see http://camlistore.org/docs/server-config#windows")
}
os.Exit(2)
}
// We copy all *.go files from camRoot's goDirs to buildSrcDir.
goDirs := []string{"cmd", "pkg", "server/camlistored", "third_party"}
// Copy files we do want in our mirrored GOPATH. This has the side effect of
@ -158,7 +157,7 @@ func main() {
deleteUnwantedOldMirrorFiles(buildSrcDir)
tags := ""
if sql && *wantSQLite {
if *sql {
tags = "with_sqlite"
}
baseArgs := []string{"install", "-v"}
@ -527,7 +526,7 @@ func deleteUnwantedOldMirrorFiles(dir string) {
})
}
func haveSQLite() bool {
func checkHaveSQLite() bool {
if runtime.GOOS == "windows" {
// TODO: Find some other non-pkg-config way to test, like
// just compiling a small Go program that sees whether
@ -538,14 +537,7 @@ func haveSQLite() bool {
}
_, err := exec.LookPath("pkg-config")
if err != nil {
if runtime.GOOS == "darwin" {
// OS X usually doesn't have pkg-config installed. Don't
// call Fatalf() so that the nicer error message in main()
// can be printed.
return false
}
log.Fatalf("No pkg-config found. Can't determine whether sqlite3 is available, and where.")
return false
}
cmd := exec.Command("pkg-config", "--libs", "sqlite3")
if runtime.GOOS == "darwin" && os.Getenv("PKG_CONFIG_PATH") == "" {

View File

@ -25,7 +25,6 @@ import (
"database/sql"
"encoding/json"
"encoding/pem"
"errors"
"flag"
"fmt"
"io/ioutil"
@ -215,6 +214,7 @@ type defaultConfigFile struct {
Auth string `json:"auth"`
Identity string `json:"identity"`
IdentitySecretRing string `json:"identitySecretRing"`
KVFile string `json:"kvIndexFile"`
BlobPath string `json:"blobPath"`
MySQL string `json:"mysql"`
Mongo string `json:"mongo"`
@ -237,7 +237,16 @@ func newDefaultConfigFile(path string) error {
return fmt.Errorf("Could not create default blobs directory: %v", err)
}
conf.BlobPath = blobDir
conf.SQLite = filepath.Join(osutil.CamliVarDir(), "camli-index.db")
if sqlite.CompiledIn() {
conf.SQLite = filepath.Join(osutil.CamliVarDir(), "camli-index.db")
if fi, err := os.Stat(conf.SQLite); os.IsNotExist(err) || (fi != nil && fi.Size() == 0) {
if err := initSQLiteDB(conf.SQLite); err != nil {
log.Printf("Error initializing DB %s: %v", conf.SQLite, err)
}
}
} else {
conf.KVFile = filepath.Join(osutil.CamliVarDir(), "camli-index.kvdb")
}
var keyId string
secRing := osutil.IdentitySecretRing()
@ -265,16 +274,6 @@ func newDefaultConfigFile(path string) error {
return fmt.Errorf("Could not create or write default server config: %v", err)
}
if sqlite.CompiledIn() {
if fi, err := os.Stat(conf.SQLite); os.IsNotExist(err) || (fi != nil && fi.Size() == 0) {
if err := initSQLiteDB(conf.SQLite); err != nil {
log.Printf("Error initializing DB %s: %v", conf.SQLite, err)
}
}
} else {
log.Printf("Wrote config file assuming SQLite, but SQLite is not available. Recompile with SQLite or modify %s and pick an index type. Please see http://camlistore.org/docs/server-config#windows", path)
return errors.New("Newly written configuration not usable.")
}
return nil
}