Allow conditionally build for Testnet/Mainnet. Closes #40

This commit is contained in:
Victor Farazdagi 2016-10-13 14:46:54 +03:00
parent f11c6421a1
commit 286a8fc344
6 changed files with 51 additions and 12 deletions

View File

@ -5,30 +5,47 @@ GOBIN = build/bin
GO ?= latest
statusgo:
build/env.sh go build -i -o $(GOBIN)/statusgo -v $(shell build/flags.sh) ./cmd/status
build/env.sh go build -i -o $(GOBIN)/statusgo -v $(shell build/testnet-flags.sh) ./cmd/status
@echo "status go compilation done."
@echo "Run \"build/bin/statusgo\" to view available commands"
statusgo-cross: statusgo-android statusgo-ios
@echo "Full cross compilation done:"
@echo "Full cross compilation done."
@ls -ld $(GOBIN)/statusgo-*
statusgo-android: xgo
build/env.sh $(GOBIN)/xgo --image farazdagi/xgo --go=$(GO) -out statusgo --dest=$(GOBIN) --targets=android-16/aar -v $(shell build/flags.sh) ./cmd/status
@echo "Android cross compilation done:"
build/env.sh $(GOBIN)/xgo --image farazdagi/xgo --go=$(GO) -out statusgo --dest=$(GOBIN) --targets=android-16/aar -v $(shell build/testnet-flags.sh) ./cmd/status
@echo "Android cross compilation done."
statusgo-ios: xgo
build/env.sh $(GOBIN)/xgo --image farazdagi/xgo --go=$(GO) -out statusgo --dest=$(GOBIN) --targets=ios-9.3/framework -v $(shell build/flags.sh) ./cmd/status
@echo "iOS framework cross compilation done:"
build/env.sh $(GOBIN)/xgo --image farazdagi/xgo --go=$(GO) -out statusgo --dest=$(GOBIN) --targets=ios-9.3/framework -v $(shell build/testnet-flags.sh) ./cmd/status
@echo "iOS framework cross compilation done."
statusgo-ios-simulator: xgo
build/env.sh $(GOBIN)/xgo --image farazdagi/xgo-ios-simulator --go=$(GO) -out statusgo --dest=$(GOBIN) --targets=ios-9.3/framework -v $(shell build/flags.sh) ./cmd/status
@echo "iOS framework cross compilation done:"
build/env.sh $(GOBIN)/xgo --image farazdagi/xgo-ios-simulator --go=$(GO) -out statusgo --dest=$(GOBIN) --targets=ios-9.3/framework -v $(shell build/testnet-flags.sh) ./cmd/status
@echo "iOS framework cross compilation done."
xgo:
build/env.sh docker pull farazdagi/xgo
build/env.sh go get github.com/karalabe/xgo
statusgo-mainnet:
build/env.sh go build -i -o $(GOBIN)/statusgo -v $(shell build/mainnet-flags.sh) ./cmd/status
@echo "status go compilation done (mainnet)."
@echo "Run \"build/bin/statusgo\" to view available commands"
statusgo-android-mainnet: xgo
build/env.sh $(GOBIN)/xgo --image farazdagi/xgo --go=$(GO) -out statusgo --dest=$(GOBIN) --targets=android-16/aar -v $(shell build/mainnet-flags.sh) ./cmd/status
@echo "Android cross compilation done (mainnet)."
statusgo-ios-mainnet: xgo
build/env.sh $(GOBIN)/xgo --image farazdagi/xgo --go=$(GO) -out statusgo --dest=$(GOBIN) --targets=ios-9.3/framework -v $(shell build/mainnet-flags.sh) ./cmd/status
@echo "iOS framework cross compilation done (mainnet)."
statusgo-ios-simulator-mainnet: xgo
build/env.sh $(GOBIN)/xgo --image farazdagi/xgo-ios-simulator --go=$(GO) -out statusgo --dest=$(GOBIN) --targets=ios-9.3/framework -v $(shell build/mainnet-flags.sh) ./cmd/status
@echo "iOS framework cross compilation done (mainnet)."
ci:
build/env.sh go test -v -cover ./geth
build/env.sh go test -v -cover ./jail

13
build/mainnet-flags.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/sh
set -e
if [ ! -f "build/env.sh" ]; then
echo "$0 must be run from the root of the repository."
exit 2
fi
# set gitCommit when running from a Git checkout.
if [ -f ".git/HEAD" ]; then
echo "-ldflags '-X github.com/status-im/status-go/geth.UseTestnet=false -X main.buildStamp=`date -u '+%Y-%m-%d.%H:%M:%S'` -X main.gitCommit=$(git rev-parse HEAD)'";
fi

View File

@ -9,5 +9,5 @@ fi
# set gitCommit when running from a Git checkout.
if [ -f ".git/HEAD" ]; then
echo "-ldflags '-X main.buildStamp=`date -u '+%Y-%m-%d.%H:%M:%S'` -X main.gitCommit=$(git rev-parse HEAD)'"
echo "-ldflags '-X github.com/status-im/status-go/geth.UseTestnet=true -X main.buildStamp=`date -u '+%Y-%m-%d.%H:%M:%S'` -X main.gitCommit=$(git rev-parse HEAD)'";
fi

View File

@ -2,6 +2,7 @@ package main
import (
"fmt"
"github.com/status-im/status-go/geth"
)
var (
@ -22,5 +23,10 @@ func main() {
if gitCommit != "" {
verString += "-" + gitCommit[:8]
}
fmt.Printf("Status\nGit Commit: %s\nBuild Time: %s\nVersion: %s\n", gitCommit, buildStamp, verString)
netVersion := "mainnet"
if geth.UseTestnet == "true" {
netVersion = "testnet"
}
fmt.Printf("Status\nGit Commit: %s\nBuild Time: %s\nVersion: %s\nNetwork: %s\n",
gitCommit, buildStamp, verString, netVersion)
}

View File

@ -71,6 +71,7 @@ type NodeManager struct {
}
var (
UseTestnet = "true" // can be overridden via -ldflags '-X geth.UseTestnet'
nodeManagerInstance *NodeManager
createOnce sync.Once
)
@ -110,7 +111,9 @@ func (m *NodeManager) MakeNode(datadir string, rpcport int) *node.Node {
set.Bool("lightkdf", true, "Reduce key-derivation RAM & CPU usage at some expense of KDF strength")
set.Bool("shh", true, "whisper")
set.Bool("light", true, "disable eth")
if UseTestnet == "true" {
set.Bool("testnet", true, "light test network")
}
set.Bool("rpc", true, "enable rpc")
set.String("rpcaddr", "localhost", "host for RPC")
set.Int("rpcport", rpcport, "rpc port")

View File

@ -2,9 +2,9 @@ package geth_test
import (
"os"
"path/filepath"
"testing"
"time"
"path/filepath"
"github.com/status-im/status-go/geth"
)