Merge pull request #822 from fjl/makefile-improvements

Makefile improvements
This commit is contained in:
Jeffrey Wilcke 2015-04-29 04:43:38 -07:00
commit bac4440e17
10 changed files with 121 additions and 98 deletions

4
.gitignore vendored
View File

@ -30,3 +30,7 @@ deploy/osx/Mist\ Installer.dmg
/build/_workspace/ /build/_workspace/
/build/bin/ /build/bin/
# travis
profile.tmp
profile.cov

View File

@ -4,13 +4,12 @@ go:
before_install: before_install:
- sudo add-apt-repository ppa:beineri/opt-qt541 -y - sudo add-apt-repository ppa:beineri/opt-qt541 -y
- sudo apt-get update -qq - sudo apt-get update -qq
- sudo apt-get install -yqq libgmp3-dev libreadline6-dev qt54quickcontrols qt54webengine - sudo apt-get install -yqq libgmp3-dev qt54quickcontrols qt54webengine
install: install:
# - go get code.google.com/p/go.tools/cmd/goimports # - go get code.google.com/p/go.tools/cmd/goimports
# - go get github.com/golang/lint/golint # - go get github.com/golang/lint/golint
# - go get golang.org/x/tools/cmd/vet # - go get golang.org/x/tools/cmd/vet
- go get golang.org/x/tools/cmd/cover - go get golang.org/x/tools/cmd/cover github.com/mattn/goveralls
- go get github.com/mattn/goveralls
before_script: before_script:
# - gofmt -l -w . # - gofmt -l -w .
# - goimports -l -w . # - goimports -l -w .
@ -18,7 +17,7 @@ before_script:
# - go vet ./... # - go vet ./...
# - go test -race ./... # - go test -race ./...
script: script:
- ./gocoverage.sh - make travis-test-with-coverage
after_success: after_success:
- if [ "$COVERALLS_TOKEN" ]; then goveralls -coverprofile=profile.cov -service=travis-ci -repotoken $COVERALLS_TOKEN; fi - if [ "$COVERALLS_TOKEN" ]; then goveralls -coverprofile=profile.cov -service=travis-ci -repotoken $COVERALLS_TOKEN; fi
env: env:

View File

