2022-06-01 08:04:03 +00:00
|
|
|
//go:build ignore
|
2017-05-31 18:10:20 +00:00
|
|
|
|
|
|
|
/*
|
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
|
|
|
Copyright 2017 The Perkeep Authors.
|
2017-05-31 18:10:20 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
|
|
|
// This program builds the Perkeep Android application. It is meant to be run
|
2017-05-31 18:10:20 +00:00
|
|
|
// within the relevant docker container.
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
|
|
|
"regexp"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
var flagRelease = flag.Bool("release", false, "Whether to assemble the release build, instead of the debug build.")
|
|
|
|
|
|
|
|
// TODO(mpl): not sure if the version in app/build.gradle should have anything
|
|
|
|
// to do with the version we want to use here. look into that later.
|
|
|
|
const appVersion = "0.7"
|
|
|
|
|
|
|
|
var (
|
2022-06-01 11:54:55 +00:00
|
|
|
pkDir = filepath.Join(os.Getenv("GOPATH"), "src/perkeep.org")
|
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
|
|
|
projectDir = filepath.Join(os.Getenv("GOPATH"), "src/perkeep.org/clients/android")
|
2017-05-31 18:10:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
if !inDocker() {
|
|
|
|
fmt.Fprintf(os.Stderr, "Usage error: this program should be run within a docker container\n")
|
|
|
|
os.Exit(2)
|
|
|
|
}
|
2022-06-01 11:54:55 +00:00
|
|
|
buildPkput()
|
2017-05-31 18:10:20 +00:00
|
|
|
buildApp()
|
|
|
|
}
|
|
|
|
|
|
|
|
func buildApp() {
|
|
|
|
cmd := exec.Command("./gradlew", "assembleDebug")
|
|
|
|
if *flagRelease {
|
|
|
|
cmd = exec.Command("./gradlew", "assembleRelease")
|
|
|
|
}
|
|
|
|
cmd.Stdout = os.Stdout
|
|
|
|
cmd.Stderr = os.Stderr
|
2022-06-01 11:54:06 +00:00
|
|
|
|
|
|
|
if _, err := os.ReadFile("./keystore.properties"); err != nil {
|
|
|
|
// no keystore.
|
|
|
|
// generate one that's in line with the one from devenv/Dockerfile.
|
|
|
|
|
|
|
|
const keystore = `## Code generated by perkeep; DO NOT EDIT.
|
|
|
|
storeFile=/home/gopher/keystore
|
|
|
|
storePassword=gopher
|
|
|
|
keyAlias=perkeep
|
|
|
|
keyPassword=gopher
|
|
|
|
`
|
|
|
|
err = os.WriteFile("./keystore.properties", []byte(keystore), 0644)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("could not write default keystore.properties: %+v", err)
|
|
|
|
}
|
|
|
|
defer os.Remove("./keystore.properties")
|
2017-05-31 18:10:20 +00:00
|
|
|
}
|
|
|
|
|
2022-06-01 11:54:55 +00:00
|
|
|
if err := cmd.Run(); err != nil {
|
|
|
|
log.Fatalf("Error building Android app: %v", err)
|
2017-05-31 18:10:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-01 11:54:55 +00:00
|
|
|
func buildPkput() {
|
|
|
|
cmd := exec.Command("make")
|
|
|
|
cmd.Dir = "./app"
|
2017-05-31 18:10:20 +00:00
|
|
|
cmd.Stdout = os.Stdout
|
|
|
|
cmd.Stderr = os.Stderr
|
2022-06-01 11:54:55 +00:00
|
|
|
err := cmd.Run()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("could not build pk-put for Android: %+v", err)
|
2017-05-31 18:10:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func version() string {
|
2018-04-21 23:02:04 +00:00
|
|
|
return "app " + appVersion + " pk-put " + getVersion() + " " + goVersion()
|
2017-05-31 18:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func goVersion() string {
|
|
|
|
out, err := exec.Command("go", "version").Output()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error getting Go version with the 'go' command: %v", err)
|
|
|
|
}
|
|
|
|
return string(out)
|
|
|
|
}
|
|
|
|
|
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
|
|
|
// getVersion returns the version of Perkeep. Either from a VERSION file at the root,
|
2017-05-31 18:10:20 +00:00
|
|
|
// or from git.
|
|
|
|
func getVersion() string {
|
2023-01-23 18:25:14 +00:00
|
|
|
slurp, err := os.ReadFile(filepath.Join(pkDir, "VERSION"))
|
2017-05-31 18:10:20 +00:00
|
|
|
if err == nil {
|
|
|
|
return strings.TrimSpace(string(slurp))
|
|
|
|
}
|
|
|
|
return gitVersion()
|
|
|
|
}
|
|
|
|
|
|
|
|
var gitVersionRx = regexp.MustCompile(`\b\d\d\d\d-\d\d-\d\d-[0-9a-f]{10,10}\b`)
|
|
|
|
|
2022-06-01 11:54:55 +00:00
|
|
|
// gitVersion returns the git version of the git repo at pkDir as a
|
2017-05-31 18:10:20 +00:00
|
|
|
// string of the form "yyyy-mm-dd-xxxxxxx", with an optional trailing
|
2017-09-10 13:28:34 +00:00
|
|
|
// '+' if there are any local uncommitted modifications to the tree.
|
2017-05-31 18:10:20 +00:00
|
|
|
func gitVersion() string {
|
|
|
|
cmd := exec.Command("git", "rev-list", "--max-count=1", "--pretty=format:'%ad-%h'",
|
|
|
|
"--date=short", "--abbrev=10", "HEAD")
|
2022-06-01 11:54:55 +00:00
|
|
|
cmd.Dir = pkDir
|
2017-05-31 18:10:20 +00:00
|
|
|
out, err := cmd.Output()
|
|
|
|
if err != nil {
|
2022-06-01 11:54:55 +00:00
|
|
|
log.Fatalf("Error running git rev-list in %s: %v", pkDir, err)
|
2017-05-31 18:10:20 +00:00
|
|
|
}
|
|
|
|
v := strings.TrimSpace(string(out))
|
|
|
|
if m := gitVersionRx.FindStringSubmatch(v); m != nil {
|
|
|
|
v = m[0]
|
|
|
|
} else {
|
|
|
|
panic("Failed to find git version in " + v)
|
|
|
|
}
|
|
|
|
cmd = exec.Command("git", "diff", "--exit-code")
|
2022-06-01 11:54:55 +00:00
|
|
|
cmd.Dir = pkDir
|
2017-05-31 18:10:20 +00:00
|
|
|
if err := cmd.Run(); err != nil {
|
|
|
|
v += "+"
|
|
|
|
}
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func inDocker() bool {
|
|
|
|
r, err := os.Open("/proc/self/cgroup")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf(`can't open "/proc/self/cgroup": %v`, err)
|
|
|
|
}
|
|
|
|
defer r.Close()
|
|
|
|
sc := bufio.NewScanner(r)
|
|
|
|
for sc.Scan() {
|
|
|
|
l := sc.Text()
|
|
|
|
fields := strings.SplitN(l, ":", 3)
|
|
|
|
if len(fields) != 3 {
|
|
|
|
log.Fatal(`unexpected line in "/proc/self/cgroup"`)
|
|
|
|
}
|
2017-11-14 16:44:32 +00:00
|
|
|
if !(strings.HasPrefix(fields[2], "/docker/") ||
|
|
|
|
strings.HasPrefix(fields[2], "/system.slice/docker.service")) {
|
2017-05-31 18:10:20 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := sc.Err(); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|