2013-07-08 00:35:10 +00:00
// +build ignore
2013-06-10 22:55:17 +00:00
/ *
2018-01-04 00:52:49 +00:00
Copyright 2013 The Perkeep Authors
2013-06-10 22:55:17 +00:00
Licensed under the Apache License , Version 2.0 ( the "License" ) ;
you may not use this file except in compliance with the License .
You may obtain a copy of the License at
http : //www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing , software
distributed under the License is distributed on an "AS IS" BASIS ,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
See the License for the specific language governing permissions and
limitations under the License .
* /
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
// This program builds Perkeep.
2013-06-10 22:55:17 +00:00
//
2013-06-11 11:19:46 +00:00
// $ go run make.go
//
// See the BUILDING file.
//
2013-06-10 22:55:17 +00:00
// The output binaries go into the ./bin/ directory (under the
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
// Perkeep root, where make.go is)
2013-06-10 22:55:17 +00:00
package main
import (
2013-06-18 20:02:03 +00:00
"archive/zip"
"bytes"
2016-05-12 22:14:54 +00:00
"crypto/sha256"
2018-04-22 19:35:28 +00:00
"errors"
2013-06-10 22:55:17 +00:00
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"os/exec"
2013-09-21 11:45:36 +00:00
pathpkg "path"
2013-06-10 22:55:17 +00:00
"path/filepath"
2013-06-20 13:49:34 +00:00
"regexp"
2013-06-10 22:55:17 +00:00
"runtime"
2013-08-26 22:52:02 +00:00
"strconv"
2013-06-10 22:55:17 +00:00
"strings"
2013-06-19 06:14:36 +00:00
"time"
2013-06-10 22:55:17 +00:00
)
2013-08-25 17:57:51 +00:00
var haveSQLite = checkHaveSQLite ( )
2013-06-10 23:18:29 +00:00
var (
2013-12-29 05:27:28 +00:00
embedResources = flag . Bool ( "embed_static" , true , "Whether to embed resources needed by the UI such as images, css, and javascript." )
2015-10-30 18:19:05 +00:00
sqlFlag = flag . String ( "sqlite" , "false" , "Whether you want SQLite in your build: true, false, or auto." )
2013-12-11 11:53:36 +00:00
race = flag . Bool ( "race" , false , "Build race-detector version of binaries (they will run slowly)" )
2015-04-13 18:00:07 +00:00
verbose = flag . Bool ( "v" , strings . Contains ( os . Getenv ( "CAMLI_DEBUG_X" ) , "makego" ) , "Verbose mode" )
2018-04-21 18:04:53 +00:00
targets = flag . String ( "targets" , "" , "Optional comma-separated list of targets (i.e go packages) to build and install. '*' builds everything. Empty builds defaults for this platform. Example: perkeep.org/server/perkeepd,perkeep.org/cmd/pk-put" )
2013-06-29 20:52:01 +00:00
quiet = flag . Bool ( "quiet" , false , "Don't print anything unless there's a failure." )
2014-08-08 23:11:53 +00:00
buildARCH = flag . String ( "arch" , runtime . GOARCH , "Architecture to build for." )
buildOS = flag . String ( "os" , runtime . GOOS , "Operating system to build for." )
2016-03-11 18:57:36 +00:00
buildARM = flag . String ( "arm" , "7" , "ARM version to use if building for ARM. Note that this version applies even if the host arch is ARM too (and possibly of a different version)." )
2015-12-07 19:35:35 +00:00
stampVersion = flag . Bool ( "stampversion" , true , "Stamp version into buildinfo.GitInfo" )
2016-05-01 00:18:43 +00:00
website = flag . Bool ( "website" , false , "Just build the website." )
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
camnetdns = flag . Bool ( "camnetdns" , false , "Just build perkeep.org/server/camnetdns." )
misc/docker/server: build with make.go
So far, when building camlistored docker image for CoreOS, we were not
using make.go, and we were neither running gopherjs nor embedding the
resources (but rather provide the UI resources at their default
filesystem location).
Now that we're using gopherjs for the web UI, it is a hard dependency
for the camlistore server.
We could reproduce the steps in make.go to build gopherjs, run it to
build the web ui resources, and then move the resources at the right
place, but since make.go already does the equivalent work it seems
to make more sense to use it, which is the main point of this CL.
Similarly, it seems to make more sense to now build a binary with the
resources embedded, which is the default make.go behaviour, instead of
building a "raw" camlistored, and provide the resources as additional
directories in the container image, so this CL takes that approach too.
Finally, it was necessary to add the "-static" flag to make.go, so we
can keep on building a static camlistored binary, that does not rely on
libc for DNS. Because our container image is FROM SCRATCH, with just the
necessary binaries, in order to get a container image of a reasonable
size.
One drawback of now using make.go in
misc/docker/server/build-camlistore-server.go is we're doing some
unnecessary (since we're already running in the isolation of a
container) copying to the virtual gopath, but that seems a very tiny
price to pay. Especially considering how rarely we run that code.
Change-Id: I416c86d366cd4ed2d3b8b1636a6a65a83b9f15d7
2017-04-04 15:58:03 +00:00
static = flag . Bool ( "static" , false , "Build a static binary, so it can run in an empty container." )
2018-05-01 21:52:17 +00:00
skipGopherJS = flag . Bool ( "skip_gopherjs" , false , "skip building/running GopherJS, even if building perkeepd/etc" )
2013-06-10 23:18:29 +00:00
)
2013-06-10 22:55:17 +00:00
2013-06-20 13:49:34 +00:00
var (
2018-02-23 19:57:12 +00:00
// pkRoot is the Perkeep project root
pkRoot string
2018-04-19 10:58:56 +00:00
binDir string // $GOBIN or $GOPATH/bin, based on user setting or default Go value.
2018-02-23 19:57:12 +00:00
2016-11-25 20:13:12 +00:00
// gopherjsGoroot should be specified through the env var
// CAMLI_GOPHERJS_GOROOT when the user's using go tip, because gopherjs only
2018-02-23 19:57:12 +00:00
// builds with Go 1.10.
2016-11-25 20:13:12 +00:00
gopherjsGoroot string
2013-06-20 13:49:34 +00:00
)
2013-06-10 22:55:17 +00:00
func main ( ) {
log . SetFlags ( 0 )
flag . Parse ( )
2014-10-21 13:02:30 +00:00
if * buildARCH == "386" && * buildOS == "darwin" {
if ok , _ := strconv . ParseBool ( os . Getenv ( "CAMLI_FORCE_OSARCH" ) ) ; ! ok {
log . Fatalf ( "You're trying to build a 32-bit binary for a Mac. That is almost always a mistake.\nTo do it anyway, set env CAMLI_FORCE_OSARCH=1 and run again.\n" )
}
}
2016-10-03 23:55:58 +00:00
if * website && * camnetdns {
log . Fatal ( "-camnetdns and -website are mutually exclusive" )
}
2018-01-02 01:16:18 +00:00
failIfCamlistoreOrgDir ( )
devcam test: do not "recurse" temp GOPATH, docs, couple more options.
Problem: make.go creates an isolated temp gopath ./tmp/build-gopath. The
integration tests make use of that gopath (by running make.go) to build
the tools, and run the test world in it. Similarly, devcam test uses
make.go to setup that temp gopath, and runs the tests from the source
files in that gopath. Consequently, when the integration tests are run
through devcam test, even though they're run from the temp gopath, they
would use the make.go in it, which would create a nested temp gopath
(CAMLIROOT/tmp/build-gopath/src/camlistore.org/tmp/build-gopath) in
which to run the tests.
This patch addresses this issue by creating a new flag (-envGoPath), and
the corresponding env var (CAMLI_MAKE_USEGOPATH), which tells make.go
not to create a new temporary gopath (and hence not to mirror any
files), and to rely on the already set GOPATH env var instead.
Also refactored make.go a bit, and added a couple options and doc to
devcam test.
Change-Id: Ia8a5d7a31e6e317f05218d9e18fb886001cd19cb
2014-08-06 16:47:42 +00:00
verifyGoVersion ( )
2018-02-23 19:57:12 +00:00
verifyPerkeepRoot ( )
devcam test: do not "recurse" temp GOPATH, docs, couple more options.
Problem: make.go creates an isolated temp gopath ./tmp/build-gopath. The
integration tests make use of that gopath (by running make.go) to build
the tools, and run the test world in it. Similarly, devcam test uses
make.go to setup that temp gopath, and runs the tests from the source
files in that gopath. Consequently, when the integration tests are run
through devcam test, even though they're run from the temp gopath, they
would use the make.go in it, which would create a nested temp gopath
(CAMLIROOT/tmp/build-gopath/src/camlistore.org/tmp/build-gopath) in
which to run the tests.
This patch addresses this issue by creating a new flag (-envGoPath), and
the corresponding env var (CAMLI_MAKE_USEGOPATH), which tells make.go
not to create a new temporary gopath (and hence not to mirror any
files), and to rely on the already set GOPATH env var instead.
Also refactored make.go a bit, and added a couple options and doc to
devcam test.
Change-Id: Ia8a5d7a31e6e317f05218d9e18fb886001cd19cb
2014-08-06 16:47:42 +00:00
version := getVersion ( )
2018-02-23 19:57:12 +00:00
sql := withSQLite ( )
2013-06-10 22:55:17 +00:00
2013-06-10 23:22:28 +00:00
if * verbose {
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
log . Printf ( "Perkeep version = %s" , version )
2013-08-26 22:52:02 +00:00
log . Printf ( "SQLite included: %v" , sql )
2018-02-23 19:57:12 +00:00
log . Printf ( "Project source: %s" , pkRoot )
2018-04-19 10:58:56 +00:00
log . Printf ( "Output binaries: %s" , actualBinDir ( ) )
2013-06-10 23:22:28 +00:00
}
2013-06-10 22:55:17 +00:00
2014-02-21 21:59:26 +00:00
buildAll := false
2013-09-11 05:42:24 +00:00
targs := [ ] string {
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
"perkeep.org/dev/devcam" ,
2018-04-22 19:35:28 +00:00
"perkeep.org/cmd/pk-get" ,
2018-03-06 21:39:14 +00:00
"perkeep.org/cmd/pk-put" ,
2018-03-05 23:07:54 +00:00
"perkeep.org/cmd/pk" ,
2018-01-03 06:10:37 +00:00
"perkeep.org/cmd/pk-deploy" ,
2018-04-21 18:04:53 +00:00
"perkeep.org/server/perkeepd" ,
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
"perkeep.org/app/hello" ,
"perkeep.org/app/publisher" ,
"perkeep.org/app/scanningcabinet" ,
"perkeep.org/app/scanningcabinet/scancab" ,
2013-09-11 05:42:24 +00:00
}
2014-02-20 04:56:05 +00:00
switch * targets {
case "*" :
buildAll = true
case "" :
2018-01-08 03:57:49 +00:00
// Add pk-mount to default build targets on OSes that support FUSE.
2014-02-21 21:59:26 +00:00
switch * buildOS {
case "linux" , "darwin" :
2018-01-08 03:57:49 +00:00
targs = append ( targs , "perkeep.org/cmd/pk-mount" )
2014-02-21 21:59:26 +00:00
}
2014-02-20 04:56:05 +00:00
default :
2016-05-01 00:18:43 +00:00
if * website {
log . Fatal ( "-targets and -website are mutually exclusive" )
}
2017-04-16 09:38:50 +00:00
if * camnetdns {
2016-10-03 23:55:58 +00:00
log . Fatal ( "-targets and -camnetdns are mutually exclusive" )
}
2013-09-11 05:42:24 +00:00
if t := strings . Split ( * targets , "," ) ; len ( t ) != 0 {
targs = t
}
}
2016-10-03 23:55:58 +00:00
if * website || * camnetdns {
2016-05-01 00:18:43 +00:00
buildAll = false
2016-10-03 23:55:58 +00:00
if * website {
2018-04-23 23:22:14 +00:00
targs = [ ] string { "perkeep.org/website/pk-web" }
2016-10-03 23:55:58 +00:00
} else if * camnetdns {
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
targs = [ ] string { "perkeep.org/server/camnetdns" }
2016-10-03 23:55:58 +00:00
}
2016-05-01 00:18:43 +00:00
}
2013-09-11 05:42:24 +00:00
2018-05-01 21:52:17 +00:00
withPerkeepd := stringListContains ( targs , "perkeep.org/server/perkeepd" )
2018-02-23 19:57:12 +00:00
withPublisher := stringListContains ( targs , "perkeep.org/app/publisher" )
2018-05-01 21:52:17 +00:00
if ( withPerkeepd || withPublisher ) && ! * skipGopherJS {
2017-06-11 12:01:42 +00:00
if err := buildReactGen ( ) ; err != nil {
log . Fatal ( err )
}
2018-05-01 21:52:17 +00:00
if withPerkeepd {
2018-02-23 19:57:12 +00:00
if err := genWebUIReact ( ) ; err != nil {
log . Fatal ( err )
}
2017-06-11 12:01:42 +00:00
}
2016-05-12 22:14:54 +00:00
// gopherjs has to run before doEmbed since we need all the javascript
// to be generated before embedding happens.
2018-05-01 21:52:17 +00:00
if err := makeJS ( withPerkeepd , withPublisher ) ; err != nil {
2016-05-12 22:14:54 +00:00
log . Fatal ( err )
}
}
2018-05-01 21:52:17 +00:00
if * embedResources && withPerkeepd {
devcam test: do not "recurse" temp GOPATH, docs, couple more options.
Problem: make.go creates an isolated temp gopath ./tmp/build-gopath. The
integration tests make use of that gopath (by running make.go) to build
the tools, and run the test world in it. Similarly, devcam test uses
make.go to setup that temp gopath, and runs the tests from the source
files in that gopath. Consequently, when the integration tests are run
through devcam test, even though they're run from the temp gopath, they
would use the make.go in it, which would create a nested temp gopath
(CAMLIROOT/tmp/build-gopath/src/camlistore.org/tmp/build-gopath) in
which to run the tests.
This patch addresses this issue by creating a new flag (-envGoPath), and
the corresponding env var (CAMLI_MAKE_USEGOPATH), which tells make.go
not to create a new temporary gopath (and hence not to mirror any
files), and to rely on the already set GOPATH env var instead.
Also refactored make.go a bit, and added a couple options and doc to
devcam test.
Change-Id: Ia8a5d7a31e6e317f05218d9e18fb886001cd19cb
2014-08-06 16:47:42 +00:00
doEmbed ( )
2013-06-18 20:02:03 +00:00
}
2014-08-24 03:11:50 +00:00
tags := [ ] string { "purego" } // for cznic/zappy
misc/docker/server: build with make.go
So far, when building camlistored docker image for CoreOS, we were not
using make.go, and we were neither running gopherjs nor embedding the
resources (but rather provide the UI resources at their default
filesystem location).
Now that we're using gopherjs for the web UI, it is a hard dependency
for the camlistore server.
We could reproduce the steps in make.go to build gopherjs, run it to
build the web ui resources, and then move the resources at the right
place, but since make.go already does the equivalent work it seems
to make more sense to use it, which is the main point of this CL.
Similarly, it seems to make more sense to now build a binary with the
resources embedded, which is the default make.go behaviour, instead of
building a "raw" camlistored, and provide the resources as additional
directories in the container image, so this CL takes that approach too.
Finally, it was necessary to add the "-static" flag to make.go, so we
can keep on building a static camlistored binary, that does not rely on
libc for DNS. Because our container image is FROM SCRATCH, with just the
necessary binaries, in order to get a container image of a reasonable
size.
One drawback of now using make.go in
misc/docker/server/build-camlistore-server.go is we're doing some
unnecessary (since we're already running in the isolation of a
container) copying to the virtual gopath, but that seems a very tiny
price to pay. Especially considering how rarely we run that code.
Change-Id: I416c86d366cd4ed2d3b8b1636a6a65a83b9f15d7
2017-04-04 15:58:03 +00:00
if * static {
tags = append ( tags , "netgo" )
}
2013-08-26 22:52:02 +00:00
if sql {
2018-01-21 18:14:40 +00:00
// used by go-sqlite to use system sqlite libraries
tags = append ( tags , "libsqlite3" )
// used by perkeep to switch behavior to sqlite for tests
// and some underlying libraries
2014-08-24 03:11:50 +00:00
tags = append ( tags , "with_sqlite" )
2013-06-10 22:55:17 +00:00
}
2013-06-22 03:18:02 +00:00
baseArgs := [ ] string { "install" , "-v" }
2013-12-11 11:53:36 +00:00
if * race {
baseArgs = append ( baseArgs , "-race" )
}
2015-04-13 18:00:07 +00:00
if * verbose {
log . Printf ( "version to stamp is %q" , version )
}
var ldFlags string
misc/docker/server: build with make.go
So far, when building camlistored docker image for CoreOS, we were not
using make.go, and we were neither running gopherjs nor embedding the
resources (but rather provide the UI resources at their default
filesystem location).
Now that we're using gopherjs for the web UI, it is a hard dependency
for the camlistore server.
We could reproduce the steps in make.go to build gopherjs, run it to
build the web ui resources, and then move the resources at the right
place, but since make.go already does the equivalent work it seems
to make more sense to use it, which is the main point of this CL.
Similarly, it seems to make more sense to now build a binary with the
resources embedded, which is the default make.go behaviour, instead of
building a "raw" camlistored, and provide the resources as additional
directories in the container image, so this CL takes that approach too.
Finally, it was necessary to add the "-static" flag to make.go, so we
can keep on building a static camlistored binary, that does not rely on
libc for DNS. Because our container image is FROM SCRATCH, with just the
necessary binaries, in order to get a container image of a reasonable
size.
One drawback of now using make.go in
misc/docker/server/build-camlistore-server.go is we're doing some
unnecessary (since we're already running in the isolation of a
container) copying to the virtual gopath, but that seems a very tiny
price to pay. Especially considering how rarely we run that code.
Change-Id: I416c86d366cd4ed2d3b8b1636a6a65a83b9f15d7
2017-04-04 15:58:03 +00:00
if * static {
ldFlags = "-w -d -linkmode internal"
}
2015-04-13 18:00:07 +00:00
if * stampVersion {
misc/docker/server: build with make.go
So far, when building camlistored docker image for CoreOS, we were not
using make.go, and we were neither running gopherjs nor embedding the
resources (but rather provide the UI resources at their default
filesystem location).
Now that we're using gopherjs for the web UI, it is a hard dependency
for the camlistore server.
We could reproduce the steps in make.go to build gopherjs, run it to
build the web ui resources, and then move the resources at the right
place, but since make.go already does the equivalent work it seems
to make more sense to use it, which is the main point of this CL.
Similarly, it seems to make more sense to now build a binary with the
resources embedded, which is the default make.go behaviour, instead of
building a "raw" camlistored, and provide the resources as additional
directories in the container image, so this CL takes that approach too.
Finally, it was necessary to add the "-static" flag to make.go, so we
can keep on building a static camlistored binary, that does not rely on
libc for DNS. Because our container image is FROM SCRATCH, with just the
necessary binaries, in order to get a container image of a reasonable
size.
One drawback of now using make.go in
misc/docker/server/build-camlistore-server.go is we're doing some
unnecessary (since we're already running in the isolation of a
container) copying to the virtual gopath, but that seems a very tiny
price to pay. Especially considering how rarely we run that code.
Change-Id: I416c86d366cd4ed2d3b8b1636a6a65a83b9f15d7
2017-04-04 15:58:03 +00:00
if ldFlags != "" {
ldFlags += " "
}
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
ldFlags += "-X \"perkeep.org/pkg/buildinfo.GitInfo=" + version + "\""
2015-04-13 18:00:07 +00:00
}
2018-05-01 21:52:17 +00:00
if ldFlags != "" {
baseArgs = append ( baseArgs , "--ldflags=" + ldFlags )
}
baseArgs = append ( baseArgs , "--tags=" + strings . Join ( tags , " " ) )
2013-06-22 03:18:02 +00:00
2013-09-21 11:45:36 +00:00
// First install command: build just the final binaries, installed to a GOBIN
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
// under <perkeep_root>/bin:
2013-09-21 11:45:36 +00:00
args := append ( baseArgs , targs ... )
if buildAll {
args = append ( args ,
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
"perkeep.org/app/..." ,
"perkeep.org/pkg/..." ,
"perkeep.org/server/..." ,
"perkeep.org/internal/..." ,
2013-09-21 11:45:36 +00:00
)
}
2013-06-10 23:18:29 +00:00
cmd := exec . Command ( "go" , args ... )
2018-02-23 19:57:12 +00:00
cmd . Env = cleanGoEnv ( )
misc/docker/server: build with make.go
So far, when building camlistored docker image for CoreOS, we were not
using make.go, and we were neither running gopherjs nor embedding the
resources (but rather provide the UI resources at their default
filesystem location).
Now that we're using gopherjs for the web UI, it is a hard dependency
for the camlistore server.
We could reproduce the steps in make.go to build gopherjs, run it to
build the web ui resources, and then move the resources at the right
place, but since make.go already does the equivalent work it seems
to make more sense to use it, which is the main point of this CL.
Similarly, it seems to make more sense to now build a binary with the
resources embedded, which is the default make.go behaviour, instead of
building a "raw" camlistored, and provide the resources as additional
directories in the container image, so this CL takes that approach too.
Finally, it was necessary to add the "-static" flag to make.go, so we
can keep on building a static camlistored binary, that does not rely on
libc for DNS. Because our container image is FROM SCRATCH, with just the
necessary binaries, in order to get a container image of a reasonable
size.
One drawback of now using make.go in
misc/docker/server/build-camlistore-server.go is we're doing some
unnecessary (since we're already running in the isolation of a
container) copying to the virtual gopath, but that seems a very tiny
price to pay. Especially considering how rarely we run that code.
Change-Id: I416c86d366cd4ed2d3b8b1636a6a65a83b9f15d7
2017-04-04 15:58:03 +00:00
if * static {
cmd . Env = append ( cmd . Env , "CGO_ENABLED=0" )
}
2015-04-13 18:00:07 +00:00
if * verbose {
log . Printf ( "Running go %q with Env %q" , args , cmd . Env )
}
2013-06-29 20:52:01 +00:00
var output bytes . Buffer
if * quiet {
cmd . Stdout = & output
cmd . Stderr = & output
} else {
cmd . Stdout = os . Stdout
cmd . Stderr = os . Stderr
}
2013-06-10 23:22:28 +00:00
if * verbose {
2013-07-05 17:41:07 +00:00
log . Printf ( "Running go install of main binaries with args %s" , cmd . Args )
2013-06-22 03:18:02 +00:00
}
if err := cmd . Run ( ) ; err != nil {
2013-07-04 02:44:57 +00:00
log . Fatalf ( "Error building main binaries: %v\n%s" , err , output . String ( ) )
2013-06-10 23:22:28 +00:00
}
2013-06-29 20:52:01 +00:00
if ! * quiet {
2018-04-19 10:58:56 +00:00
log . Printf ( "Success. Binaries are in %s" , actualBinDir ( ) )
2013-06-29 20:52:01 +00:00
}
2013-06-10 22:55:17 +00:00
}
2018-04-19 10:58:56 +00:00
func actualBinDir ( ) string {
cmd := exec . Command ( "go" , "list" , "-f" , "{{.Target}}" , "perkeep.org/cmd/pk" )
cmd . Env = cleanGoEnv ( )
cmd . Stderr = os . Stderr
out , err := cmd . Output ( )
if err != nil {
log . Fatalf ( "Could not run go list to guess install dir: %v, %v" , err , out )
2018-02-23 19:57:12 +00:00
}
2018-04-19 10:58:56 +00:00
return filepath . Dir ( strings . TrimSpace ( string ( out ) ) )
2018-02-23 19:57:12 +00:00
}
2016-03-11 18:57:36 +00:00
func baseDirName ( sql bool ) string {
buildBaseDir := "build-gopath"
if ! sql {
buildBaseDir += "-nosqlite"
}
// We don't even consider whether we're cross-compiling. As long as we
// build for ARM, we do it in its own versioned dir.
if * buildARCH == "arm" {
buildBaseDir += "-armv" + * buildARM
}
return buildBaseDir
}
2016-05-12 22:14:54 +00:00
const (
publisherJS = "app/publisher/publisher.js"
2018-04-21 18:04:53 +00:00
gopherjsUI = "server/perkeepd/ui/goui.js"
2016-05-12 22:14:54 +00:00
)
2018-02-23 19:57:12 +00:00
func buildGopherjs ( ) error {
// if gopherjs binary already exists, record its modtime, so we can reset it later.
// See explanation below.
outBin := hostExeName ( filepath . Join ( binDir , "gopherjs" ) )
fi , err := os . Stat ( outBin )
if err != nil && ! os . IsNotExist ( err ) {
return err
2016-05-12 22:14:54 +00:00
}
2018-02-23 19:57:12 +00:00
modtime := time . Now ( )
2018-04-17 20:31:33 +00:00
var hashBefore string
2018-02-23 19:57:12 +00:00
if err == nil {
modtime = fi . ModTime ( )
2018-04-17 20:31:33 +00:00
hashBefore = hashsum ( outBin )
2016-05-12 22:14:54 +00:00
}
2018-02-23 19:57:12 +00:00
src := filepath . Join ( pkRoot , filepath . FromSlash ( "vendor/github.com/gopherjs/gopherjs" ) )
2016-11-25 20:13:12 +00:00
goBin := "go"
if gopherjsGoroot != "" {
2018-02-23 19:57:12 +00:00
goBin = hostExeName ( filepath . Join ( gopherjsGoroot , "bin" , "go" ) )
2016-11-25 20:13:12 +00:00
}
2018-02-23 19:57:12 +00:00
cmd := exec . Command ( goBin , "install" , "-v" )
2016-05-12 22:14:54 +00:00
cmd . Dir = src
2018-04-19 10:58:56 +00:00
cmd . Env = os . Environ ( )
2016-08-26 21:58:40 +00:00
// forcing GOOS and GOARCH to prevent cross-compiling, as gopherjs will run on the
// current (host) platform.
2018-04-19 10:58:56 +00:00
cmd . Env = append ( cmd . Env , "GOOS=" + runtime . GOOS )
cmd . Env = append ( cmd . Env , "GOARCH=" + runtime . GOARCH )
2017-07-17 11:30:29 +00:00
if gopherjsGoroot != "" {
2018-04-19 10:58:56 +00:00
cmd . Env = append ( cmd . Env , "GOROOT=" + gopherjsGoroot )
2017-07-17 11:30:29 +00:00
}
2018-02-23 19:57:12 +00:00
var buf bytes . Buffer
cmd . Stderr = & buf
if err := cmd . Run ( ) ; err != nil {
return fmt . Errorf ( "error while building gopherjs: %v, %v" , err , buf . String ( ) )
}
if * verbose {
fmt . Println ( buf . String ( ) )
}
hashAfter := hashsum ( outBin )
if hashAfter != hashBefore {
log . Printf ( "gopherjs rebuilt at %v" , outBin )
return nil
2016-05-12 22:14:54 +00:00
}
2018-02-23 19:57:12 +00:00
// even if the source hasn't changed, apparently goinstall still at least bumps
// the modtime. Which means, 'gopherjs install' would then always rebuild its
// output too, even if no source changed since last time. We want to avoid that
// (because then parts of Perkeep get unnecessarily rebuilt too and yada yada), so
// we reset the modtime of gopherjs if the binary is the same as the previous time
// it was built.
return os . Chtimes ( outBin , modtime , modtime )
2016-05-12 22:14:54 +00:00
}
2018-02-23 19:57:12 +00:00
func hashsum ( filename string ) string {
h := sha256 . New ( )
f , err := os . Open ( filename )
if err != nil {
log . Fatalf ( "could not compute SHA256 of %v: %v" , filename , err )
2016-05-12 22:14:54 +00:00
}
2018-02-23 19:57:12 +00:00
defer f . Close ( )
if _ , err := io . Copy ( h , f ) ; err != nil {
log . Fatalf ( "could not compute SHA256 of %v: %v" , filename , err )
2016-05-12 22:14:54 +00:00
}
2018-02-23 19:57:12 +00:00
return string ( h . Sum ( nil ) )
2016-05-12 22:14:54 +00:00
}
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
// genSearchTypes duplicates some of the perkeep.org/pkg/search types into
// perkeep.org/app/publisher/js/zsearch.go , because it's too costly (in output
2016-07-15 00:10:07 +00:00
// file size) for now to import the search pkg into gopherjs.
func genSearchTypes ( ) error {
2018-02-23 19:57:12 +00:00
sourceFile := filepath . Join ( pkRoot , filepath . FromSlash ( "pkg/search/describe.go" ) )
outputFile := filepath . Join ( pkRoot , filepath . FromSlash ( "app/publisher/js/zsearch.go" ) )
2016-07-15 00:10:07 +00:00
fi1 , err := os . Stat ( sourceFile )
if err != nil {
return err
}
fi2 , err := os . Stat ( outputFile )
if err != nil && ! os . IsNotExist ( err ) {
return err
}
if err == nil && fi2 . ModTime ( ) . After ( fi1 . ModTime ( ) ) {
return nil
}
2018-04-19 10:58:56 +00:00
cmd := exec . Command ( "go" , "generate" , "-v" , "perkeep.org/app/publisher/js" )
2016-07-15 00:10:07 +00:00
if out , err := cmd . CombinedOutput ( ) ; err != nil {
return fmt . Errorf ( "go generate for publisher js error: %v, %v" , err , string ( out ) )
}
log . Printf ( "generated %v" , outputFile )
return nil
}
2018-02-23 19:57:12 +00:00
func genPublisherJS ( ) error {
2016-07-15 00:10:07 +00:00
if err := genSearchTypes ( ) ; err != nil {
return err
}
2018-02-23 19:57:12 +00:00
output := filepath . Join ( pkRoot , filepath . FromSlash ( publisherJS ) )
pkg := "perkeep.org/app/publisher/js"
return genJS ( pkg , output )
}
2016-05-12 22:14:54 +00:00
2018-02-23 19:57:12 +00:00
func genWebUIJS ( ) error {
output := filepath . Join ( pkRoot , filepath . FromSlash ( gopherjsUI ) )
2018-04-21 18:04:53 +00:00
pkg := "perkeep.org/server/perkeepd/ui/goui"
2018-02-23 19:57:12 +00:00
return genJS ( pkg , output )
}
2018-04-22 19:35:28 +00:00
func goPathBinDir ( ) ( string , error ) {
cmd := exec . Command ( "go" , "env" , "GOPATH" )
out , err := cmd . Output ( )
if err != nil {
return "" , fmt . Errorf ( "could not get GOPATH: %v, %s" , err , out )
}
paths := filepath . SplitList ( strings . TrimSpace ( string ( out ) ) )
if len ( paths ) < 1 {
return "" , errors . New ( "no GOPATH" )
}
return filepath . Join ( paths [ 0 ] , "bin" ) , nil
}
2018-02-23 19:57:12 +00:00
func genJS ( pkg , output string ) error {
// We want to use 'gopherjs install', and not 'gopherjs build', as the former is
// smarter and only rebuilds the output if needed. However, 'install' writes the
// output to GOPATH/bin, and not GOBIN. (https://github.com/gopherjs/gopherjs/issues/494)
// This means we have to be somewhat careful with naming our source pkg since gopherjs
// derives its output name from it.
// TODO(mpl): maybe rename the source pkg directories mentioned above.
if err := runGopherJS ( pkg ) ; err != nil {
2016-05-12 22:14:54 +00:00
return err
}
2018-02-23 19:57:12 +00:00
// TODO(mpl): set GOBIN, and remove all below, once
// https://github.com/gopherjs/gopherjs/issues/494 is fixed
2018-04-22 19:35:28 +00:00
binDir , err := goPathBinDir ( )
if err != nil {
return err
}
jsout := filepath . Join ( binDir , filepath . Base ( pkg ) + ".js" )
2018-02-23 19:57:12 +00:00
fi1 , err1 := os . Stat ( output )
if err1 != nil && ! os . IsNotExist ( err1 ) {
return err1
2016-05-12 22:14:54 +00:00
}
2018-02-23 19:57:12 +00:00
fi2 , err2 := os . Stat ( jsout )
if err2 != nil && ! os . IsNotExist ( err2 ) {
return err2
2016-05-12 22:14:54 +00:00
}
2018-02-23 19:57:12 +00:00
if err1 == nil && fi1 . ModTime ( ) . After ( fi2 . ModTime ( ) ) {
// output exists and is already up to date, nothing to do
return nil
2016-05-12 22:14:54 +00:00
}
2018-02-23 19:57:12 +00:00
data , err := ioutil . ReadFile ( jsout )
if err != nil {
2016-05-12 22:14:54 +00:00
return err
}
2018-02-23 19:57:12 +00:00
return ioutil . WriteFile ( output , data , 0600 )
2016-05-12 22:14:54 +00:00
}
2018-02-23 19:57:12 +00:00
func runGopherJS ( pkg string ) error {
gopherjsBin := hostExeName ( filepath . Join ( binDir , "gopherjs" ) )
args := [ ] string { "install" , pkg , "-v" , "--tags" , "nocgo noReactBundle" }
pkg/server: add files "zipper" to DownloadHandler
We want to add a feature for clients (the web UI), where they can select
a bunch of files and ask the server for a zip archive of all these files.
This CL modifies the DownloadHandler so it does exactly that upon
reception of a POST request with a query parameter of the form
files=sha1-foo,sha1-bar,sha1-baz
This CL also adds a new button to the contextual sidebar of the web UI,
that takes care of sending the download request to the server.
known limitations: only permanodes with file as camliContent are
accepted as a valid selection (i.e. no sets, or static-dirs, etc) for
now.
Implementation detail:
We're creating an ephemeral DOM form on the fly to send the request.
The reason is: if we sent it as a Go http request, we'd have to read
the response manually and then we'd have no way of writing it to disk.
If we did it with an xhr, we could write the response to disk by
creating a File or Blob and then using URL.createObjectURL(), but we'd
have to keep the response in memory while doing so, which is
unacceptable for large enough archives.
Fixes #899
Change-Id: I104f7c5bd10ab3369e28d33752380dd12b5b3e6b
2017-03-06 20:02:19 +00:00
if * embedResources {
// when embedding for "production", use -m to minify the javascript output
args = append ( args , "-m" )
}
2017-01-25 18:36:41 +00:00
cmd := exec . Command ( gopherjsBin , args ... )
2018-04-19 10:58:56 +00:00
cmd . Env = os . Environ ( )
2017-05-17 23:18:24 +00:00
// Pretend we're on linux regardless of the actual host, because recommended
// hack to work around https://github.com/gopherjs/gopherjs/issues/511
2018-04-19 10:58:56 +00:00
cmd . Env = append ( cmd . Env , "GOOS=linux" )
2017-07-17 11:30:29 +00:00
if gopherjsGoroot != "" {
2018-04-19 10:58:56 +00:00
cmd . Env = append ( cmd . Env , "GOROOT=" + gopherjsGoroot )
2017-07-17 11:30:29 +00:00
}
2018-02-23 19:57:12 +00:00
var buf bytes . Buffer
cmd . Stderr = & buf
err := cmd . Run ( )
2017-01-25 18:36:41 +00:00
if err != nil {
2018-02-23 19:57:12 +00:00
return fmt . Errorf ( "gopherjs for %v error: %v, %v" , pkg , err , buf . String ( ) )
2017-01-25 18:36:41 +00:00
}
2018-02-23 19:57:12 +00:00
if * verbose {
fmt . Println ( buf . String ( ) )
2017-01-25 18:36:41 +00:00
}
return nil
}
2018-02-23 19:57:12 +00:00
// genWebUIReact runs go generate on the gopherjs code of the web UI, which
2017-06-11 12:01:42 +00:00
// invokes reactGen on the Go React components. This generates the boilerplate
// code, in gen_*_reactGen.go files, required to complete those components.
func genWebUIReact ( ) error {
2018-04-21 18:04:53 +00:00
args := [ ] string { "generate" , "-v" , "perkeep.org/server/perkeepd/ui/goui/..." }
2017-06-11 12:01:42 +00:00
path := strings . Join ( [ ] string {
2018-02-23 19:57:12 +00:00
binDir ,
2017-06-11 12:01:42 +00:00
os . Getenv ( "PATH" ) ,
} , string ( os . PathListSeparator ) )
cmd := exec . Command ( "go" , args ... )
2018-04-19 10:58:56 +00:00
cmd . Env = os . Environ ( )
cmd . Env = append ( cmd . Env , "PATH=" + path )
2018-02-23 19:57:12 +00:00
var buf bytes . Buffer
cmd . Stderr = & buf
err := cmd . Run ( )
2016-05-12 22:14:54 +00:00
if err != nil {
2018-02-23 19:57:12 +00:00
return fmt . Errorf ( "go generate for web UI error: %v, %v" , err , buf . String ( ) )
2016-05-12 22:14:54 +00:00
}
2018-02-23 19:57:12 +00:00
if * verbose {
fmt . Println ( buf . String ( ) )
2016-05-12 22:14:54 +00:00
}
2018-02-23 19:57:12 +00:00
return nil
2016-05-12 22:14:54 +00:00
}
2018-02-23 19:57:12 +00:00
// makeJS builds and runs the gopherjs command on perkeep.org/app/publisher/js
2018-04-21 18:04:53 +00:00
// and perkeep.org/server/perkeepd/ui/goui
2018-02-23 19:57:12 +00:00
func makeJS ( doWebUI , doPublisher bool ) error {
if err := buildGopherjs ( ) ; err != nil {
2016-05-12 22:14:54 +00:00
return fmt . Errorf ( "error building gopherjs: %v" , err )
}
2018-02-23 19:57:12 +00:00
if doPublisher {
if err := genPublisherJS ( ) ; err != nil {
return err
devcam test: do not "recurse" temp GOPATH, docs, couple more options.
Problem: make.go creates an isolated temp gopath ./tmp/build-gopath. The
integration tests make use of that gopath (by running make.go) to build
the tools, and run the test world in it. Similarly, devcam test uses
make.go to setup that temp gopath, and runs the tests from the source
files in that gopath. Consequently, when the integration tests are run
through devcam test, even though they're run from the temp gopath, they
would use the make.go in it, which would create a nested temp gopath
(CAMLIROOT/tmp/build-gopath/src/camlistore.org/tmp/build-gopath) in
which to run the tests.
This patch addresses this issue by creating a new flag (-envGoPath), and
the corresponding env var (CAMLI_MAKE_USEGOPATH), which tells make.go
not to create a new temporary gopath (and hence not to mirror any
files), and to rely on the already set GOPATH env var instead.
Also refactored make.go a bit, and added a couple options and doc to
devcam test.
Change-Id: Ia8a5d7a31e6e317f05218d9e18fb886001cd19cb
2014-08-06 16:47:42 +00:00
}
}
2018-02-23 19:57:12 +00:00
if doWebUI {
if err := genWebUIJS ( ) ; err != nil {
return err
2014-08-08 23:11:53 +00:00
}
}
2018-02-23 19:57:12 +00:00
return nil
2013-09-04 02:48:32 +00:00
}
2013-07-11 09:49:54 +00:00
// Create an environment variable of the form key=value.
func envPair ( key , value string ) string {
return fmt . Sprintf ( "%s=%s" , key , value )
}
2018-04-19 10:58:56 +00:00
// cleanGoEnv returns a copy of the current environment with any variable listed
// in others removed. Also, when cross-compiling, it removes GOBIN and sets GOOS
// and GOARCH, and GOARM as needed.
2017-06-11 12:01:42 +00:00
func cleanGoEnv ( others ... string ) ( clean [ ] string ) {
excl := make ( [ ] string , len ( others ) )
for i , v := range others {
excl [ i ] = v + "="
}
Env :
2013-06-18 22:21:56 +00:00
for _ , env := range os . Environ ( ) {
2017-06-11 12:01:42 +00:00
for _ , v := range excl {
if strings . HasPrefix ( env , v ) {
continue Env
}
}
2018-04-19 10:58:56 +00:00
// remove GOBIN if we're cross-compiling
if strings . HasPrefix ( env , "GOBIN=" ) &&
( * buildOS != runtime . GOOS || * buildARCH != runtime . GOARCH ) {
2013-06-18 22:21:56 +00:00
continue
}
2013-08-20 14:46:32 +00:00
// We skip these two as well, otherwise they'd take precedence over the
// ones appended below.
if * buildOS != runtime . GOOS && strings . HasPrefix ( env , "GOOS=" ) {
continue
}
if * buildARCH != runtime . GOARCH && strings . HasPrefix ( env , "GOARCH=" ) {
continue
}
2016-03-11 18:57:36 +00:00
// If we're building for ARM (regardless of cross-compiling or not), we reset GOARM
if * buildARCH == "arm" && strings . HasPrefix ( env , "GOARM=" ) {
continue
}
2013-06-18 22:21:56 +00:00
clean = append ( clean , env )
}
2013-07-05 17:41:07 +00:00
if * buildOS != runtime . GOOS {
2013-07-11 09:49:54 +00:00
clean = append ( clean , envPair ( "GOOS" , * buildOS ) )
}
if * buildARCH != runtime . GOARCH {
clean = append ( clean , envPair ( "GOARCH" , * buildARCH ) )
2016-03-11 18:57:36 +00:00
}
// If we're building for ARM (regardless of cross-compiling or not), we reset GOARM
if * buildARCH == "arm" {
clean = append ( clean , envPair ( "GOARM" , * buildARM ) )
2013-07-05 17:41:07 +00:00
}
2013-06-18 22:21:56 +00:00
return
}
2013-09-11 05:42:24 +00:00
func stringListContains ( strs [ ] string , str string ) bool {
for _ , s := range strs {
if s == str {
return true
}
}
return false
}
2018-02-23 19:57:12 +00:00
// fullSrcPath returns the full path concatenation
// of pkRoot with fromSrc.
func fullSrcPath ( fromSrc string ) string {
return filepath . Join ( pkRoot , filepath . FromSlash ( fromSrc ) )
2013-06-20 13:49:34 +00:00
}
func genEmbeds ( ) error {
2018-02-23 19:57:12 +00:00
cmdName := hostExeName ( filepath . Join ( binDir , "genfileembed" ) )
2016-06-06 23:53:46 +00:00
for _ , embeds := range [ ] string {
2018-04-21 18:04:53 +00:00
"server/perkeepd/ui" ,
2016-06-06 23:53:46 +00:00
"pkg/server" ,
2018-01-09 22:24:59 +00:00
"clients/web/embed/fontawesome" ,
"clients/web/embed/glitch" ,
"clients/web/embed/leaflet" ,
"clients/web/embed/less" ,
"clients/web/embed/opensans" ,
"clients/web/embed/react" ,
2016-06-06 23:53:46 +00:00
"app/publisher" ,
"app/scanningcabinet/ui" ,
} {
2018-02-23 19:57:12 +00:00
embeds := fullSrcPath ( embeds )
2017-12-08 08:24:14 +00:00
var args [ ] string
2018-04-18 21:59:02 +00:00
args = append ( args , embeds )
2013-06-20 13:49:34 +00:00
cmd := exec . Command ( cmdName , args ... )
cmd . Stdout = os . Stdout
2018-04-18 21:59:02 +00:00
var buf bytes . Buffer
cmd . Stderr = & buf
2013-06-20 13:49:34 +00:00
if * verbose {
log . Printf ( "Running %s %s" , cmdName , embeds )
}
2018-04-18 21:59:02 +00:00
if err := cmd . Run ( ) ; err != nil {
os . Stderr . Write ( buf . Bytes ( ) )
return fmt . Errorf ( "error running %s %s: %v" , cmdName , embeds , err )
2013-06-20 13:49:34 +00:00
}
2018-04-18 21:59:02 +00:00
if * verbose {
fmt . Println ( buf . String ( ) )
2013-06-20 13:49:34 +00:00
}
}
return nil
}
func buildGenfileembed ( ) error {
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
return buildBin ( "perkeep.org/pkg/fileembed/genfileembed" )
2017-06-11 12:01:42 +00:00
}
func buildReactGen ( ) error {
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
return buildBin ( "perkeep.org/vendor/myitcv.io/react/cmd/reactGen" )
2017-06-11 12:01:42 +00:00
}
2018-04-19 10:58:56 +00:00
func buildDevcam ( ) error {
return buildBin ( "perkeep.org/dev/devcam" )
}
2017-06-11 12:01:42 +00:00
func buildBin ( pkg string ) error {
pkgBase := pathpkg . Base ( pkg )
2013-06-18 23:04:27 +00:00
args := [ ] string { "install" , "-v" }
args = append ( args ,
2017-06-11 12:01:42 +00:00
filepath . FromSlash ( pkg ) ,
2013-06-18 23:04:27 +00:00
)
cmd := exec . Command ( "go" , args ... )
cmd . Stdout = os . Stdout
cmd . Stderr = os . Stderr
if * verbose {
log . Printf ( "Running go with args %s" , args )
}
if err := cmd . Run ( ) ; err != nil {
2017-06-11 12:01:42 +00:00
return fmt . Errorf ( "Error building %v: %v" , pkgBase , err )
2013-06-18 23:04:27 +00:00
}
if * verbose {
2018-04-19 10:58:56 +00:00
log . Printf ( "%v installed in %s" , pkgBase , actualBinDir ( ) )
2013-06-18 23:04:27 +00:00
}
return nil
}
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
// getVersion returns the version of Perkeep. Either from a VERSION file at the root,
2013-06-10 22:55:17 +00:00
// or from git.
devcam test: do not "recurse" temp GOPATH, docs, couple more options.
Problem: make.go creates an isolated temp gopath ./tmp/build-gopath. The
integration tests make use of that gopath (by running make.go) to build
the tools, and run the test world in it. Similarly, devcam test uses
make.go to setup that temp gopath, and runs the tests from the source
files in that gopath. Consequently, when the integration tests are run
through devcam test, even though they're run from the temp gopath, they
would use the make.go in it, which would create a nested temp gopath
(CAMLIROOT/tmp/build-gopath/src/camlistore.org/tmp/build-gopath) in
which to run the tests.
This patch addresses this issue by creating a new flag (-envGoPath), and
the corresponding env var (CAMLI_MAKE_USEGOPATH), which tells make.go
not to create a new temporary gopath (and hence not to mirror any
files), and to rely on the already set GOPATH env var instead.
Also refactored make.go a bit, and added a couple options and doc to
devcam test.
Change-Id: Ia8a5d7a31e6e317f05218d9e18fb886001cd19cb
2014-08-06 16:47:42 +00:00
func getVersion ( ) string {
2018-02-23 19:57:12 +00:00
slurp , err := ioutil . ReadFile ( filepath . Join ( pkRoot , "VERSION" ) )
2013-06-10 22:55:17 +00:00
if err == nil {
return strings . TrimSpace ( string ( slurp ) )
}
devcam test: do not "recurse" temp GOPATH, docs, couple more options.
Problem: make.go creates an isolated temp gopath ./tmp/build-gopath. The
integration tests make use of that gopath (by running make.go) to build
the tools, and run the test world in it. Similarly, devcam test uses
make.go to setup that temp gopath, and runs the tests from the source
files in that gopath. Consequently, when the integration tests are run
through devcam test, even though they're run from the temp gopath, they
would use the make.go in it, which would create a nested temp gopath
(CAMLIROOT/tmp/build-gopath/src/camlistore.org/tmp/build-gopath) in
which to run the tests.
This patch addresses this issue by creating a new flag (-envGoPath), and
the corresponding env var (CAMLI_MAKE_USEGOPATH), which tells make.go
not to create a new temporary gopath (and hence not to mirror any
files), and to rely on the already set GOPATH env var instead.
Also refactored make.go a bit, and added a couple options and doc to
devcam test.
Change-Id: Ia8a5d7a31e6e317f05218d9e18fb886001cd19cb
2014-08-06 16:47:42 +00:00
return gitVersion ( )
2013-07-29 01:15:04 +00:00
}
2017-01-30 16:32:09 +00:00
var gitVersionRx = regexp . MustCompile ( ` \b\d\d\d\d-\d\d-\d\d-[0-9a-f] { 10,10}\b ` )
2013-07-29 01:15:04 +00:00
2018-02-23 19:57:12 +00:00
// gitVersion returns the git version of the git repo at pkRoot as a
2013-07-29 01:15:04 +00:00
// string of the form "yyyy-mm-dd-xxxxxxx", with an optional trailing
2017-09-10 13:28:34 +00:00
// '+' if there are any local uncommitted modifications to the tree.
devcam test: do not "recurse" temp GOPATH, docs, couple more options.
Problem: make.go creates an isolated temp gopath ./tmp/build-gopath. The
integration tests make use of that gopath (by running make.go) to build
the tools, and run the test world in it. Similarly, devcam test uses
make.go to setup that temp gopath, and runs the tests from the source
files in that gopath. Consequently, when the integration tests are run
through devcam test, even though they're run from the temp gopath, they
would use the make.go in it, which would create a nested temp gopath
(CAMLIROOT/tmp/build-gopath/src/camlistore.org/tmp/build-gopath) in
which to run the tests.
This patch addresses this issue by creating a new flag (-envGoPath), and
the corresponding env var (CAMLI_MAKE_USEGOPATH), which tells make.go
not to create a new temporary gopath (and hence not to mirror any
files), and to rely on the already set GOPATH env var instead.
Also refactored make.go a bit, and added a couple options and doc to
devcam test.
Change-Id: Ia8a5d7a31e6e317f05218d9e18fb886001cd19cb
2014-08-06 16:47:42 +00:00
func gitVersion ( ) string {
2017-01-30 16:32:09 +00:00
cmd := exec . Command ( "git" , "rev-list" , "--max-count=1" , "--pretty=format:'%ad-%h'" ,
"--date=short" , "--abbrev=10" , "HEAD" )
2018-02-23 19:57:12 +00:00
cmd . Dir = pkRoot
2013-07-29 01:15:04 +00:00
out , err := cmd . Output ( )
2013-06-10 22:55:17 +00:00
if err != nil {
2018-02-23 19:57:12 +00:00
log . Fatalf ( "Error running git rev-list in %s: %v" , pkRoot , err )
2013-07-29 01:15:04 +00:00
}
v := strings . TrimSpace ( string ( out ) )
if m := gitVersionRx . FindStringSubmatch ( v ) ; m != nil {
v = m [ 0 ]
} else {
panic ( "Failed to find git version in " + v )
}
cmd = exec . Command ( "git" , "diff" , "--exit-code" )
2018-02-23 19:57:12 +00:00
cmd . Dir = pkRoot
2013-07-29 01:15:04 +00:00
if err := cmd . Run ( ) ; err != nil {
v += "+"
2013-06-10 22:55:17 +00:00
}
2013-07-29 01:15:04 +00:00
return v
2013-06-10 22:55:17 +00:00
}
2018-02-23 19:57:12 +00:00
// verifyPerkeepRoot sets pkRoot and crashes if dir isn't the Perkeep root directory.
func verifyPerkeepRoot ( ) {
var err error
pkRoot , err = os . Getwd ( )
if err != nil {
log . Fatalf ( "Failed to get current directory: %v" , err )
}
testFile := filepath . Join ( pkRoot , "pkg" , "blob" , "ref.go" )
2013-06-10 22:55:17 +00:00
if _ , err := os . Stat ( testFile ) ; err != nil {
2018-02-23 19:57:12 +00:00
log . Fatalf ( "make.go must be run from the Perkeep src root directory (where make.go is). Current working directory is %s" , pkRoot )
2013-06-10 22:55:17 +00:00
}
2018-04-23 03:16:51 +00:00
validateDirInGOPATH ( pkRoot )
2018-04-19 10:58:56 +00:00
cmd := exec . Command ( "go" , "list" , "-f" , "{{.Target}}" , "perkeep.org/cmd/pk" )
cmd . Stderr = os . Stderr
out , err := cmd . Output ( )
if err != nil {
log . Fatalf ( "Could not run go list to find install dir: %v, %s" , err , out )
}
binDir = filepath . Dir ( strings . TrimSpace ( string ( out ) ) )
2013-06-10 22:55:17 +00:00
}
2018-04-23 03:16:51 +00:00
func validateDirInGOPATH ( dir string ) {
fi , err := os . Lstat ( dir )
if err != nil {
log . Fatal ( err )
}
gopathEnv , err := exec . Command ( "go" , "env" , "GOPATH" ) . Output ( )
if err != nil {
log . Fatalf ( "error finding GOPATH: %v" , err )
}
gopaths := filepath . SplitList ( strings . TrimSpace ( string ( gopathEnv ) ) )
if len ( gopaths ) == 0 {
log . Fatalf ( "failed to find your GOPATH: go env GOPATH returned nothing" )
}
var validOpts [ ] string
for _ , gopath := range gopaths {
validDir := filepath . Join ( gopath , "src" , "perkeep.org" )
validOpts = append ( validOpts , validDir )
fi2 , err := os . Lstat ( validDir )
if os . IsNotExist ( err ) {
continue
}
if err != nil {
log . Fatal ( err )
}
if os . SameFile ( fi , fi2 ) {
// In a valid directory.
return
}
}
if len ( validOpts ) == 1 {
log . Fatalf ( "make.go cannot be run from %s; it must be in a valid GOPATH. Move the directory containing make.go to %s" , dir , validOpts [ 0 ] )
} else {
log . Fatalf ( "make.go cannot be run from %s; it must be in a valid GOPATH. Move the directory containing make.go to one of %q" , dir , validOpts )
}
}
2017-02-17 00:17:20 +00:00
const (
2018-04-04 00:07:04 +00:00
goVersionMinor = 10
gopherJSGoMinor = 10
2017-02-17 00:17:20 +00:00
)
2016-11-25 20:13:12 +00:00
2018-02-19 01:34:10 +00:00
var validVersionRx = regexp . MustCompile ( ` go version go1\.(\d+) ` )
// verifyGoVersion runs "go version" and parses the output. If the version is
// acceptable a check for gopherjs versions are also done. If problems
// are found a message is logged and we abort.
2013-06-10 22:55:17 +00:00
func verifyGoVersion ( ) {
_ , err := exec . LookPath ( "go" )
if err != nil {
2018-02-19 01:34:10 +00:00
log . Fatalf ( "Go doesn't appear to be installed ('go' isn't in your PATH). Install Go 1.%d or newer." , goVersionMinor )
2013-06-10 22:55:17 +00:00
}
out , err := exec . Command ( "go" , "version" ) . Output ( )
if err != nil {
log . Fatalf ( "Error checking Go version with the 'go' command: %v" , err )
}
2018-02-19 01:34:10 +00:00
version := string ( out )
// Handle non-versioned binaries
// ex: "go version devel +c26fac8 Thu Feb 15 21:41:39 2018 +0000 linux/amd64"
if strings . HasPrefix ( version , "go version devel " ) {
2018-02-26 17:08:51 +00:00
verifyGopherjsGoroot ( " devel" )
2014-08-06 15:50:44 +00:00
return
}
2018-02-19 01:34:10 +00:00
m := validVersionRx . FindStringSubmatch ( version )
if m == nil {
log . Fatalf ( "Unexpected output while checking 'go version': %q" , version )
2014-08-06 15:50:44 +00:00
}
2018-02-19 01:34:10 +00:00
minorVersion , err := strconv . Atoi ( m [ 1 ] )
if err != nil {
log . Fatalf ( "Unexpected error while parsing version string %q: %v" , m [ 1 ] , err )
}
if minorVersion < goVersionMinor {
2018-02-28 23:13:28 +00:00
log . Fatalf ( "Your version of Go (%s) is too old. Perkeep requires Go 1.%d or later." , string ( out ) , goVersionMinor )
2018-02-19 01:34:10 +00:00
}
if minorVersion != gopherJSGoMinor {
2018-02-26 17:08:51 +00:00
verifyGopherjsGoroot ( fmt . Sprintf ( "1.%d" , minorVersion ) )
2013-06-10 22:55:17 +00:00
}
2016-11-25 20:13:12 +00:00
}
2018-02-26 17:08:51 +00:00
func verifyGopherjsGoroot ( goFound string ) {
2018-02-23 19:57:12 +00:00
gopherjsGoroot = os . Getenv ( "CAMLI_GOPHERJS_GOROOT" )
goBin := hostExeName ( filepath . Join ( gopherjsGoroot , "bin" , "go" ) )
2016-11-25 20:13:12 +00:00
if gopherjsGoroot == "" {
2018-02-26 17:08:51 +00:00
goInHomeDir , err := findGopherJSGoroot ( )
if err != nil {
log . Fatalf ( "Error while looking for a go1.%d dir in %v: %v" , gopherJSGoMinor , homeDir ( ) , err )
}
if goInHomeDir == "" {
log . Fatalf ( "You're using go%s != go1.%d, which GopherJS requires, and it was not found in %v. You need to specify a go1.%d root in CAMLI_GOPHERJS_GOROOT for building GopherJS." , goFound , gopherJSGoMinor , homeDir ( ) , gopherJSGoMinor )
}
gopherjsGoroot = filepath . Join ( homeDir ( ) , goInHomeDir )
2018-02-23 19:57:12 +00:00
goBin = hostExeName ( filepath . Join ( gopherjsGoroot , "bin" , "go" ) )
2018-02-26 17:08:51 +00:00
log . Printf ( "You're using go%s != go1.%d, which GopherJS requires, and CAMLI_GOPHERJS_GOROOT was not provided, so defaulting to %v for building GopherJS instead." , goFound , gopherJSGoMinor , goBin )
2016-11-25 20:13:12 +00:00
}
if _ , err := os . Stat ( goBin ) ; err != nil {
if ! os . IsNotExist ( err ) {
log . Fatal ( err )
}
2018-02-26 17:08:51 +00:00
log . Fatalf ( "%v not found. You need to specify a go1.%d root in CAMLI_GOPHERJS_GOROOT for building GopherJS" , goBin , gopherJSGoMinor )
}
}
// findGopherJSGoroot tries to find a go1.gopherJSGoMinor.* go root in the home
// directory. It returns the empty string and no error if none was found.
func findGopherJSGoroot ( ) ( string , error ) {
dir , err := os . Open ( homeDir ( ) )
if err != nil {
return "" , err
}
defer dir . Close ( )
names , err := dir . Readdirnames ( - 1 )
if err != nil {
return "" , err
}
goVersion := fmt . Sprintf ( "go1.%d" , gopherJSGoMinor )
for _ , name := range names {
if strings . HasPrefix ( name , goVersion ) {
return name , nil
}
2016-11-25 20:13:12 +00:00
}
2018-02-26 17:08:51 +00:00
return "" , nil
2013-06-10 22:55:17 +00:00
}
devcam test: do not "recurse" temp GOPATH, docs, couple more options.
Problem: make.go creates an isolated temp gopath ./tmp/build-gopath. The
integration tests make use of that gopath (by running make.go) to build
the tools, and run the test world in it. Similarly, devcam test uses
make.go to setup that temp gopath, and runs the tests from the source
files in that gopath. Consequently, when the integration tests are run
through devcam test, even though they're run from the temp gopath, they
would use the make.go in it, which would create a nested temp gopath
(CAMLIROOT/tmp/build-gopath/src/camlistore.org/tmp/build-gopath) in
which to run the tests.
This patch addresses this issue by creating a new flag (-envGoPath), and
the corresponding env var (CAMLI_MAKE_USEGOPATH), which tells make.go
not to create a new temporary gopath (and hence not to mirror any
files), and to rely on the already set GOPATH env var instead.
Also refactored make.go a bit, and added a couple options and doc to
devcam test.
Change-Id: Ia8a5d7a31e6e317f05218d9e18fb886001cd19cb
2014-08-06 16:47:42 +00:00
func withSQLite ( ) bool {
cross := runtime . GOOS != * buildOS || runtime . GOARCH != * buildARCH
var sql bool
var err error
if * sqlFlag == "auto" {
sql = ! cross && haveSQLite
} else {
sql , err = strconv . ParseBool ( * sqlFlag )
if err != nil {
log . Fatalf ( "Bad boolean --sql flag %q" , * sqlFlag )
}
}
if cross && sql {
log . Fatalf ( "SQLite isn't available when cross-compiling to another OS. Set --sqlite=false." )
}
if sql && ! haveSQLite {
2018-01-21 18:14:40 +00:00
// TODO(lindner): fix these docs.
devcam test: do not "recurse" temp GOPATH, docs, couple more options.
Problem: make.go creates an isolated temp gopath ./tmp/build-gopath. The
integration tests make use of that gopath (by running make.go) to build
the tools, and run the test world in it. Similarly, devcam test uses
make.go to setup that temp gopath, and runs the tests from the source
files in that gopath. Consequently, when the integration tests are run
through devcam test, even though they're run from the temp gopath, they
would use the make.go in it, which would create a nested temp gopath
(CAMLIROOT/tmp/build-gopath/src/camlistore.org/tmp/build-gopath) in
which to run the tests.
This patch addresses this issue by creating a new flag (-envGoPath), and
the corresponding env var (CAMLI_MAKE_USEGOPATH), which tells make.go
not to create a new temporary gopath (and hence not to mirror any
files), and to rely on the already set GOPATH env var instead.
Also refactored make.go a bit, and added a couple options and doc to
devcam test.
Change-Id: Ia8a5d7a31e6e317f05218d9e18fb886001cd19cb
2014-08-06 16:47:42 +00:00
log . Printf ( "SQLite not found. Either install it, or run make.go with --sqlite=false See https://code.google.com/p/camlistore/wiki/SQLite" )
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" :
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
log . Printf ( "SQLite is not easy on windows. Please see https://perkeep.org/doc/server-config#windows" )
devcam test: do not "recurse" temp GOPATH, docs, couple more options.
Problem: make.go creates an isolated temp gopath ./tmp/build-gopath. The
integration tests make use of that gopath (by running make.go) to build
the tools, and run the test world in it. Similarly, devcam test uses
make.go to setup that temp gopath, and runs the tests from the source
files in that gopath. Consequently, when the integration tests are run
through devcam test, even though they're run from the temp gopath, they
would use the make.go in it, which would create a nested temp gopath
(CAMLIROOT/tmp/build-gopath/src/camlistore.org/tmp/build-gopath) in
which to run the tests.
This patch addresses this issue by creating a new flag (-envGoPath), and
the corresponding env var (CAMLI_MAKE_USEGOPATH), which tells make.go
not to create a new temporary gopath (and hence not to mirror any
files), and to rely on the already set GOPATH env var instead.
Also refactored make.go a bit, and added a couple options and doc to
devcam test.
Change-Id: Ia8a5d7a31e6e317f05218d9e18fb886001cd19cb
2014-08-06 16:47:42 +00:00
}
os . Exit ( 2 )
}
return sql
}
2013-08-25 17:57:51 +00:00
func checkHaveSQLite ( ) bool {
2013-06-10 22:55:17 +00:00
if runtime . GOOS == "windows" {
// TODO: Find some other non-pkg-config way to test, like
// just compiling a small Go program that sees whether
// it's available.
//
// For now:
return false
}
_ , err := exec . LookPath ( "pkg-config" )
if err != nil {
2013-08-25 17:57:51 +00:00
return false
2013-06-10 22:55:17 +00:00
}
2013-12-25 02:24:24 +00:00
out , err := exec . Command ( "pkg-config" , "--libs" , "sqlite3" ) . Output ( )
2013-06-14 20:21:04 +00:00
if err != nil && err . Error ( ) == "exit status 1" {
// This is sloppy (comparing against a string), but
// doing it correctly requires using multiple *.go
// files to portably get the OS-syscall bits, and I
// want to keep make.go a single file.
return false
}
2013-06-10 22:55:17 +00:00
if err != nil {
log . Fatalf ( "Can't determine whether sqlite3 is available, and where. pkg-config error was: %v, %s" , err , out )
}
return strings . TrimSpace ( string ( out ) ) != ""
}
2013-06-18 20:02:03 +00:00
devcam test: do not "recurse" temp GOPATH, docs, couple more options.
Problem: make.go creates an isolated temp gopath ./tmp/build-gopath. The
integration tests make use of that gopath (by running make.go) to build
the tools, and run the test world in it. Similarly, devcam test uses
make.go to setup that temp gopath, and runs the tests from the source
files in that gopath. Consequently, when the integration tests are run
through devcam test, even though they're run from the temp gopath, they
would use the make.go in it, which would create a nested temp gopath
(CAMLIROOT/tmp/build-gopath/src/camlistore.org/tmp/build-gopath) in
which to run the tests.
This patch addresses this issue by creating a new flag (-envGoPath), and
the corresponding env var (CAMLI_MAKE_USEGOPATH), which tells make.go
not to create a new temporary gopath (and hence not to mirror any
files), and to rely on the already set GOPATH env var instead.
Also refactored make.go a bit, and added a couple options and doc to
devcam test.
Change-Id: Ia8a5d7a31e6e317f05218d9e18fb886001cd19cb
2014-08-06 16:47:42 +00:00
func doEmbed ( ) {
if * verbose {
log . Printf ( "Embedding resources..." )
}
2018-04-21 18:04:53 +00:00
closureEmbed := fullSrcPath ( "server/perkeepd/ui/closure/z_data.go" )
2018-02-23 19:57:12 +00:00
closureSrcDir := filepath . Join ( pkRoot , filepath . FromSlash ( "clients/web/embed/closure/lib" ) )
devcam test: do not "recurse" temp GOPATH, docs, couple more options.
Problem: make.go creates an isolated temp gopath ./tmp/build-gopath. The
integration tests make use of that gopath (by running make.go) to build
the tools, and run the test world in it. Similarly, devcam test uses
make.go to setup that temp gopath, and runs the tests from the source
files in that gopath. Consequently, when the integration tests are run
through devcam test, even though they're run from the temp gopath, they
would use the make.go in it, which would create a nested temp gopath
(CAMLIROOT/tmp/build-gopath/src/camlistore.org/tmp/build-gopath) in
which to run the tests.
This patch addresses this issue by creating a new flag (-envGoPath), and
the corresponding env var (CAMLI_MAKE_USEGOPATH), which tells make.go
not to create a new temporary gopath (and hence not to mirror any
files), and to rely on the already set GOPATH env var instead.
Also refactored make.go a bit, and added a couple options and doc to
devcam test.
Change-Id: Ia8a5d7a31e6e317f05218d9e18fb886001cd19cb
2014-08-06 16:47:42 +00:00
err := embedClosure ( closureSrcDir , closureEmbed )
if err != nil {
log . Fatal ( err )
}
if err = buildGenfileembed ( ) ; err != nil {
log . Fatal ( err )
}
if err = genEmbeds ( ) ; err != nil {
log . Fatal ( err )
}
}
2013-06-18 20:02:03 +00:00
func embedClosure ( closureDir , embedFile string ) error {
if _ , err := os . Stat ( closureDir ) ; err != nil {
return fmt . Errorf ( "Could not stat %v: %v" , closureDir , err )
}
2015-02-06 08:37:38 +00:00
// first collect the files and modTime
2013-06-19 06:14:36 +00:00
var modTime time . Time
2015-02-06 08:37:38 +00:00
type pathAndSuffix struct {
path , suffix string
}
var files [ ] pathAndSuffix
2013-06-18 20:02:03 +00:00
err := filepath . Walk ( closureDir , func ( path string , fi os . FileInfo , err error ) error {
if err != nil {
return err
}
suffix , err := filepath . Rel ( closureDir , path )
if err != nil {
return fmt . Errorf ( "Failed to find Rel(%q, %q): %v" , closureDir , path , err )
}
if fi . IsDir ( ) {
return nil
}
2013-06-19 06:14:36 +00:00
if mt := fi . ModTime ( ) ; mt . After ( modTime ) {
modTime = mt
}
2015-02-06 08:37:38 +00:00
files = append ( files , pathAndSuffix { path , suffix } )
return nil
} )
if err != nil {
return err
}
// do not regenerate the whole embedFile if it exists and newer than modTime.
if fi , err := os . Stat ( embedFile ) ; err == nil && fi . Size ( ) > 0 && fi . ModTime ( ) . After ( modTime ) {
if * verbose {
log . Printf ( "skipping regeneration of %s" , embedFile )
}
return nil
}
// second, zip it
var zipbuf bytes . Buffer
var zipdest io . Writer = & zipbuf
if os . Getenv ( "CAMLI_WRITE_TMP_ZIP" ) != "" {
f , _ := os . Create ( "/tmp/camli-closure.zip" )
zipdest = io . MultiWriter ( zipdest , f )
defer f . Close ( )
}
w := zip . NewWriter ( zipdest )
for _ , elt := range files {
b , err := ioutil . ReadFile ( elt . path )
2013-06-18 20:02:03 +00:00
if err != nil {
return err
}
2015-02-06 08:37:38 +00:00
f , err := w . Create ( filepath . ToSlash ( elt . suffix ) )
2013-06-18 20:02:03 +00:00
if err != nil {
2015-02-06 08:37:38 +00:00
return err
}
if _ , err = f . Write ( b ) ; err != nil {
return err
2013-06-18 20:02:03 +00:00
}
}
2015-02-06 08:37:38 +00:00
if err = w . Close ( ) ; err != nil {
2013-06-18 20:02:03 +00:00
return err
}
// then embed it as a quoted string
var qb bytes . Buffer
fmt . Fprint ( & qb , "package closure\n\n" )
2013-06-19 06:14:36 +00:00
fmt . Fprint ( & qb , "import \"time\"\n\n" )
fmt . Fprint ( & qb , "func init() {\n" )
fmt . Fprintf ( & qb , "\tZipModTime = time.Unix(%d, 0)\n" , modTime . Unix ( ) )
fmt . Fprint ( & qb , "\tZipData = " )
2013-06-18 20:02:03 +00:00
quote ( & qb , zipbuf . Bytes ( ) )
2013-06-19 06:14:36 +00:00
fmt . Fprint ( & qb , "\n}\n" )
2013-06-18 20:02:03 +00:00
// and write to a .go file
if err := writeFileIfDifferent ( embedFile , qb . Bytes ( ) ) ; err != nil {
return err
}
return nil
}
func writeFileIfDifferent ( filename string , contents [ ] byte ) error {
fi , err := os . Stat ( filename )
if err == nil && fi . Size ( ) == int64 ( len ( contents ) ) && contentsEqual ( filename , contents ) {
return nil
}
return ioutil . WriteFile ( filename , contents , 0644 )
}
func contentsEqual ( filename string , contents [ ] byte ) bool {
got , err := ioutil . ReadFile ( filename )
2014-08-17 00:35:38 +00:00
if os . IsNotExist ( err ) {
2013-06-18 20:02:03 +00:00
return false
}
2014-08-17 00:35:38 +00:00
if err != nil {
log . Fatalf ( "Error reading %v: %v" , filename , err )
}
2013-06-18 20:02:03 +00:00
return bytes . Equal ( got , contents )
}
// quote escapes and quotes the bytes from bs and writes
// them to dest.
func quote ( dest * bytes . Buffer , bs [ ] byte ) {
dest . WriteByte ( '"' )
for _ , b := range bs {
if b == '\n' {
dest . WriteString ( ` \n ` )
2013-06-19 01:39:43 +00:00
continue
2013-06-18 20:02:03 +00:00
}
if b == '\\' {
dest . WriteString ( ` \\ ` )
continue
}
if b == '"' {
dest . WriteString ( ` \" ` )
continue
}
if ( b >= 32 && b <= 126 ) || b == '\t' {
dest . WriteByte ( b )
continue
}
fmt . Fprintf ( dest , "\\x%02x" , b )
}
dest . WriteByte ( '"' )
}
2013-09-21 11:45:36 +00:00
2018-02-23 19:57:12 +00:00
// hostExeName returns the executable name
2018-03-19 10:52:43 +00:00
// for s on the currently running host OS.
2018-02-23 19:57:12 +00:00
func hostExeName ( s string ) string {
2018-03-19 10:52:43 +00:00
if runtime . GOOS == "windows" {
return s + ".exe"
}
return s
}
2016-11-25 20:13:12 +00:00
// copied from pkg/osutil/paths.go
func homeDir ( ) string {
if runtime . GOOS == "windows" {
return os . Getenv ( "HOMEDRIVE" ) + os . Getenv ( "HOMEPATH" )
}
return os . Getenv ( "HOME" )
}
2018-01-02 01:16:18 +00:00
func failIfCamlistoreOrgDir ( ) {
2018-01-02 01:27:42 +00:00
dir , _ := os . Getwd ( )
2018-01-02 01:16:18 +00:00
if strings . HasSuffix ( dir , "camlistore.org" ) {
log . Fatalf ( ` Camlistore was renamed to Perkeep . Your current directory ( % s ) looks like a camlistore . org directory .
We ' re expecting you to be in a perkeep . org directory now .
2018-01-06 03:49:59 +00:00
See https : //github.com/perkeep/perkeep/issues/981#issuecomment-354690313 for details.
2018-01-02 01:16:18 +00:00
You need to rename your "camlistore.org" parent directory to "perkeep.org"
` , dir )
}
}