mirror of https://github.com/perkeep/perkeep.git
Merge "devcam: do not depend on GOPATH, rebuild camget and camput"
This commit is contained in:
commit
69367a7e5a
|
@ -19,7 +19,6 @@ limitations under the License.
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
@ -27,7 +26,6 @@ import (
|
|||
"strconv"
|
||||
|
||||
"camlistore.org/pkg/cmdmain"
|
||||
"camlistore.org/pkg/osutil"
|
||||
)
|
||||
|
||||
type gaeCmd struct {
|
||||
|
@ -37,9 +35,6 @@ type gaeCmd struct {
|
|||
sdk string
|
||||
wipe bool
|
||||
// end of flag vars
|
||||
|
||||
camliSrcRoot string // the camlistore source tree
|
||||
applicationDir string // App Engine application dir: camliSrcRoot/server/appengine
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
@ -66,18 +61,14 @@ func (c *gaeCmd) RunCommand(args []string) error {
|
|||
if err != nil {
|
||||
return cmdmain.UsageError(fmt.Sprint(err))
|
||||
}
|
||||
c.camliSrcRoot, err = osutil.GoPackagePath("camlistore.org")
|
||||
if err != nil {
|
||||
return errors.New("Package camlistore.org not found in $GOPATH (or $GOPATH not defined).")
|
||||
}
|
||||
c.applicationDir = filepath.Join(c.camliSrcRoot, "server", "appengine")
|
||||
if _, err := os.Stat(c.applicationDir); err != nil {
|
||||
return fmt.Errorf("Appengine application dir not found at %s", c.applicationDir)
|
||||
applicationDir := filepath.Join("server", "appengine")
|
||||
if _, err := os.Stat(applicationDir); err != nil {
|
||||
return fmt.Errorf("Appengine application dir not found at %s", applicationDir)
|
||||
}
|
||||
if err = c.checkSDK(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = c.mirrorSourceRoot(); err != nil {
|
||||
if err = c.mirrorSourceRoot(applicationDir); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -93,7 +84,7 @@ func (c *gaeCmd) RunCommand(args []string) error {
|
|||
cmdArgs = append(cmdArgs, "--clear_datastore")
|
||||
}
|
||||
cmdArgs = append(cmdArgs, args...)
|
||||
cmdArgs = append(cmdArgs, c.applicationDir)
|
||||
cmdArgs = append(cmdArgs, applicationDir)
|
||||
return runExec(devAppServerBin, cmdArgs)
|
||||
}
|
||||
|
||||
|
@ -105,7 +96,7 @@ func (c *gaeCmd) checkFlags(args []string) error {
|
|||
}
|
||||
|
||||
func (c *gaeCmd) checkSDK() error {
|
||||
defaultSDK := filepath.Join(c.camliSrcRoot, "appengine-sdk")
|
||||
defaultSDK := "appengine-sdk"
|
||||
if c.sdk == "" {
|
||||
c.sdk = defaultSDK
|
||||
}
|
||||
|
@ -115,11 +106,11 @@ func (c *gaeCmd) checkSDK() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *gaeCmd) mirrorSourceRoot() error {
|
||||
func (c *gaeCmd) mirrorSourceRoot(gaeAppDir string) error {
|
||||
uiDirs := []string{"server/camlistored/ui", "third_party/closure/lib/closure", "pkg/server"}
|
||||
for _, dir := range uiDirs {
|
||||
oriPath := filepath.Join(c.camliSrcRoot, filepath.FromSlash(dir))
|
||||
dstPath := filepath.Join(c.applicationDir, "source_root", filepath.FromSlash(dir))
|
||||
oriPath := filepath.Join(camliSrcRoot, filepath.FromSlash(dir))
|
||||
dstPath := filepath.Join(gaeAppDir, "source_root", filepath.FromSlash(dir))
|
||||
if err := cpDir(oriPath, dstPath, []string{".go"}); err != nil {
|
||||
return fmt.Errorf("Error while mirroring %s to %s: %v", oriPath, dstPath, err)
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ limitations under the License.
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
@ -30,7 +29,6 @@ import (
|
|||
"strings"
|
||||
|
||||
"camlistore.org/pkg/cmdmain"
|
||||
"camlistore.org/pkg/osutil"
|
||||
)
|
||||
|
||||
type getCmd struct {
|
||||
|
@ -40,8 +38,7 @@ type getCmd struct {
|
|||
tls bool
|
||||
// end of flag vars
|
||||
|
||||
verbose bool // set by CAMLI_QUIET
|
||||
camliSrcRoot string // the camlistore source tree
|
||||
verbose bool // set by CAMLI_QUIET
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
@ -74,19 +71,14 @@ func (c *getCmd) RunCommand(args []string) error {
|
|||
if err != nil {
|
||||
return cmdmain.UsageError(fmt.Sprint(err))
|
||||
}
|
||||
c.camliSrcRoot, err = osutil.GoPackagePath("camlistore.org")
|
||||
if err != nil {
|
||||
return errors.New("Package camlistore.org not found in $GOPATH (or $GOPATH not defined).")
|
||||
}
|
||||
err = os.Chdir(c.camliSrcRoot)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not chdir to %v: %v", c.camliSrcRoot, err)
|
||||
if err := c.build(); err != nil {
|
||||
return fmt.Errorf("Could not build camget: %v", err)
|
||||
}
|
||||
if err := c.setEnvVars(); err != nil {
|
||||
return fmt.Errorf("Could not setup the env vars: %v", err)
|
||||
}
|
||||
|
||||
cmdBin := filepath.Join(c.camliSrcRoot, "bin", "camget")
|
||||
cmdBin := filepath.Join("bin", "camget")
|
||||
cmdArgs := []string{
|
||||
"-verbose=" + strconv.FormatBool(c.verbose),
|
||||
}
|
||||
|
@ -108,10 +100,10 @@ func (c *getCmd) checkFlags(args []string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *getCmd) build(name string) error {
|
||||
func (c *getCmd) build() error {
|
||||
cmdName := "camget"
|
||||
target := filepath.Join("camlistore.org", "cmd", cmdName)
|
||||
binPath := filepath.Join(c.camliSrcRoot, "bin", cmdName)
|
||||
binPath := filepath.Join("bin", cmdName)
|
||||
var modtime int64
|
||||
fi, err := os.Stat(binPath)
|
||||
if err != nil {
|
||||
|
@ -138,13 +130,11 @@ func (c *getCmd) build(name string) error {
|
|||
}
|
||||
|
||||
func (c *getCmd) setEnvVars() error {
|
||||
setenv("CAMLI_CONFIG_DIR", filepath.Join(c.camliSrcRoot, "config", "dev-client-dir"))
|
||||
setenv("CAMLI_SECRET_RING", filepath.Join(c.camliSrcRoot,
|
||||
filepath.FromSlash("pkg/jsonsign/testdata/test-secring.gpg")))
|
||||
setenv("CAMLI_CONFIG_DIR", filepath.Join("config", "dev-client-dir"))
|
||||
setenv("CAMLI_SECRET_RING", filepath.FromSlash("pkg/jsonsign/testdata/test-secring.gpg"))
|
||||
setenv("CAMLI_KEYID", "26F5ABDA")
|
||||
setenv("CAMLI_AUTH", "userpass:camlistore:pass3179")
|
||||
setenv("CAMLI_DEV_KEYBLOBS", filepath.Join(c.camliSrcRoot,
|
||||
filepath.FromSlash("config/dev-client-dir/keyblobs")))
|
||||
setenv("CAMLI_DEV_KEYBLOBS", filepath.FromSlash("config/dev-client-dir/keyblobs"))
|
||||
c.verbose, _ = strconv.ParseBool(os.Getenv("CAMLI_QUIET"))
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ limitations under the License.
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
@ -29,7 +28,6 @@ import (
|
|||
"strings"
|
||||
|
||||
"camlistore.org/pkg/cmdmain"
|
||||
"camlistore.org/pkg/osutil"
|
||||
)
|
||||
|
||||
type putCmd struct {
|
||||
|
@ -40,8 +38,7 @@ type putCmd struct {
|
|||
tls bool
|
||||
// end of flag vars
|
||||
|
||||
verbose bool // set by CAMLI_QUIET
|
||||
camliSrcRoot string // the camlistore source tree
|
||||
verbose bool // set by CAMLI_QUIET
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
@ -74,13 +71,8 @@ func (c *putCmd) RunCommand(args []string) error {
|
|||
if err != nil {
|
||||
return cmdmain.UsageError(fmt.Sprint(err))
|
||||
}
|
||||
c.camliSrcRoot, err = osutil.GoPackagePath("camlistore.org")
|
||||
if err != nil {
|
||||
return errors.New("Package camlistore.org not found in $GOPATH (or $GOPATH not defined).")
|
||||
}
|
||||
err = os.Chdir(c.camliSrcRoot)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not chdir to %v: %v", c.camliSrcRoot, err)
|
||||
if err := c.build(); err != nil {
|
||||
return fmt.Errorf("Could not build camput: %v", err)
|
||||
}
|
||||
if err := c.setEnvVars(); err != nil {
|
||||
return fmt.Errorf("Could not setup the env vars: %v", err)
|
||||
|
@ -91,7 +83,7 @@ func (c *putCmd) RunCommand(args []string) error {
|
|||
blobserver = strings.Replace(blobserver, "http://", "https://", 1)
|
||||
}
|
||||
|
||||
cmdBin := filepath.Join(c.camliSrcRoot, "bin", "camput")
|
||||
cmdBin := filepath.Join("bin", "camput")
|
||||
cmdArgs := []string{
|
||||
"-verbose=" + strconv.FormatBool(c.verbose),
|
||||
"-server=" + blobserver,
|
||||
|
@ -107,10 +99,10 @@ func (c *putCmd) checkFlags(args []string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *putCmd) build(name string) error {
|
||||
func (c *putCmd) build() error {
|
||||
cmdName := "camput"
|
||||
target := filepath.Join("camlistore.org", "cmd", cmdName)
|
||||
binPath := filepath.Join(c.camliSrcRoot, "bin", cmdName)
|
||||
binPath := filepath.Join("bin", cmdName)
|
||||
var modtime int64
|
||||
fi, err := os.Stat(binPath)
|
||||
if err != nil {
|
||||
|
@ -137,16 +129,13 @@ func (c *putCmd) build(name string) error {
|
|||
}
|
||||
|
||||
func (c *putCmd) setEnvVars() error {
|
||||
setenv("CAMLI_CONFIG_DIR", filepath.Join(c.camliSrcRoot, "config", "dev-client-dir"))
|
||||
setenv("CAMLI_SECRET_RING", filepath.Join(c.camliSrcRoot,
|
||||
filepath.FromSlash("pkg/jsonsign/testdata/test-secring.gpg")))
|
||||
setenv("CAMLI_CONFIG_DIR", filepath.Join("config", "dev-client-dir"))
|
||||
setenv("CAMLI_SECRET_RING", filepath.FromSlash("pkg/jsonsign/testdata/test-secring.gpg"))
|
||||
setenv("CAMLI_KEYID", "26F5ABDA")
|
||||
setenv("CAMLI_AUTH", "userpass:camlistore:pass3179")
|
||||
setenv("CAMLI_DEV_KEYBLOBS", filepath.Join(c.camliSrcRoot,
|
||||
filepath.FromSlash("config/dev-client-dir/keyblobs")))
|
||||
setenv("CAMLI_DEV_KEYBLOBS", filepath.FromSlash("config/dev-client-dir/keyblobs"))
|
||||
if c.altkey {
|
||||
setenv("CAMLI_SECRET_RING", filepath.Join(c.camliSrcRoot,
|
||||
filepath.FromSlash("pkg/jsonsign/testdata/password-foo-secring.gpg")))
|
||||
setenv("CAMLI_SECRET_RING", filepath.FromSlash("pkg/jsonsign/testdata/password-foo-secring.gpg"))
|
||||
setenv("CAMLI_KEYID", "C7C3E176")
|
||||
println("**\n** Note: password is \"foo\"\n**\n")
|
||||
}
|
||||
|
|
|
@ -30,6 +30,10 @@ import (
|
|||
"camlistore.org/pkg/cmdmain"
|
||||
)
|
||||
|
||||
// The path to the Camlistore source tree. Any devcam command
|
||||
// should be run from there.
|
||||
var camliSrcRoot string
|
||||
|
||||
// sysExec is set to syscall.Exec on platforms that support it.
|
||||
var sysExec func(argv0 string, argv []string, envv []string) (err error)
|
||||
|
||||
|
@ -137,7 +141,22 @@ func handleSignals(camliProc *os.Process) {
|
|||
}
|
||||
}
|
||||
|
||||
func checkCamliSrcRoot() {
|
||||
if _, err := os.Stat("make.go"); err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
log.Fatalf("Could not stat make.go: %v", err)
|
||||
}
|
||||
log.Fatal("./make.go not found; devcam needs to be run from the Camlistore source tree root.")
|
||||
}
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
camliSrcRoot = cwd
|
||||
}
|
||||
|
||||
func main() {
|
||||
checkCamliSrcRoot()
|
||||
// TODO(mpl): usage error is not really correct for devcam.
|
||||
// See if I can reimplement it while still using cmdmain.Main().
|
||||
cmdmain.Main()
|
||||
|
|
|
@ -57,9 +57,8 @@ type serverCmd struct {
|
|||
openBrowser bool
|
||||
// end of flag vars
|
||||
|
||||
camliSrcRoot string // the camlistore source tree
|
||||
listen string // address + port to listen on
|
||||
camliRoot string // the temp dir where blobs are stored
|
||||
listen string // address + port to listen on
|
||||
camliRoot string // the temp dir where blobs are stored
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
@ -133,7 +132,7 @@ func (c *serverCmd) build(name string) error {
|
|||
default:
|
||||
return fmt.Errorf("Could not build, invalid target: %v", name)
|
||||
}
|
||||
binPath := filepath.Join(c.camliSrcRoot, "bin", name)
|
||||
binPath := filepath.Join("bin", name)
|
||||
var modtime int64
|
||||
fi, err := os.Stat(binPath)
|
||||
if err != nil {
|
||||
|
@ -242,7 +241,7 @@ func (c *serverCmd) setEnvVars() error {
|
|||
}
|
||||
setenv("CAMLI_BASEURL", base)
|
||||
|
||||
setenv("CAMLI_DEV_CAMLI_ROOT", c.camliSrcRoot)
|
||||
setenv("CAMLI_DEV_CAMLI_ROOT", camliSrcRoot)
|
||||
setenv("CAMLI_AUTH", "devauth:pass3179")
|
||||
fullSuffix := func(name string) string {
|
||||
return filepath.Join(c.camliRoot, name)
|
||||
|
@ -263,7 +262,7 @@ func (c *serverCmd) setEnvVars() error {
|
|||
setenv(k, v)
|
||||
}
|
||||
setenv("CAMLI_PORT", c.port)
|
||||
setenv("CAMLI_SECRET_RING", filepath.Join(c.camliSrcRoot,
|
||||
setenv("CAMLI_SECRET_RING", filepath.Join(camliSrcRoot,
|
||||
filepath.FromSlash("pkg/jsonsign/testdata/test-secring.gpg")))
|
||||
return nil
|
||||
}
|
||||
|
@ -292,7 +291,7 @@ func (c *serverCmd) setupIndexer() error {
|
|||
} else {
|
||||
args = append(args, "-ignoreexists")
|
||||
}
|
||||
binPath := filepath.Join(c.camliSrcRoot, "bin", "camtool")
|
||||
binPath := filepath.Join("bin", "camtool")
|
||||
cmd := exec.Command(binPath, args...)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
@ -304,7 +303,7 @@ func (c *serverCmd) setupIndexer() error {
|
|||
|
||||
func (c *serverCmd) syncTemplateBlobs() error {
|
||||
if c.wipe {
|
||||
templateDir := filepath.Join(c.camliSrcRoot, "dev-server-template")
|
||||
templateDir := "dev-server-template"
|
||||
if _, err := os.Stat(templateDir); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil
|
||||
|
@ -344,14 +343,6 @@ func (c *serverCmd) RunCommand(args []string) error {
|
|||
if err != nil {
|
||||
return cmdmain.UsageError(fmt.Sprint(err))
|
||||
}
|
||||
c.camliSrcRoot, err = osutil.GoPackagePath("camlistore.org")
|
||||
if err != nil {
|
||||
return errors.New("Package camlistore.org not found in $GOPATH (or $GOPATH not defined).")
|
||||
}
|
||||
err = os.Chdir(c.camliSrcRoot)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not chdir to %v: %v", c.camliSrcRoot, err)
|
||||
}
|
||||
if !c.noBuild {
|
||||
for _, name := range []string{"camlistored", "camtool"} {
|
||||
err := c.build(name)
|
||||
|
@ -379,9 +370,9 @@ func (c *serverCmd) RunCommand(args []string) error {
|
|||
log.Printf("Starting dev server on %v/ui/ with password \"pass3179\"\n",
|
||||
os.Getenv("CAMLI_BASEURL"))
|
||||
|
||||
camliBin := filepath.Join(c.camliSrcRoot, "bin", "camlistored")
|
||||
camliBin := filepath.Join("bin", "camlistored")
|
||||
cmdArgs := []string{
|
||||
"-configfile=" + filepath.Join(c.camliSrcRoot, "config", "dev-server-config.json"),
|
||||
"-configfile=" + filepath.Join(camliSrcRoot, "config", "dev-server-config.json"),
|
||||
"-listen=" + c.listen,
|
||||
"-openbrowser=" + strconv.FormatBool(c.openBrowser),
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue