Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add some love to Makefile #2099

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
105 changes: 77 additions & 28 deletions Makefile
Expand Up @@ -8,6 +8,49 @@ BIN_DIR = $(CURR_DIR)/build
BIN_DIR_WIN = $(CURR_DIR_WIN)/build
export GO111MODULE = on

ifneq ($(OS),Windows_NT)
# This is a code for automatic help generator.
# It supports ANSI colors and categories.
# To add new item into help output, simply add comments
# starting with '##'. To add category, use @category.
GREEN := $(shell echo "\e[32m")
BLUE := $(shell echo "\e[1;34m")
YELLOW := $(shell echo "\e[33m")
WHITE := $(shell echo "\e[1;37m")
RESET := $(shell echo "\e[0m")
define HELP_FUN
%help;
while(<>) { push @{$$help{$$2 // 'options'}}, [$$1, $$3] if /^([a-zA-Z0-9\-]+)\s*:.*\#\#(?:@([a-zA-Z\-]+))?\s(.*)$$/ };
print <<"END";
___________________________________________________________________
| _______________________________________________________________ |
| | | |
| | \\\\ | |
| | \\\\_ | |
| | ( _\\ | |
| | / \\__ | |
| | / _/`"` | |
| | {\\ )_ | |
| | `"""` | |
| | ${WHITE}ⴵ spacemesh${RESET} ${BLUE}// makefile ${RESET} | |
| | Usage: make [target] | |
| |_______________________________________________________________| |
|___________________________________________________________________|

END
for (sort keys %help) {
print "${BLUE}// $$_:${RESET}\n";
for (@{$$help{$$_}}) {
$$sep = " " x (35 - length $$_->[0]);
print " ${YELLOW}$$_->[0]${RESET}$$sep${GREEN}$$_->[1]${RESET}\n";
};
print "\n";
}
endef
export HELP_FUN

endif

BRANCH := $(shell bash -c 'if [ "$$TRAVIS_PULL_REQUEST" == "false" ]; then echo $$TRAVIS_BRANCH; else echo $$TRAVIS_PULL_REQUEST_BRANCH; fi')

# Set BRANCH when running make manually
Expand All @@ -24,16 +67,22 @@ PLATFORMS := windows linux darwin freebsd
os = $(word 1, $@)

ifeq ($(BRANCH),develop)
DOCKER_IMAGE_REPO := go-spacemesh
DOCKER_IMAGE_REPO := go-spacemesh
else
DOCKER_IMAGE_REPO := go-spacemesh-dev
DOCKER_IMAGE_REPO := go-spacemesh-dev
endif

all: install build
all: install build ##@build Install and build everything
.PHONY: all

ifneq ($(OS),Windows_NT)
help:
@perl -e "$$HELP_FUN" $(MAKEFILE_LIST)
.PHONY: help
endif


install:
install: ##@build Prepare dev environment and install dependencies
ifeq ($(OS),Windows_NT)
setup_env.bat
else
Expand All @@ -42,7 +91,7 @@ endif
.PHONY: install


genproto:
genproto: ##@build Rebuild ProtoBuf autogenerated code
ifeq ($(OS),Windows_NT)
scripts\win\genproto.bat
else
Expand All @@ -51,7 +100,7 @@ endif
.PHONY: genproto


build: genproto
build: genproto ##@build Build go-spacemesh executable
ifeq ($(OS),Windows_NT)
go build ${LDFLAGS} -o $(BIN_DIR_WIN)/$(BINARY).exe
else
Expand All @@ -60,7 +109,7 @@ endif
.PHONY: build


hare:
hare: ##@build Build Hare tester binary
ifeq ($(OS),Windows_NT)
cd cmd/hare ; go build -o $(BIN_DIR_WIN)/go-hare.exe; cd ..
else
Expand All @@ -69,7 +118,7 @@ endif
.PHONY: hare


p2p:
p2p: ##@build Build P2P tester binary
ifeq ($(OS),WINDOWS_NT)
cd cmd/p2p ; go build -o $(BIN_DIR_WIN)/go-p2p.exe; cd ..
else
Expand All @@ -78,7 +127,7 @@ endif
.PHONY: p2p


sync:
sync: ##@build Build Sync tester binary
ifeq ($(OS),WINDOWS_NT)
cd cmd/sync ; go build -o $(BIN_DIR_WIN)/go-sync.exe; cd ..
else
Expand All @@ -87,7 +136,7 @@ endif
.PHONY: sync


harness:
harness: ##@build Build Harness binary
ifeq ($(OS),WINDOWS_NT)
cd cmd/integration ; go build -o $(BIN_DIR_WIN)/go-harness.exe; cd ..
else
Expand All @@ -96,7 +145,7 @@ endif
.PHONY: harness


tidy:
tidy: ##@housekeeping Tidy go modules
go mod tidy
.PHONY: tidy

Expand All @@ -115,22 +164,22 @@ arm6: genproto
.PHONY: pi


test: genproto
test: genproto ##@test Run tests
ulimit -n 9999; go test -timeout 0 -p 1 ./...
.PHONY: test


test-no-app-test: genproto
test-no-app-test: genproto ##@test Run tests except excluding app
ulimit -n 9999; go test -timeout 0 -p 1 -tags exclude_app_test ./...
.PHONY: test


test-only-app-test: genproto
test-only-app-test: genproto ##@test Run only app test
ulimit -n 9999; go test -timeout 0 -p 1 -v -tags !exclude_app_test ./cmd/node
.PHONY: test


test-tidy:
test-tidy: ##@housekeeping Make sure dependencees are intact
# Working directory must be clean, or this test would be destructive
git diff --quiet || (echo "\033[0;31mWorking directory not clean!\033[0m" && git diff && exit 1)
# We expect `go mod tidy` not to change anything, the test should fail otherwise
Expand All @@ -139,20 +188,20 @@ test-tidy:
.PHONY: test-tidy


test-fmt:
test-fmt: ##@housekeeping Make sure code is formatted properly
git diff --quiet || (echo "\033[0;31mWorking directory not clean!\033[0m" && git diff && exit 1)
# We expect `go fmt` not to change anything, the test should fail otherwise
go fmt ./...
git diff --exit-code || (git diff && git checkout . && exit 1)
.PHONY: test-fmt

lint:
lint: ##@housekeeping Check go linters happiness
golint --set_exit_status ./...
go vet ./...
.PHONY: lint


cover:
cover: ##@housekeeping Generate test coverage info
@echo "mode: count" > cover-all.out
@$(foreach pkg,$(PKGS),\
go test -coverprofile=cover.out -covermode=count $(pkg);\
Expand All @@ -161,7 +210,7 @@ cover:
.PHONY: cover


tag-and-build:
tag-and-build: ##@housekeeping Apply new version
@git diff --quiet || (echo "working directory must be clean"; exit 2)
echo ${VERSION} > version.txt
git commit -m "bump version to ${VERSION}" version.txt
Expand All @@ -173,18 +222,18 @@ tag-and-build:
.PHONY: tag-and-build


list-versions:
list-versions: ##@housekeeping List 4 latest tags
@echo "Latest 5 tagged versions:\n"
@git for-each-ref --sort=-creatordate --count=5 --format '%(creatordate:short): %(refname:short)' refs/tags
.PHONY: list-versions


dockerbuild-go:
dockerbuild-go: ##@housekeeping Build spacemesh docker image
docker build -t $(DOCKER_IMAGE_REPO):$(BRANCH) .
.PHONY: dockerbuild-go


dockerbuild-test:
dockerbuild-test: ##@housekeeping Build tests docker image
docker build -f DockerFileTests --build-arg GCLOUD_KEY="$(GCLOUD_KEY)" \
--build-arg PROJECT_NAME="$(PROJECT_NAME)" \
--build-arg CLUSTER_NAME="$(CLUSTER_NAME)" \
Expand All @@ -193,7 +242,7 @@ dockerbuild-test:
.PHONY: dockerbuild-test


dockerpush: dockerbuild-go
dockerpush: dockerbuild-go ##@housekeeping Push docker image
echo "$(DOCKER_PASSWORD)" | docker login -u "$(DOCKER_USERNAME)" --password-stdin
docker tag $(DOCKER_IMAGE_REPO):$(BRANCH) spacemeshos/$(DOCKER_IMAGE_REPO):$(BRANCH)
docker push spacemeshos/$(DOCKER_IMAGE_REPO):$(BRANCH)
Expand Down Expand Up @@ -399,23 +448,23 @@ dockertest-tx-stress: dockerbuild-test dockerrun-tx-stress


# The following is used to run tests one after the other locally
dockerrun-test: dockerbuild-test dockerrun-p2p dockerrun-mining dockerrun-hare dockerrun-sync dockerrun-late-nodes dockerrun-genesis-voting dockerrun-blocks-add-node dockerrun-blocks-add-node dockerrun-blocks-remove-node
dockerrun-test: dockerbuild-test dockerrun-p2p dockerrun-mining dockerrun-hare dockerrun-sync dockerrun-late-nodes dockerrun-genesis-voting dockerrun-blocks-add-node dockerrun-blocks-add-node dockerrun-blocks-remove-node ##@test Run docker containers for tests
.PHONY: dockerrun-test

dockerrun-all: dockerpush dockerrun-test
.PHONY: dockerrun-all

dockerrun-stress: dockerbuild-test dockerrun-blocks-stress dockerrun-grpc-stress dockerrun-sync-stress dockerrun-tx-stress
dockerrun-stress: dockerbuild-test dockerrun-blocks-stress dockerrun-grpc-stress dockerrun-sync-stress dockerrun-tx-stress ##@test Run stress tests in docker
.PHONY: dockerrun-stress

dockertest-stress: dockerpush dockerrun-stress
.PHONY: dockertest-stress

dockertest-hare-mining: dockertest-hare dockertest-mining
dockertest-hare-mining: dockertest-hare dockertest-mining ##@test Run Hare and mining tests in docker
.PHONY: dockertest-hare-mining

dockertest-sync-blocks-remove-node: dockertest-sync dockertest-blocks-remove-node
dockertest-sync-blocks-remove-node: dockertest-sync dockertest-blocks-remove-node ##@test Run syncrhonization and blocks tests in docker
.PHONY: dockertest-sync-blocks-remove-node

dockertest-genesis-voting-p2p: dockertest-genesis-voting dockertest-p2p
dockertest-genesis-voting-p2p: dockertest-genesis-voting dockertest-p2p ##@test Run genesis voting and p2p tests in docker
.PHONY: dockertest-genesis-voting-p2p