@ -1,22 +1,28 @@
# This Makefile is meant to be used by people that do not usually work # This Makefile is meant to be used by people that do not usually work
# with Go source code. If you know what GOPATH is then you probably # with Go source code. If you know what GOPATH is then you probably
# don't need to bother with make. # don't need to bother with make.
#
# Note that there is no way to run the tests or do anything other than
# building the binaries. This is by design.
.PHONY: geth mist clean .PHONY: geth mist all test travis-test-with-coverage clean
GOBIN = build/bin GOBIN = build/bin
geth: geth:
build/env.sh go install -v github.com/ethereum/go-ethereum/cmd/geth build/env.sh go install -v $(shell build/ldflags.sh) ./cmd/geth
@echo "Done building." @echo "Done building."
@echo "Run \"$(GOBIN)/geth\" to launch geth." @echo "Run \"$(GOBIN)/geth\" to launch geth."
mist: mist:
build/env.sh go install -v github.com/ethereum/go-ethereum/cmd/mist build/env.sh go install -v $(shell build/ldflags.sh) ./cmd/mist
@echo "Done building." @echo "Done building."
@echo "Run \"$(GOBIN)/mist --asset_path=cmd/mist/assets\" to launch mist." @echo "Run \"$(GOBIN)/mist --asset_path=cmd/mist/assets\" to launch mist."
all:
build/env.sh go install -v $(shell build/ldflags.sh) ./...
test: all
build/env.sh go test ./...
travis-test-with-coverage: all
build/env.sh build/test-global-coverage.sh
clean: clean:
rm -fr build/_workspace/pkg/ $(GOBIN)/* rm -fr build/_workspace/pkg/ Godeps/_workspace/pkg $(GOBIN)/*

View File

@ -12,38 +12,6 @@ master | [![Build+Status](https://build.ethdev.com/buildstatusimage?builder=L
[![Stories in Progress](https://badge.waffle.io/ethereum/go-ethereum.svg?label=in%20progress&title=In Progress)](http://waffle.io/ethereum/go-ethereum) [![Stories in Progress](https://badge.waffle.io/ethereum/go-ethereum.svg?label=in%20progress&title=In Progress)](http://waffle.io/ethereum/go-ethereum)
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ethereum/go-ethereum?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ethereum/go-ethereum?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
Build
=====
Mist (GUI):
`go get github.com/ethereum/go-ethereum/cmd/mist`
Geth (CLI):
`go get github.com/ethereum/go-ethereum/cmd/geth`
As of POC-8, go-ethereum uses [Godep](https://github.com/tools/godep) to manage dependencies. Assuming you have [your environment all set up](https://github.com/ethereum/go-ethereum/wiki/Building-Ethereum), switch to the go-ethereum repository root folder, and build/install the executable you need:
Mist (GUI):
```
godep go build -v ./cmd/mist
```
Geth (CLI):
```
godep go build -v ./cmd/geth
```
Instead of `build`, you can use `install` which will also install the resulting binary.
For prerequisites and detailed build instructions please see the [Wiki](https://github.com/ethereum/go-ethereum/wiki/Building-Ethereum)
If you intend to develop on go-ethereum, check the [Developers' Guide](https://github.com/ethereum/go-ethereum/wiki/Developers'-Guide)
Automated (dev) builds Automated (dev) builds
====================== ======================
@ -54,6 +22,19 @@ Automated (dev) builds
[utopic](https://build.ethdev.com/builds/Linux%20Go%20develop%20deb%20i386-utopic/latest/) [utopic](https://build.ethdev.com/builds/Linux%20Go%20develop%20deb%20i386-utopic/latest/)
* [Windows 64-bit](https://build.ethdev.com/builds/Windows%20Go%20develop%20branch/Geth-Win64-latest.7z) * [Windows 64-bit](https://build.ethdev.com/builds/Windows%20Go%20develop%20branch/Geth-Win64-latest.7z)
Building the source
===================
For prerequisites and detailed build instructions please read the
[Installation Instructions](https://github.com/ethereum/go-ethereum/wiki/Building-Ethereum)
on the wiki.
Building geth requires two external dependencies, Go and GMP.
You can install them using your favourite package manager.
Once the dependencies are installed, run
make geth
Executables Executables
=========== ===========
@ -68,18 +49,16 @@ Go Ethereum comes with several wrappers/executables found in
* `evm` is a generic Ethereum Virtual Machine: `evm -code 60ff60ff -gas * `evm` is a generic Ethereum Virtual Machine: `evm -code 60ff60ff -gas
10000 -price 0 -dump`. See `-h` for a detailed description. 10000 -price 0 -dump`. See `-h` for a detailed description.
* `disasm` disassembles EVM code: `echo "6001" | disasm` * `disasm` disassembles EVM code: `echo "6001" | disasm`
* `rlpdump` converts a rlp stream to `interface{}`. * `rlpdump` prints RLP structures
Command line options Command line options
============================ ====================
Both `mist` and `geth` can be configured via command line options, environment variables and config files. Both `mist` and `geth` can be configured via command line options, environment variables and config files.
To get the options available: To get the options available:
``` geth --help
geth -help
```
For further details on options, see the [wiki](https://github.com/ethereum/go-ethereum/wiki/Command-Line-Options) For further details on options, see the [wiki](https://github.com/ethereum/go-ethereum/wiki/Command-Line-Options)
@ -92,6 +71,6 @@ are ignored (use gofmt!). If you send pull requests make absolute sure that you
commit on the `develop` branch and that you do not merge to master. commit on the `develop` branch and that you do not merge to master.
Commits that are directly based on master are simply ignored. Commits that are directly based on master are simply ignored.
See [Developers' Guide](https://github.com/ethereum/go-ethereum/wiki/Developers'-Guide) for more details on configuring your environment, testing, and dependency management. See [Developers' Guide](https://github.com/ethereum/go-ethereum/wiki/Developers'-Guide)
for more details on configuring your environment, testing, and
TEST dependency management.

View File

@ -24,5 +24,9 @@ GOPATH="$ethdir/go-ethereum/Godeps/_workspace:$workspace"
GOBIN="$PWD/build/bin" GOBIN="$PWD/build/bin"
export GOPATH GOBIN export GOPATH GOBIN
# Run the command inside the workspace.
cd "$ethdir/go-ethereum"
PWD="$ethdir/go-ethereum"
# Launch the arguments with the configured environment. # Launch the arguments with the configured environment.
exec $@ exec "$@"

13
build/ldflags.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 main.gitCommit $(git rev-parse HEAD)'"
fi

26
build/test-global-coverage.sh Executable file
View File

@ -0,0 +1,26 @@
#!/bin/bash
# This script runs all package tests and merges the resulting coverage
# profiles. Coverage is accounted per package under test.
set -e
if [ ! -f "build/env.sh" ]; then
echo "$0 must be run from the root of the repository."
exit 2
fi
echo "mode: count" > profile.cov
for pkg in $(go list ./...); do
# drop the namespace prefix.
dir=${pkg##github.com/ethereum/go-ethereum/}
if [[ $dir != "tests/vm" ]]; then
go test -covermode=count -coverprofile=$dir/profile.tmp $pkg
fi
if [[ -f $dir/profile.tmp ]]; then
tail -n +2 $dir/profile.tmp >> profile.cov
rm $dir/profile.tmp
fi
done

View File

@ -50,9 +50,20 @@ const (
Version = "0.9.12" Version = "0.9.12"
) )
var app = utils.NewApp(Version, "the go-ethereum command line interface") var (
gitCommit string // set via linker flag
nodeNameVersion string
app *cli.App
)
func init() { func init() {
if gitCommit == "" {
nodeNameVersion = Version
} else {
nodeNameVersion = Version + "-" + gitCommit[:8]
}
app = utils.NewApp(Version, "the go-ethereum command line interface")
app.Action = run app.Action = run
app.HideVersion = true // we have a command to print the version app.HideVersion = true // we have a command to print the version
app.Commands = []cli.Command{ app.Commands = []cli.Command{
@ -278,7 +289,7 @@ func main() {
func run(ctx *cli.Context) { func run(ctx *cli.Context) {
utils.HandleInterrupt() utils.HandleInterrupt()
cfg := utils.MakeEthConfig(ClientIdentifier, Version, ctx) cfg := utils.MakeEthConfig(ClientIdentifier, nodeNameVersion, ctx)
ethereum, err := eth.New(cfg) ethereum, err := eth.New(cfg)
if err != nil { if err != nil {
utils.Fatalf("%v", err) utils.Fatalf("%v", err)
@ -290,7 +301,7 @@ func run(ctx *cli.Context) {
} }
func console(ctx *cli.Context) { func console(ctx *cli.Context) {
cfg := utils.MakeEthConfig(ClientIdentifier, Version, ctx) cfg := utils.MakeEthConfig(ClientIdentifier, nodeNameVersion, ctx)
ethereum, err := eth.New(cfg) ethereum, err := eth.New(cfg)
if err != nil { if err != nil {
utils.Fatalf("%v", err) utils.Fatalf("%v", err)
@ -305,7 +316,7 @@ func console(ctx *cli.Context) {
} }
func execJSFiles(ctx *cli.Context) { func execJSFiles(ctx *cli.Context) {
cfg := utils.MakeEthConfig(ClientIdentifier, Version, ctx) cfg := utils.MakeEthConfig(ClientIdentifier, nodeNameVersion, ctx)
ethereum, err := eth.New(cfg) ethereum, err := eth.New(cfg)
if err != nil { if err != nil {
utils.Fatalf("%v", err) utils.Fatalf("%v", err)
@ -487,7 +498,7 @@ func exportchain(ctx *cli.Context) {
utils.Fatalf("This command requires an argument.") utils.Fatalf("This command requires an argument.")
} }
cfg := utils.MakeEthConfig(ClientIdentifier, Version, ctx) cfg := utils.MakeEthConfig(ClientIdentifier, nodeNameVersion, ctx)
cfg.SkipBcVersionCheck = true cfg.SkipBcVersionCheck = true
ethereum, err := eth.New(cfg) ethereum, err := eth.New(cfg)
@ -589,15 +600,17 @@ func makedag(ctx *cli.Context) {
} }
func version(c *cli.Context) { func version(c *cli.Context) {
fmt.Printf(`%v fmt.Println(ClientIdentifier)
Version: %v fmt.Println("Version:", Version)
Protocol Version: %d if gitCommit != "" {
Network Id: %d fmt.Println("Git Commit:", gitCommit)
GO: %s }
OS: %s fmt.Println("Protocol Version:", c.GlobalInt(utils.ProtocolVersionFlag.Name))
GOPATH=%s fmt.Println("Network Id:", c.GlobalInt(utils.NetworkIdFlag.Name))
GOROOT=%s fmt.Println("Go Version:", runtime.Version())
`, ClientIdentifier, Version, c.GlobalInt(utils.ProtocolVersionFlag.Name), c.GlobalInt(utils.NetworkIdFlag.Name), runtime.Version(), runtime.GOOS, os.Getenv("GOPATH"), runtime.GOROOT()) fmt.Println("OS:", runtime.GOOS)
fmt.Printf("GOPATH=%s\n", os.Getenv("GOPATH"))
fmt.Printf("GOROOT=%s\n", runtime.GOROOT())
} }
// hashish returns true for strings that look like hashes. // hashish returns true for strings that look like hashes.

View File

@ -41,6 +41,9 @@ const (
) )
var ( var (
gitCommit string // set via linker flag
nodeNameVersion string
app = utils.NewApp(Version, "the ether browser") app = utils.NewApp(Version, "the ether browser")
assetPathFlag = cli.StringFlag{ assetPathFlag = cli.StringFlag{
Name: "asset_path", Name: "asset_path",
@ -55,6 +58,11 @@ func init() {
if len(rpcCorsFlag.Value) == 0 { if len(rpcCorsFlag.Value) == 0 {
rpcCorsFlag.Value = "http://localhost" rpcCorsFlag.Value = "http://localhost"
} }
if gitCommit == "" {
nodeNameVersion = Version
} else {
nodeNameVersion = Version + "-" + gitCommit[:8]
}
app.Action = run app.Action = run
app.Flags = []cli.Flag{ app.Flags = []cli.Flag{
@ -74,6 +82,7 @@ func init() {
utils.RPCPortFlag, utils.RPCPortFlag,
utils.JSpathFlag, utils.JSpathFlag,
utils.ProtocolVersionFlag, utils.ProtocolVersionFlag,
utils.BlockchainVersionFlag,
utils.NetworkIdFlag, utils.NetworkIdFlag,
} }
} }
@ -106,7 +115,8 @@ func run(ctx *cli.Context) {
tstart := time.Now() tstart := time.Now()
// TODO: show qml popup instead of exiting if initialization fails. // TODO: show qml popup instead of exiting if initialization fails.
cfg := utils.MakeEthConfig(ClientIdentifier, Version, ctx) cfg := utils.MakeEthConfig(ClientIdentifier, nodeNameVersion, ctx)
cfg.Shh = true
ethereum, err := eth.New(cfg) ethereum, err := eth.New(cfg)
if err != nil { if err != nil {
utils.Fatalf("%v", err) utils.Fatalf("%v", err)

View File

@ -1,31 +0,0 @@
#!/bin/bash
set -e
# Add godep workspace to GOPATH. We do it manually instead of using
# 'godep go test' or 'godep restore' so godep doesn't need to be installed.
GOPATH="$PWD/Godeps/_workspace:$GOPATH"
# Install packages before testing. Not doing this would cause
# 'go test' to recompile all package dependencies before testing each package.
go install ./...
# Run test coverage on each subdirectories and merge the coverage profile.
echo "mode: count" > profile.cov
# Standard go tooling behavior is to ignore dirs with leading underscors
for dir in $(find . -maxdepth 10 -not -path './.git*' -not -path '*/_*' -type d);
do
if ls $dir/*.go &> /dev/null; then
# echo $dir
if [[ $dir != "./tests/vm" && $dir != "." ]]
then
go test -covermode=count -coverprofile=$dir/profile.tmp $dir
fi
if [ -f $dir/profile.tmp ]
then
cat $dir/profile.tmp | tail -n +2 >> profile.cov
rm $dir/profile.tmp
fi
fi
done