2013-07-08 00:35:10 +00:00
// +build ignore
2013-06-10 22:55:17 +00:00
/ *
Copyright 2013 Google Inc .
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 .
* /
// This program builds Camlistore.
//
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
// Camlistore root, where make.go is)
package main
import (
2013-06-18 20:02:03 +00:00
"archive/zip"
2014-08-17 01:19:38 +00:00
"bufio"
2013-06-18 20:02:03 +00:00
"bytes"
2016-05-12 22:14:54 +00:00
"crypto/sha256"
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-06-18 20:02:03 +00:00
all = flag . Bool ( "all" , false , "Force rebuild of everything (go install -a)" )
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" )
2014-02-20 04:56:05 +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: camlistore.org/server/camlistored,camlistore.org/cmd/camput" )
2013-06-29 20:52:01 +00:00
quiet = flag . Bool ( "quiet" , false , "Don't print anything unless there's a failure." )
2013-09-11 17:51:07 +00:00
onlysync = flag . Bool ( "onlysync" , false , "Only populate the temporary source/build tree and output its full path. It is meant to prepare the environment for running the full test suite with 'devcam test'." )
2014-08-08 23:11:53 +00:00
ifModsSince = flag . Int64 ( "if_mods_since" , 0 , "If non-zero return immediately without building if there aren't any filesystem modifications past this time (in unix seconds)" )
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." )
2016-10-03 23:55:58 +00:00
camnetdns = flag . Bool ( "camnetdns" , false , "Just build camlistore.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." )
2016-05-06 23:40:31 +00:00
// Use GOPATH from the environment and work from there. Do not create a temporary source tree with a new GOPATH in it.
// It is set through CAMLI_MAKE_USEGOPATH for integration tests that call 'go run make.go', and which are already in
// a temp GOPATH.
useGoPath bool
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 (
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
// camRoot is the original Camlistore project root, from where the source files are mirrored.
camRoot string
2013-06-20 13:49:34 +00:00
// buildGoPath becomes our child "go" processes' GOPATH environment variable
buildGoPath string
// Our temporary source tree root and build dir, i.e: buildGoPath + "src/camlistore.org"
buildSrcDir string
// files mirrored from camRoot to buildSrcDir
2017-08-23 01:09:25 +00:00
rxMirrored = regexp . MustCompile ( ` ^([a-zA-Z0-9\-\_\.]+\.(?:blobs|camli|css|eot|err|gif|go|s|pb\.go|gpg|html|ico|jpg|js|json|xml|min\.css|min\.js|mp3|otf|png|svg|pdf|psd|tiff|ttf|woff|woff2|xcf|tar\.gz|gz|tar\.xz|tbz2|zip|sh))$ ` )
2016-05-12 22:14:54 +00:00
// base file exceptions for the above matching, so as not to complicate the regexp any further
mirrorIgnored = map [ string ] bool {
2016-07-15 00:10:07 +00:00
"publisher.js" : true , // because this file is (re)generated after the mirroring
2017-01-25 18:36:41 +00:00
"goui.js" : true , // because this file is (re)generated after the mirroring
2016-05-12 22:14:54 +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
2017-02-17 22:49:21 +00:00
// builds with Go 1.8.
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" )
}
2017-02-04 23:33:57 +00:00
gopherjsGoroot = os . Getenv ( "CAMLI_GOPHERJS_GOROOT" )
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 ( )
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
sql := withSQLite ( )
if useEnvGoPath , _ := strconv . ParseBool ( os . Getenv ( "CAMLI_MAKE_USEGOPATH" ) ) ; useEnvGoPath {
2016-05-06 23:40:31 +00:00
useGoPath = true
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
}
2014-08-08 23:11:53 +00:00
latestSrcMod := time . Now ( )
2016-05-06 23:40:31 +00:00
if useGoPath {
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
buildGoPath = os . Getenv ( "GOPATH" )
var err error
camRoot , err = goPackagePath ( "camlistore.org" )
if err != nil {
log . Fatalf ( "Cannot run make.go with --use_gopath: %v (is GOPATH not set?)" , err )
}
buildSrcDir = camRoot
2014-08-08 23:11:53 +00:00
if * ifModsSince > 0 {
latestSrcMod = walkDirs ( sql )
}
2013-08-26 22:52:02 +00:00
} else {
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
var err error
camRoot , err = os . Getwd ( )
2013-08-26 22:52:02 +00:00
if err != nil {
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 . Fatalf ( "Failed to get current directory: %v" , err )
2013-07-05 17:41:07 +00:00
}
2014-08-08 23:11:53 +00:00
latestSrcMod = mirror ( sql )
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
if * onlysync {
2016-05-01 00:18:43 +00:00
if * website {
log . Fatal ( "-onlysync and -website are mutually exclusive" )
}
2016-10-03 23:55:58 +00:00
if * camnetdns {
log . Fatal ( "-onlysync and -camnetdns are mutually exclusive" )
}
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
mirrorFile ( "make.go" , filepath . Join ( buildSrcDir , "make.go" ) )
2016-02-12 23:44:09 +00:00
// Since we have not done the resources embedding, the
// z_*.go files have not been marked as wanted and are
// going to be removed. And they will have to be
// regenerated next time make.go is run.
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
deleteUnwantedOldMirrorFiles ( buildSrcDir , true )
fmt . Println ( buildGoPath )
return
2013-08-25 17:57:51 +00:00
}
}
2014-08-08 23:11:53 +00:00
if latestSrcMod . Before ( time . Unix ( * ifModsSince , 0 ) ) {
return
}
2013-06-10 22:55:17 +00:00
binDir := filepath . Join ( camRoot , "bin" )
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 ( )
2013-06-10 22:55:17 +00:00
2013-06-10 23:22:28 +00:00
if * verbose {
log . Printf ( "Camlistore version = %s" , version )
2013-08-26 22:52:02 +00:00
log . Printf ( "SQLite included: %v" , sql )
2013-06-20 13:49:34 +00:00
log . Printf ( "Temporary source: %s" , buildSrcDir )
2013-06-10 23:22:28 +00:00
log . Printf ( "Output binaries: %s" , binDir )
}
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 {
"camlistore.org/dev/devcam" ,
"camlistore.org/cmd/camget" ,
"camlistore.org/cmd/camput" ,
"camlistore.org/cmd/camtool" ,
2015-01-12 23:59:42 +00:00
"camlistore.org/cmd/camdeploy" ,
2013-09-11 05:42:24 +00:00
"camlistore.org/server/camlistored" ,
2014-05-08 14:07:29 +00:00
"camlistore.org/app/hello" ,
2014-06-14 20:14:34 +00:00
"camlistore.org/app/publisher" ,
new app: scanning cabinet
WARNING: this app is still experimental, and even its data schema might
change. Do not use in production.
This change adds a Camlistore-based port of the scanning cabinet app
originally created by Brad Fitzpatrick:
https://github.com/bradfitz/scanningcabinet
Some of it is inspired from the App Engine Go port of Patrick Borgeest:
https://bitbucket.org/pborgeest/nometicland
The data schema is roughly as follows:
-a scan is a permanode, with the node type: "scanningcabinet:scan".
-a scan's camliContent attribute is set to the actual image file.
-a scan also holds the "dateCreated" attribute, as well as the
"document" attribute, which references the document this scan is a part
of (if any).
-a document is a permanode, with the node type: "scanningcabinet:doc".
-a document page, is modeled by the "camliPath:sha1-xxx" = "pageNumber"
relation, where sha1-xxx is the blobRef of a scan.
-a document can also hold the following attributes: "dateCreated",
"tag", "locationText", "title", "startDate", and "paymentDueDate".
Known caveats, in decreasing order of concern:
-the data schema might still change.
-the scancab tool, to actually create and upload the files from physical
documents, is practically untested (since I do not own a scanner).
-some parts, in particular related to searches, are probably
sub-optimized.
-the usual unavoidable bugs.
Change-Id: If6afc509e13f7c21164a3abd276fec075a3813bb
2016-07-07 15:53:57 +00:00
"camlistore.org/app/scanningcabinet" ,
2017-01-22 19:33:56 +00:00
"camlistore.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 "" :
2014-02-21 21:59:26 +00:00
// Add cammount to default build targets on OSes that support FUSE.
switch * buildOS {
case "linux" , "darwin" :
targs = append ( targs , "camlistore.org/cmd/cammount" )
}
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 {
targs = [ ] string { "camlistore.org/website" }
} else if * camnetdns {
targs = [ ] string { "camlistore.org/server/camnetdns" }
}
2016-05-01 00:18:43 +00:00
}
2013-09-11 05:42:24 +00:00
withCamlistored := stringListContains ( targs , "camlistore.org/server/camlistored" )
2016-05-12 22:14:54 +00:00
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
// TODO(mpl): no need to build publisher.js if we're not building the publisher app.
2016-05-12 22:14:54 +00:00
if withCamlistored {
2017-06-11 12:01:42 +00:00
if err := buildReactGen ( ) ; err != nil {
log . Fatal ( err )
}
if err := genWebUIReact ( ) ; err != nil {
log . Fatal ( err )
}
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.
if err := makeGopherjs ( ) ; err != nil {
log . Fatal ( err )
}
}
2013-09-11 05:42:24 +00:00
if * embedResources && withCamlistored {
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
}
2016-05-06 23:40:31 +00:00
if ! useGoPath {
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
deleteUnwantedOldMirrorFiles ( buildSrcDir , withCamlistored )
}
2013-06-18 21:45:40 +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 {
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-06-10 23:18:29 +00:00
if * all {
2013-06-22 03:18:02 +00:00
baseArgs = append ( baseArgs , "-a" )
2013-06-10 23:18:29 +00:00
}
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 += " "
}
ldFlags += "-X \"camlistore.org/pkg/buildinfo.GitInfo=" + version + "\""
2015-04-13 18:00:07 +00:00
}
2014-10-03 17:31:59 +00:00
baseArgs = append ( baseArgs , "--ldflags=" + ldFlags , "--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
// under <camlistore_root>/bin:
args := append ( baseArgs , targs ... )
if buildAll {
args = append ( args ,
2014-05-08 14:07:29 +00:00
"camlistore.org/app/..." ,
2013-09-21 11:45:36 +00:00
"camlistore.org/pkg/..." ,
"camlistore.org/server/..." ,
2015-03-31 20:27:59 +00:00
"camlistore.org/internal/..." ,
2013-09-21 11:45:36 +00:00
)
}
2013-06-10 23:18:29 +00:00
cmd := exec . Command ( "go" , args ... )
2013-06-18 22:21:56 +00:00
cmd . Env = append ( cleanGoEnv ( ) ,
2013-06-20 13:49:34 +00:00
"GOPATH=" + buildGoPath ,
2013-06-18 22:21:56 +00:00
)
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
2013-09-21 11:45:36 +00:00
// Copy the binaries from $CAMROOT/tmp/build-gopath-foo/bin to $CAMROOT/bin.
// This is necessary (instead of just using GOBIN environment variable) so
// each tmp/build-gopath-* has its own binary modtimes for its own build tags.
// Otherwise switching sqlite true<->false doesn't necessarily cause a rebuild.
// See camlistore.org/issue/229
for _ , targ := range targs {
src := exeName ( filepath . Join ( actualBinDir ( filepath . Join ( buildGoPath , "bin" ) ) , pathpkg . Base ( targ ) ) )
dst := exeName ( filepath . Join ( actualBinDir ( binDir ) , pathpkg . Base ( targ ) ) )
if err := mirrorFile ( src , dst ) ; err != nil {
log . Fatalf ( "Error copying %s to %s: %v" , src , dst , err )
2013-06-29 20:52:01 +00:00
}
2013-06-10 22:55:17 +00:00
}
2013-06-22 03:18:02 +00:00
2013-06-29 20:52:01 +00:00
if ! * quiet {
2013-09-04 20:44:43 +00:00
log . Printf ( "Success. Binaries are in %s" , actualBinDir ( binDir ) )
2013-06-29 20:52:01 +00:00
}
2013-06-10 22:55:17 +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"
2017-01-25 18:36:41 +00:00
gopherjsUI = "server/camlistored/ui/goui.js"
2016-05-12 22:14:54 +00:00
)
// buildGopherjs builds the gopherjs binary from our vendored gopherjs source.
// It returns the path to the binary if successful, an error otherwise.
func buildGopherjs ( ) ( string , error ) {
src := filepath . Join ( buildSrcDir , filepath . FromSlash ( "vendor/github.com/gopherjs/gopherjs" ) )
2016-08-26 21:58:40 +00:00
// Note: do not use exeName for gopherjs, as it will run on the current platform,
// not on the one we're cross-compiling for.
bin := filepath . Join ( buildGoPath , "bin" , "gopherjs" )
if runtime . GOOS == "windows" {
bin += ".exe"
}
2016-05-12 22:14:54 +00:00
var srcModtime , binModtime time . Time
if err := filepath . Walk ( src , func ( path string , fi os . FileInfo , err error ) error {
if err != nil {
return err
}
if fi . IsDir ( ) {
return nil
}
if t := fi . ModTime ( ) ; t . After ( srcModtime ) {
srcModtime = t
}
return nil
} ) ; err != nil {
return "" , err
}
fi , err := os . Stat ( bin )
if err != nil {
if ! os . IsNotExist ( err ) {
return "" , err
}
binModtime = srcModtime
} else {
binModtime = fi . ModTime ( )
}
if binModtime . After ( srcModtime ) {
return bin , nil
}
log . Printf ( "Now rebuilding gopherjs at %v" , bin )
2016-11-25 20:13:12 +00:00
goBin := "go"
if gopherjsGoroot != "" {
goBin = filepath . Join ( gopherjsGoroot , "bin" , "go" )
}
cmd := exec . Command ( goBin , "install" )
2016-05-12 22:14:54 +00:00
cmd . Dir = src
cmd . Env = append ( cleanGoEnv ( ) ,
"GOPATH=" + buildGoPath ,
)
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.
cmd . Env = setEnv ( cmd . Env , "GOOS" , runtime . GOOS )
cmd . Env = setEnv ( cmd . Env , "GOARCH" , runtime . GOARCH )
2017-07-17 11:30:29 +00:00
if gopherjsGoroot != "" {
cmd . Env = setEnv ( cmd . Env , "GOROOT" , gopherjsGoroot )
}
2016-05-12 22:14:54 +00:00
if out , err := cmd . CombinedOutput ( ) ; err != nil {
return "" , fmt . Errorf ( "error while building gopherjs: %v, %v" , err , string ( out ) )
}
return bin , nil
}
// For some reason (https://github.com/gopherjs/gopherjs/issues/415), the
// github.com/gopherjs/gopherjs/js import is treated specially, and it cannot be
// vendored at all for gopherjs to work properly. So we move it to our tmp GOPATH.
func moveGopherjs ( ) error {
dest := filepath . Join ( buildGoPath , filepath . FromSlash ( "src/github.com/gopherjs/gopherjs" ) )
if err := os . MkdirAll ( dest , 0700 ) ; err != nil {
return err
}
src := filepath . Join ( buildSrcDir , filepath . FromSlash ( "vendor/github.com/gopherjs/gopherjs" ) )
if err := filepath . Walk ( src , func ( path string , fi os . FileInfo , err error ) error {
if err != nil {
return err
}
suffix , err := filepath . Rel ( src , path )
if err != nil {
return err
}
destName := filepath . Join ( dest , suffix )
if fi . IsDir ( ) {
return os . MkdirAll ( destName , 0700 )
}
destFi , err := os . Stat ( destName )
if err != nil && ! os . IsNotExist ( err ) {
return err
}
if err == nil && ! fi . ModTime ( ) . After ( destFi . ModTime ( ) ) {
return nil
}
dataSrc , err := ioutil . ReadFile ( path )
if err != nil {
return err
}
return ioutil . WriteFile ( destName , dataSrc , 0600 )
} ) ; err != nil {
return err
}
return os . RemoveAll ( src )
}
2016-07-15 00:10:07 +00:00
// genSearchTypes duplicates some of the camlistore.org/pkg/search types into
// camlistore.org/app/publisher/js/zsearch.go , because it's too costly (in output
// file size) for now to import the search pkg into gopherjs.
func genSearchTypes ( ) error {
sourceFile := filepath . Join ( buildSrcDir , filepath . FromSlash ( "pkg/search/describe.go" ) )
outputFile := filepath . Join ( buildSrcDir , filepath . FromSlash ( "app/publisher/js/zsearch.go" ) )
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 ( ) ) {
wantDestFile [ outputFile ] = true
return nil
}
args := [ ] string { "generate" , "camlistore.org/app/publisher/js" }
cmd := exec . Command ( "go" , args ... )
cmd . Env = append ( cleanGoEnv ( ) ,
"GOPATH=" + buildGoPath ,
)
2016-09-05 16:10:01 +00:00
cmd . Env = setEnv ( cmd . Env , "GOOS" , runtime . GOOS )
cmd . Env = setEnv ( cmd . Env , "GOARCH" , runtime . GOARCH )
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 ) )
}
wantDestFile [ outputFile ] = true
log . Printf ( "generated %v" , outputFile )
return nil
}
2016-05-12 22:14:54 +00:00
// genPublisherJS runs the gopherjs command, using the gopherjsBin binary, on
// camlistore.org/app/publisher/js, to generate the javascript code at
// app/publisher/publisher.js
func genPublisherJS ( gopherjsBin string ) error {
2016-07-15 00:10:07 +00:00
if err := genSearchTypes ( ) ; err != nil {
return err
}
2016-05-12 22:14:54 +00:00
// Run gopherjs on a temporary output file, so we don't change the
// modtime of the existing gopherjs.js if there was no reason to.
output := filepath . Join ( buildSrcDir , filepath . FromSlash ( publisherJS ) )
tmpOutput := output + ".new"
2017-06-11 12:01:42 +00:00
args := [ ] string { "build" , "--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" )
}
args = append ( args , "-o" , tmpOutput , "camlistore.org/app/publisher/js" )
2016-05-12 22:14:54 +00:00
cmd := exec . Command ( gopherjsBin , args ... )
cmd . Env = append ( cleanGoEnv ( ) ,
"GOPATH=" + buildGoPath ,
)
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
cmd . Env = setEnv ( cmd . Env , "GOOS" , "linux" )
2016-11-25 20:13:12 +00:00
if gopherjsGoroot != "" {
cmd . Env = setEnv ( cmd . Env , "GOROOT" , gopherjsGoroot )
}
2016-05-12 22:14:54 +00:00
if out , err := cmd . CombinedOutput ( ) ; err != nil {
return fmt . Errorf ( "gopherjs for publisher error: %v, %v" , err , string ( out ) )
}
// check if new output is different from previous run result
_ , err := os . Stat ( output )
if err != nil && ! os . IsNotExist ( err ) {
return err
}
needsUpdate := true
if err == nil {
if hashsum ( tmpOutput ) == hashsum ( output ) {
needsUpdate = false
}
}
if needsUpdate {
// general case: replace previous run result with new output
if err := os . Rename ( tmpOutput , output ) ; err != nil {
return err
}
log . Printf ( "gopherjs generated %v" , output )
}
// And since we're generating after the mirroring, we need to manually
// add the output to the wanted files
wantDestFile [ output ] = true
wantDestFile [ output + ".map" ] = true
// Finally, even when embedding resources, we copy the output back to
// camRoot. It's a bit unsatisfactory that we have to modify things out of
// buildGoPath but it's better than the alternative (the user ending up
// without a copy of publisher.js in their camRoot).
jsInCamRoot := filepath . Join ( camRoot , filepath . FromSlash ( publisherJS ) )
if ! needsUpdate {
_ , err := os . Stat ( jsInCamRoot )
if err == nil {
return nil
}
if ! os . IsNotExist ( err ) {
log . Fatal ( err )
}
}
data , err := ioutil . ReadFile ( output )
if err != nil {
return err
}
if err := ioutil . WriteFile (
jsInCamRoot ,
data , 0600 ) ; err != nil {
return err
}
log . Printf ( "Copied gopherjs generated code to %v" , jsInCamRoot )
return nil
}
2017-01-25 18:36:41 +00:00
// TODO(mpl): refactor genWebUIJS with genPublisherJS
// genWebUIJS runs the gopherjs command, using the gopherjsBin binary, on
// camlistore.org/server/camlistored/ui/goui, to generate the javascript
// code at camlistore.org/server/camlistored/ui/goui.js
func genWebUIJS ( gopherjsBin string ) error {
// Run gopherjs on a temporary output file, so we don't change the
// modtime of the existing goui.js if there was no reason to.
output := filepath . Join ( buildSrcDir , filepath . FromSlash ( gopherjsUI ) )
tmpOutput := output + ".new"
2017-06-11 12:01:42 +00:00
args := [ ] string { "build" , "--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" )
}
args = append ( args , "-o" , tmpOutput , "camlistore.org/server/camlistored/ui/goui" )
2017-01-25 18:36:41 +00:00
cmd := exec . Command ( gopherjsBin , args ... )
cmd . Env = append ( cleanGoEnv ( ) ,
"GOPATH=" + buildGoPath ,
)
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
cmd . Env = setEnv ( cmd . Env , "GOOS" , "linux" )
2017-07-17 11:30:29 +00:00
if gopherjsGoroot != "" {
cmd . Env = setEnv ( cmd . Env , "GOROOT" , gopherjsGoroot )
}
2017-01-25 18:36:41 +00:00
if out , err := cmd . CombinedOutput ( ) ; err != nil {
return fmt . Errorf ( "gopherjs for web UI error: %v, %v" , err , string ( out ) )
}
// check if new output is different from previous run result
_ , err := os . Stat ( output )
if err != nil && ! os . IsNotExist ( err ) {
return err
}
needsUpdate := true
if err == nil {
if hashsum ( tmpOutput ) == hashsum ( output ) {
needsUpdate = false
}
}
if needsUpdate {
// general case: replace previous run result with new output
if err := os . Rename ( tmpOutput , output ) ; err != nil {
return err
}
log . Printf ( "gopherjs for web UI generated %v" , output )
}
// And since we're generating after the mirroring, we need to manually
// add the output to the wanted files
wantDestFile [ output ] = true
wantDestFile [ output + ".map" ] = true
// Finally, even when embedding resources, we copy the output back to
// camRoot. It's a bit unsatisfactory that we have to modify things out of
// buildGoPath but it's better than the alternative (the user ending up
// without a copy of publisher.js in their camRoot).
jsInCamRoot := filepath . Join ( camRoot , filepath . FromSlash ( gopherjsUI ) )
if ! needsUpdate {
_ , err := os . Stat ( jsInCamRoot )
if err == nil {
return nil
}
if ! os . IsNotExist ( err ) {
log . Fatal ( err )
}
}
data , err := ioutil . ReadFile ( output )
if err != nil {
return err
}
if err := ioutil . WriteFile (
jsInCamRoot ,
data , 0600 ) ; err != nil {
return err
}
log . Printf ( "Copied gopherjs generated code for web UI to %v" , jsInCamRoot )
return nil
}
2017-06-11 12:01:42 +00:00
// genWebUIRect runs go generate on the gopherjs code of the web UI, which
// 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 {
args := [ ] string { "generate" , "camlistore.org/server/camlistored/ui/goui/..." }
path := strings . Join ( [ ] string {
filepath . Join ( buildGoPath , "bin" ) ,
os . Getenv ( "PATH" ) ,
} , string ( os . PathListSeparator ) )
cmd := exec . Command ( "go" , args ... )
cmd . Env = append ( cleanGoEnv ( "PATH" ) ,
"GOPATH=" + buildGoPath ,
"PATH=" + path ,
)
if out , err := cmd . CombinedOutput ( ) ; err != nil {
return fmt . Errorf ( "go generate for web UI error: %v, %v" , err , string ( out ) )
}
return nil
}
2016-05-12 22:14:54 +00:00
// noGopherJS creates a fake (unusable) gopherjs.js file for when we want to skip all of
// the gopherjs business.
func noGopherJS ( output string ) {
if err := ioutil . WriteFile (
output ,
[ ] byte ( "// This (broken) output should only be generated when CAMLI_MAKE_USEGOPATH is set, which should be only for integration tests.\n" ) ,
0600 ) ; err != nil {
log . Fatal ( err )
}
}
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 )
}
defer f . Close ( )
if _ , err := io . Copy ( h , f ) ; err != nil {
log . Fatalf ( "could not compute SHA256 of %v: %v" , filename , err )
}
return string ( h . Sum ( nil ) )
}
// makeGopherjs builds and runs the gopherjs command on camlistore.org/app/publisher/js
2017-01-25 18:36:41 +00:00
// and camlistore.org/server/camlistored/ui/goui
2016-05-12 22:14:54 +00:00
// When CAMLI_MAKE_USEGOPATH is set (for integration tests through devcam), we
// generate a fake file instead.
func makeGopherjs ( ) error {
if useGoPath {
noGopherJS ( filepath . Join ( buildSrcDir , filepath . FromSlash ( publisherJS ) ) )
return nil
}
gopherjs , err := buildGopherjs ( )
if err != nil {
return fmt . Errorf ( "error building gopherjs: %v" , err )
}
// TODO(mpl): remove when https://github.com/gopherjs/gopherjs/issues/415 is fixed.
if err := moveGopherjs ( ) ; err != nil {
return err
}
if err := genPublisherJS ( gopherjs ) ; err != nil {
return err
}
2017-01-25 18:36:41 +00:00
if err := genWebUIJS ( gopherjs ) ; err != nil {
return err
}
2016-05-12 22:14:54 +00:00
return nil
}
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
// create the tmp GOPATH, and mirror to it from camRoot.
2014-08-08 23:11:53 +00:00
// return the latest modtime among all of the walked files.
func mirror ( sql bool ) ( latestSrcMod time . Time ) {
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
verifyCamlistoreRoot ( camRoot )
2016-03-11 18:57:36 +00:00
buildBaseDir := baseDirName ( sql )
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
buildGoPath = filepath . Join ( camRoot , "tmp" , buildBaseDir )
buildSrcDir = filepath . Join ( buildGoPath , "src" , "camlistore.org" )
if err := os . MkdirAll ( buildSrcDir , 0755 ) ; err != nil {
log . Fatal ( err )
}
// We copy all *.go files from camRoot's goDirs to buildSrcDir.
2015-03-31 20:27:59 +00:00
goDirs := [ ] string {
"app" ,
"cmd" ,
"dev" ,
"internal" ,
"pkg" ,
"server/camlistored" ,
2015-08-15 20:43:31 +00:00
"vendor" ,
2015-03-31 20:27:59 +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
if * onlysync {
2017-12-01 03:11:47 +00:00
goDirs = append ( goDirs , "config" , "misc" , "./website" )
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
}
2016-05-01 00:18:43 +00:00
if * website {
goDirs = [ ] string {
"pkg" ,
"vendor" ,
"website" ,
}
2016-10-03 23:55:58 +00:00
} else if * camnetdns {
goDirs = [ ] string {
"pkg" ,
"vendor" ,
"server/camnetdns" ,
}
2016-05-01 00:18:43 +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
// Copy files we do want in our mirrored GOPATH. This has the side effect of
// populating wantDestFile, populated by mirrorFile.
for _ , dir := range goDirs {
srcPath := filepath . Join ( camRoot , filepath . FromSlash ( dir ) )
dstPath := buildSrcPath ( dir )
2014-08-08 23:11:53 +00:00
if maxMod , err := mirrorDir ( srcPath , dstPath , walkOpts { sqlite : sql } ) ; err != nil {
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 . Fatalf ( "Error while mirroring %s to %s: %v" , srcPath , dstPath , err )
} else {
if maxMod . After ( latestSrcMod ) {
latestSrcMod = maxMod
}
}
}
2014-08-08 23:11:53 +00:00
return
}
// TODO(mpl): see if walkDirs and mirror can be refactored further.
// walk all the dirs in camRoot, to return the latest
// modtime among all of the walked files.
func walkDirs ( sql bool ) ( latestSrcMod time . Time ) {
d , err := os . Open ( camRoot )
if err != nil {
log . Fatal ( err )
}
dirs , err := d . Readdirnames ( - 1 )
d . Close ( )
if err != nil {
log . Fatal ( err )
}
for _ , dir := range dirs {
srcPath := filepath . Join ( camRoot , filepath . FromSlash ( dir ) )
if maxMod , err := walkDir ( srcPath , walkOpts { sqlite : sql } ) ; err != nil {
log . Fatalf ( "Error while walking %s: %v" , srcPath , err )
} else {
if maxMod . After ( latestSrcMod ) {
latestSrcMod = maxMod
}
}
}
return
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
}
2013-09-04 02:48:32 +00:00
func actualBinDir ( dir string ) string {
if * buildARCH == runtime . GOARCH && * buildOS == runtime . GOOS {
return dir
}
return filepath . Join ( dir , * buildOS + "_" + * buildARCH )
}
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 )
}
2017-06-11 12:01:42 +00:00
// cleanGoEnv returns a copy of the current environment with GOPATH, GOBIN and
// any variable listed in others removed. it also sets GOOS and GOARCH as
// needed when cross-compiling.
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
}
}
2013-06-18 22:21:56 +00:00
if strings . HasPrefix ( env , "GOPATH=" ) || strings . HasPrefix ( env , "GOBIN=" ) {
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-07-11 09:49:54 +00:00
// setEnv sets the given key & value in the provided environment.
// Each value in the env list should be of the form key=value.
func setEnv ( env [ ] string , key , value string ) [ ] string {
for i , s := range env {
if strings . HasPrefix ( s , fmt . Sprintf ( "%s=" , key ) ) {
env [ i ] = envPair ( key , value )
return env
}
}
env = append ( env , envPair ( key , value ) )
return env
}
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
}
2013-06-20 13:49:34 +00:00
// buildSrcPath returns the full path concatenation
// of buildSrcDir with fromSrc.
func buildSrcPath ( fromSrc string ) string {
return filepath . Join ( buildSrcDir , filepath . FromSlash ( fromSrc ) )
}
// genEmbeds generates from the static resources the zembed.*.go
// files that will allow for these resources to be included in
// the camlistored binary.
// It also populates wantDestFile with those files so they're
// kept in between runs.
func genEmbeds ( ) error {
2015-07-24 15:01:23 +00:00
// Note: do not use exeName for genfileembed, as it will run on the current platform,
// not on the one we're cross-compiling for.
cmdName := filepath . Join ( buildGoPath , "bin" , "genfileembed" )
if runtime . GOOS == "windows" {
cmdName += ".exe"
}
2016-06-06 23:53:46 +00:00
for _ , embeds := range [ ] string {
"server/camlistored/ui" ,
"pkg/server" ,
"vendor/embed/fontawesome" ,
"vendor/embed/glitch" ,
"vendor/embed/leaflet" ,
"vendor/embed/less" ,
"vendor/embed/opensans" ,
"vendor/embed/react" ,
"app/publisher" ,
"app/scanningcabinet/ui" ,
} {
2014-04-05 05:59:43 +00:00
embeds := buildSrcPath ( embeds )
2017-12-08 08:24:14 +00:00
var args [ ] string
if * all {
args = append ( args , "-all" )
}
args = append ( args , "-output-files-stderr" , embeds )
2013-06-20 13:49:34 +00:00
cmd := exec . Command ( cmdName , args ... )
cmd . Env = append ( cleanGoEnv ( ) ,
"GOPATH=" + buildGoPath ,
)
cmd . Stdout = os . Stdout
2014-08-17 01:19:38 +00:00
stderr , err := cmd . StderrPipe ( )
if err != nil {
log . Fatal ( err )
}
2013-06-20 13:49:34 +00:00
if * verbose {
log . Printf ( "Running %s %s" , cmdName , embeds )
}
2014-08-17 01:19:38 +00:00
if err := cmd . Start ( ) ; err != nil {
return fmt . Errorf ( "Error starting %s %s: %v" , cmdName , embeds , err )
2013-06-20 13:49:34 +00:00
}
2014-08-17 01:19:38 +00:00
parseGenEmbedOutputLines ( stderr )
if err := cmd . Wait ( ) ; err != nil {
return fmt . Errorf ( "Error running %s %s: %v" , cmdName , embeds , err )
2013-06-20 13:49:34 +00:00
}
}
return nil
}
2014-08-17 01:19:38 +00:00
func parseGenEmbedOutputLines ( r io . Reader ) {
sc := bufio . NewScanner ( r )
for sc . Scan ( ) {
ln := sc . Text ( )
if ! strings . HasPrefix ( ln , "OUTPUT:" ) {
continue
}
wantDestFile [ strings . TrimSpace ( strings . TrimPrefix ( ln , "OUTPUT:" ) ) ] = true
}
}
2013-06-20 13:49:34 +00:00
func buildGenfileembed ( ) error {
2017-06-11 12:01:42 +00:00
return buildBin ( "camlistore.org/pkg/fileembed/genfileembed" )
}
func buildReactGen ( ) error {
return buildBin ( "camlistore.org/vendor/myitcv.io/react/cmd/reactGen" )
}
func buildBin ( pkg string ) error {
pkgBase := pathpkg . Base ( pkg )
2013-06-18 23:04:27 +00:00
args := [ ] string { "install" , "-v" }
if * all {
args = append ( args , "-a" )
}
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 ... )
2013-07-11 09:49:54 +00:00
2013-06-18 23:04:27 +00:00
// We don't even need to set GOBIN as it defaults to $GOPATH/bin
2017-06-11 12:01:42 +00:00
// and that is where we want the bin to go.
2013-07-11 09:49:54 +00:00
// Here we replace the GOOS and GOARCH valuesfrom the env with the host OS,
// to support cross-compiling.
cmd . Env = cleanGoEnv ( )
cmd . Env = setEnv ( cmd . Env , "GOPATH" , buildGoPath )
cmd . Env = setEnv ( cmd . Env , "GOOS" , runtime . GOOS )
cmd . Env = setEnv ( cmd . Env , "GOARCH" , runtime . GOARCH )
2013-06-18 23:04:27 +00:00
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 {
2017-06-11 12:01:42 +00:00
log . Printf ( "%v installed in %s" , pkgBase , filepath . Join ( buildGoPath , "bin" ) )
2013-06-18 23:04:27 +00:00
}
return nil
}
2013-06-10 22:55:17 +00:00
// getVersion returns the version of Camlistore. Either from a VERSION file at the root,
// 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 {
2013-06-10 22:55:17 +00:00
slurp , err := ioutil . ReadFile ( filepath . Join ( camRoot , "VERSION" ) )
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
// gitVersion returns the git version of the git repo at camRoot as a
// 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" )
2013-07-29 01:15:04 +00:00
cmd . Dir = camRoot
out , err := cmd . Output ( )
2013-06-10 22:55:17 +00:00
if err != nil {
2013-07-29 01:15:04 +00:00
log . Fatalf ( "Error running git rev-list in %s: %v" , camRoot , err )
}
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" )
cmd . Dir = camRoot
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
}
// verifyCamlistoreRoot crashes if dir isn't the Camlistore root directory.
func verifyCamlistoreRoot ( dir string ) {
2013-08-04 02:54:30 +00:00
testFile := filepath . Join ( dir , "pkg" , "blob" , "ref.go" )
2013-06-10 22:55:17 +00:00
if _ , err := os . Stat ( testFile ) ; err != nil {
log . Fatalf ( "make.go must be run from the Camlistore src root directory (where make.go is). Current working directory is %s" , dir )
}
}
2017-02-17 00:17:20 +00:00
const (
2017-09-18 09:22:05 +00:00
goVersionMinor = '9'
gopherJSGoMinor = '9'
2017-02-17 00:17:20 +00:00
)
2016-11-25 20:13:12 +00:00
2013-06-10 22:55:17 +00:00
func verifyGoVersion ( ) {
_ , err := exec . LookPath ( "go" )
if err != nil {
2016-11-25 20:13:12 +00:00
log . Fatalf ( "Go doesn't appear to be installed ('go' isn't in your PATH). Install Go 1.%c 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 )
}
fields := strings . Fields ( string ( out ) )
if len ( fields ) < 3 || ! strings . HasPrefix ( string ( out ) , "go version " ) {
log . Fatalf ( "Unexpected output while checking 'go version': %q" , out )
}
version := fields [ 2 ]
2014-08-06 15:50:44 +00:00
if version == "devel" {
2016-11-25 20:13:12 +00:00
verifyGopherjsGoroot ( )
2014-08-06 15:50:44 +00:00
return
}
// this check is still needed for the "go1" case.
if len ( version ) < len ( "go1." ) {
2016-11-25 20:13:12 +00:00
log . Fatalf ( "Your version of Go (%s) is too old. Camlistore requires Go 1.%c or later." , version , goVersionMinor )
2014-08-06 15:50:44 +00:00
}
minorChar := strings . TrimPrefix ( version , "go1." ) [ 0 ]
2016-11-25 20:13:12 +00:00
if minorChar >= goVersionMinor && minorChar <= '9' {
2017-02-17 00:17:20 +00:00
if minorChar != gopherJSGoMinor {
2016-12-02 12:04:01 +00:00
verifyGopherjsGoroot ( )
}
2014-08-06 15:50:44 +00:00
return
2013-06-10 22:55:17 +00:00
}
2016-11-25 20:13:12 +00:00
log . Fatalf ( "Your version of Go (%s) is too old. Camlistore requires Go 1.%c or later." , version , goVersionMinor )
}
func verifyGopherjsGoroot ( ) {
goBin := filepath . Join ( gopherjsGoroot , "bin" , "go" )
if gopherjsGoroot == "" {
2017-02-17 00:17:20 +00:00
gopherjsGoroot = filepath . Join ( homeDir ( ) , fmt . Sprintf ( "go1.%c" , gopherJSGoMinor ) )
2016-11-25 20:13:12 +00:00
goBin = filepath . Join ( gopherjsGoroot , "bin" , "go" )
2017-02-17 00:17:20 +00:00
log . Printf ( "You're using go != 1.%c, and CAMLI_GOPHERJS_GOROOT was not provided, so defaulting to %v for building gopherjs instead." , gopherJSGoMinor , goBin )
2016-11-25 20:13:12 +00:00
}
if _ , err := os . Stat ( goBin ) ; err != nil {
if ! os . IsNotExist ( err ) {
log . Fatal ( err )
}
2017-02-17 22:49:21 +00:00
log . Fatalf ( "%v not found. You need to specify a go1.%c root in CAMLI_GOPHERJS_GOROOT for building gopherjs" , goBin , gopherJSGoMinor )
2016-11-25 20:13:12 +00:00
}
2013-06-10 22:55:17 +00:00
}
2014-08-08 23:11:53 +00:00
type walkOpts struct {
dst string // if non empty, mirror walked files to this destination.
sqlite bool // want sqlite package?
2013-12-25 01:42:32 +00:00
}
2014-08-08 23:11:53 +00:00
func walkDir ( src string , opts walkOpts ) ( maxMod time . Time , err error ) {
2013-06-29 20:52:01 +00:00
err = filepath . Walk ( src , func ( path string , fi os . FileInfo , err error ) error {
2013-06-10 22:55:17 +00:00
if err != nil {
return err
}
base := fi . Name ( )
if fi . IsDir ( ) {
2013-12-25 01:42:32 +00:00
if ! opts . sqlite && strings . Contains ( path , "mattn" ) && strings . Contains ( path , "go-sqlite3" ) {
return filepath . SkipDir
}
2013-09-11 17:51:07 +00:00
return nil
2013-06-10 22:55:17 +00:00
}
2014-08-15 16:31:40 +00:00
dir , _ := filepath . Split ( path )
parent := filepath . Base ( dir )
if ( strings . HasPrefix ( base , ".#" ) || ! rxMirrored . MatchString ( base ) ) && parent != "testdata" {
2013-06-10 22:55:17 +00:00
return nil
}
2016-05-12 22:14:54 +00:00
if _ , ok := mirrorIgnored [ base ] ; ok {
return nil
}
2013-06-10 22:55:17 +00:00
suffix , err := filepath . Rel ( src , path )
if err != nil {
return fmt . Errorf ( "Failed to find Rel(%q, %q): %v" , src , path , err )
}
2013-06-29 20:52:01 +00:00
if t := fi . ModTime ( ) ; t . After ( maxMod ) {
maxMod = t
}
2014-08-08 23:11:53 +00:00
if opts . dst != "" {
return mirrorFile ( path , filepath . Join ( opts . dst , suffix ) )
}
return nil
2013-06-10 22:55:17 +00:00
} )
2013-06-29 20:52:01 +00:00
return
2013-06-10 22:55:17 +00:00
}
2014-08-08 23:11:53 +00:00
func mirrorDir ( src , dst string , opts walkOpts ) ( maxMod time . Time , err error ) {
opts . dst = dst
return walkDir ( src , opts )
}
2013-06-10 22:55:17 +00:00
var wantDestFile = make ( map [ string ] bool ) // full dest filename => true
2013-09-21 12:23:07 +00:00
func isExecMode ( mode os . FileMode ) bool {
return ( mode & 0111 ) != 0
}
2013-06-10 22:55:17 +00:00
func mirrorFile ( src , dst string ) error {
wantDestFile [ dst ] = true
sfi , err := os . Stat ( src )
if err != nil {
return err
}
if sfi . Mode ( ) & os . ModeType != 0 {
log . Fatalf ( "mirrorFile can't deal with non-regular file %s" , src )
}
dfi , err := os . Stat ( dst )
if err == nil &&
2013-09-21 12:23:07 +00:00
isExecMode ( sfi . Mode ( ) ) == isExecMode ( dfi . Mode ( ) ) &&
2013-06-10 22:55:17 +00:00
( dfi . Mode ( ) & os . ModeType == 0 ) &&
dfi . Size ( ) == sfi . Size ( ) &&
dfi . ModTime ( ) . Unix ( ) == sfi . ModTime ( ) . Unix ( ) {
// Seems to not be modified.
return nil
}
dstDir := filepath . Dir ( dst )
if err := os . MkdirAll ( dstDir , 0755 ) ; err != nil {
return err
}
df , err := os . Create ( dst )
if err != nil {
return err
}
sf , err := os . Open ( src )
if err != nil {
return err
}
defer sf . Close ( )
n , err := io . Copy ( df , sf )
if err == nil && n != sfi . Size ( ) {
err = fmt . Errorf ( "copied wrong size for %s -> %s: copied %d; want %d" , src , dst , n , sfi . Size ( ) )
}
cerr := df . Close ( )
if err == nil {
err = cerr
}
2013-09-21 12:23:07 +00:00
if err == nil {
err = os . Chmod ( dst , sfi . Mode ( ) )
}
2013-06-10 23:18:29 +00:00
if err == nil {
err = os . Chtimes ( dst , sfi . ModTime ( ) , sfi . ModTime ( ) )
}
2013-06-10 22:55:17 +00:00
return err
}
2013-09-11 05:42:24 +00:00
func deleteUnwantedOldMirrorFiles ( dir string , withCamlistored bool ) {
2013-06-10 22:55:17 +00:00
filepath . Walk ( dir , func ( path string , fi os . FileInfo , err error ) error {
if err != nil {
log . Fatalf ( "Error stating while cleaning %s: %v" , path , err )
}
if fi . IsDir ( ) {
return nil
}
2014-08-17 01:19:38 +00:00
base := filepath . Base ( path )
2013-06-10 22:55:17 +00:00
if ! wantDestFile [ path ] {
2014-08-17 01:19:38 +00:00
if ! withCamlistored && ( strings . HasPrefix ( base , "zembed_" ) || strings . Contains ( path , "z_data.go" ) ) {
2013-09-11 05:42:24 +00:00
// If we're not building the camlistored binary,
// no need to clean up the embedded Closure, JS,
// CSS, HTML, etc. Doing so would just mean we'd
// have to put it back into place later.
return nil
}
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
if * verbose {
2013-06-29 20:52:01 +00:00
log . Printf ( "Deleting old file from temp build dir: %s" , path )
}
2013-06-10 22:55:17 +00:00
return os . Remove ( path )
}
return nil
} )
}
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 {
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" :
2016-04-27 15:48:50 +00:00
log . Printf ( "SQLite is not easy on windows. Please see https://camlistore.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..." )
}
closureEmbed := buildSrcPath ( "server/camlistored/ui/closure/z_data.go" )
2016-04-20 23:43:47 +00:00
closureSrcDir := filepath . Join ( camRoot , filepath . FromSlash ( "vendor/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 )
}
wantDestFile [ closureEmbed ] = true
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
func exeName ( s string ) string {
if * buildOS == "windows" {
return s + ".exe"
}
return s
}
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
// goPackagePath returns the path to the provided Go package's
// source directory.
// pkg may be a path prefix without any *.go files.
// The error is os.ErrNotExist if GOPATH is unset or the directory
// doesn't exist in any GOPATH component.
func goPackagePath ( pkg string ) ( path string , err error ) {
gp := os . Getenv ( "GOPATH" )
if gp == "" {
return path , os . ErrNotExist
}
for _ , p := range filepath . SplitList ( gp ) {
dir := filepath . Join ( p , "src" , filepath . FromSlash ( pkg ) )
fi , err := os . Stat ( dir )
if os . IsNotExist ( err ) {
continue
}
if err != nil {
return "" , err
}
if ! fi . IsDir ( ) {
continue
}
return dir , nil
}
return path , os . ErrNotExist
}
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" )
}