<commit_before>SHELL = /bin/sh
HERE = $(shell pwd)
BIN = $(HERE)/bin
GPM = $(HERE)/gpm
DEPS = $(HERE)/.godeps
GOPATH = $(DEPS):$(HERE)

PLATFORM=$(shell uname)

# Setup commands and env vars if there is no system go linked into bin/go
PATH := $(HERE)/bin:$(DEPS)/bin:$(PATH)

PACKAGE = github.com/mozilla-services/pushgo
TARGET = simplepush
COVER_MODE = count
COVER_PATH = $(HERE)/.coverage

VERSION = $(strip $(shell [ -e $(HERE)/GITREF ] && cat $(HERE)/GITREF 2>/dev/null))
ifeq ($(VERSION),)
	VERSION = $(strip $(shell git describe --tags --always HEAD 2>/dev/null))
endif

ifneq ($(strip $(VERSION)),)
	GOLDFLAGS := -X $(PACKAGE)/simplepush.VERSION $(VERSION) $(GOLDFLAGS)
endif

.PHONY: all build clean test $(TARGET) memcached

all: build

$(BIN):
	mkdir -p $(BIN)

$(DEPS):
	@echo "Installing dependencies"
	GOPATH=$(GOPATH) $(GPM) install
	GOPATH=$(GOPATH) go get -u github.com/mattn/goveralls

build: $(DEPS)

libmemcached-1.0.18:
	wget -qO - https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz | tar xvz
	cd libmemcached-1.0.18 && \
	./configure --prefix=/usr && \
	autoreconf -ivf
ifeq ($(PLATFORM),Darwin)
	cd libmemcached-1.0.18 && \
	sed -i '' $$'/ax_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"/c\\\nax_pthread_flags=\"pthreads none -Kthread -kthread lthread -lpthread -lpthreads -mthreads pthread --thread-safe -mt pthread-config"\n' m4/ax_pthread.m4
else
	cd libmemcached-1.0.18 && \
	sed -i '/ax_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"/c\ax_pthread_flags="pthreads none -Kthread -kthread lthread -lpthread -lpthreads -mthreads pthread --thread-safe -mt pthread-config"' m4/ax_pthread.m4
endif

memcached: libmemcached-1.0.18
	cd libmemcached-1.0.18 && sudo make install

$(TARGET):
	rm -f $(TARGET)
	@echo "Building simplepush"
	GOPATH=$(GOPATH) go build \
		-ldflags "$(GOLDFLAGS)" -tags libmemcached -o $(TARGET) $(PACKAGE)

$(HERE)/mockgen:
	GOPATH=$(GOPATH) go build github.com/rafrombrc/gomock/mockgen

test-mocks: $(HERE)/mockgen
	./mockgen -source=src/github.com/mozilla-services/pushgo/simplepush/config.go \
		-destination=src/github.com/mozilla-services/pushgo/simplepush/mock_config_test.go -package="simplepush"
	./mockgen -source=src/github.com/mozilla-services/pushgo/simplepush/worker.go \
		-destination=src/github.com/mozilla-services/pushgo/simplepush/mock_worker_test.go -package="simplepush"
	./mockgen -source=src/github.com/mozilla-services/pushgo/simplepush/storage.go \
		-destination=src/github.com/mozilla-services/pushgo/simplepush/mock_store_test.go -package="simplepush"
	./mockgen -source=src/github.com/mozilla-services/pushgo/simplepush/locator.go \
		-destination=src/github.com/mozilla-services/pushgo/simplepush/mock_locator_test.go -package="simplepush"
	./mockgen -source=src/github.com/mozilla-services/pushgo/simplepush/metrics.go \
		-destination=src/github.com/mozilla-services/pushgo/simplepush/mock_metrics_test.go -package="simplepush"
	# Note that to generate the log/router mock, the HasConfigStruct needs to be manually
	# copied into log.go while this is run, then the mocked config struct needs to be
	# removed from the mock_log_test.go file.
	# Issue: https://code.google.com/p/gomock/issues/detail?id=16
	#./mockgen -source=src/github.com/mozilla-services/pushgo/simplepush/log.go \
	#	-destination=src/github.com/mozilla-services/pushgo/simplepush/mock_log_test.go -package="simplepush"
	#./mockgen -source=src/github.com/mozilla-services/pushgo/simplepush/router.go \
	#	-destination=src/github.com/mozilla-services/pushgo/simplepush/mock_router_test.go -package="simplepush"

test-gomc:
	GOPATH=$(GOPATH) go test \
		-tags "memcached_server_test libmemcached" \
		-ldflags "$(GOLDFLAGS)" $(addprefix $(PACKAGE)/,id retry simplepush)

test-gomemcache:
	GOPATH=$(GOPATH) go test \
		-tags memcached_server_test \
		-ldflags "$(GOLDFLAGS)" $(addprefix $(PACKAGE)/,id retry simplepush)

clean-cov:
	rm -rf $(COVER_PATH)
	rm -f $(addprefix coverage,.out .html)

cov-dir: clean-cov
	mkdir -p $(COVER_PATH)

retry-cov: cov-dir
	GOPATH=$(GOPATH) go test \
		-covermode=$(COVER_MODE) -coverprofile=$(COVER_PATH)/retry.out \
		-ldflags "$(GOLDFLAGS)" $(PACKAGE)/retry

id-cov: cov-dir
	GOPATH=$(GOPATH) go test \
		-covermode=$(COVER_MODE) -coverprofile=$(COVER_PATH)/id.out \
		-ldflags "$(GOLDFLAGS)" $(PACKAGE)/id

simplepush-cov: cov-dir
	GOPATH=$(GOPATH) go test \
		-covermode=$(COVER_MODE) -coverprofile=$(COVER_PATH)/simplepush.out \
		-ldflags "$(GOLDFLAGS)" $(PACKAGE)/simplepush

# Merge coverage reports for each package. -coverprofile does not support<commit_msg>Add go cover check<commit_after>SHELL = /bin/sh
HERE = $(shell pwd)
BIN = $(HERE)/bin
GPM = $(HERE)/gpm
DEPS = $(HERE)/.godeps
GOPATH = $(DEPS):$(HERE)
TOOLS = $(shell GOPATH=$(GOPATH) go tool)

PLATFORM=$(shell uname)

# Setup commands and env vars if there is no system go linked into bin/go
PATH := $(HERE)/bin:$(DEPS)/bin:$(PATH)

PACKAGE = github.com/mozilla-services/pushgo
TARGET = simplepush
COVER_MODE = count
COVER_PATH = $(HERE)/.coverage

VERSION = $(strip $(shell [ -e $(HERE)/GITREF ] && cat $(HERE)/GITREF 2>/dev/null))
ifeq ($(VERSION),)
	VERSION = $(strip $(shell git describe --tags --always HEAD 2>/dev/null))
endif

ifneq ($(strip $(VERSION)),)
	GOLDFLAGS := -X $(PACKAGE)/simplepush.VERSION $(VERSION) $(GOLDFLAGS)
endif


.PHONY: all build clean test $(TARGET) memcached

all: build

$(BIN):
	mkdir -p $(BIN)

$(DEPS):
	@echo "Installing dependencies"
	GOPATH=$(GOPATH) $(GPM) install
	GOPATH=$(GOPATH) go get -u github.com/mattn/goveralls

build: $(DEPS)

libmemcached-1.0.18:
	wget -qO - https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz | tar xvz
	cd libmemcached-1.0.18 && \
	./configure --prefix=/usr && \
	autoreconf -ivf
ifeq ($(PLATFORM),Darwin)
	cd libmemcached-1.0.18 && \
	sed -i '' $$'/ax_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"/c\\\nax_pthread_flags=\"pthreads none -Kthread -kthread lthread -lpthread -lpthreads -mthreads pthread --thread-safe -mt pthread-config"\n' m4/ax_pthread.m4
else
	cd libmemcached-1.0.18 && \
	sed -i '/ax_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"/c\ax_pthread_flags="pthreads none -Kthread -kthread lthread -lpthread -lpthreads -mthreads pthread --thread-safe -mt pthread-config"' m4/ax_pthread.m4
endif

memcached: libmemcached-1.0.18
	cd libmemcached-1.0.18 && sudo make install

$(TARGET):
	rm -f $(TARGET)
	@echo "Building simplepush"
	GOPATH=$(GOPATH) go build \
		-ldflags "$(GOLDFLAGS)" -tags libmemcached -o $(TARGET) $(PACKAGE)

$(HERE)/mockgen:
	GOPATH=$(GOPATH) go build github.com/rafrombrc/gomock/mockgen

test-mocks: $(HERE)/mockgen
	./mockgen -source=src/github.com/mozilla-services/pushgo/simplepush/config.go \
		-destination=src/github.com/mozilla-services/pushgo/simplepush/mock_config_test.go -package="simplepush"
	./mockgen -source=src/github.com/mozilla-services/pushgo/simplepush/worker.go \
		-destination=src/github.com/mozilla-services/pushgo/simplepush/mock_worker_test.go -package="simplepush"
	./mockgen -source=src/github.com/mozilla-services/pushgo/simplepush/storage.go \
		-destination=src/github.com/mozilla-services/pushgo/simplepush/mock_store_test.go -package="simplepush"
	./mockgen -source=src/github.com/mozilla-services/pushgo/simplepush/locator.go \
		-destination=src/github.com/mozilla-services/pushgo/simplepush/mock_locator_test.go -package="simplepush"
	./mockgen -source=src/github.com/mozilla-services/pushgo/simplepush/metrics.go \
		-destination=src/github.com/mozilla-services/pushgo/simplepush/mock_metrics_test.go -package="simplepush"
	# Note that to generate the log/router mock, the HasConfigStruct needs to be manually
	# copied into log.go while this is run, then the mocked config struct needs to be
	# removed from the mock_log_test.go file.
	# Issue: https://code.google.com/p/gomock/issues/detail?id=16
	#./mockgen -source=src/github.com/mozilla-services/pushgo/simplepush/log.go \
	#	-destination=src/github.com/mozilla-services/pushgo/simplepush/mock_log_test.go -package="simplepush"
	#./mockgen -source=src/github.com/mozilla-services/pushgo/simplepush/router.go \
	#	-destination=src/github.com/mozilla-services/pushgo/simplepush/mock_router_test.go -package="simplepush"

test-gomc:
	GOPATH=$(GOPATH) go test \
		-tags "memcached_server_test libmemcached" \
		-ldflags "$(GOLDFLAGS)" $(addprefix $(PACKAGE)/,id retry simplepush)

test-gomemcache:
	GOPATH=$(GOPATH) go test \
		-tags memcached_server_test \
		-ldflags "$(GOLDFLAGS)" $(addprefix $(PACKAGE)/,id retry simplepush)

check-cov:
ifneq (cover,$(filter cover,$(TOOLS)))
	@echo "Go tool 'Cover' not installed."
	go tool cover
	false
endif

clean-cov:
	rm -rf $(COVER_PATH)
	rm -f $(addprefix coverage,.out .html)

cov-dir: clean-cov
	mkdir -p $(COVER_PATH)

retry-cov: check-cov cov-dir
	GOPATH=$(GOPATH) go test \
		-covermode=$(COVER_MODE) -coverprofile=$(COVER_PATH)/retry.out \
		-ldflags "$(GOLDFLAGS)" $(PACKAGE)/retry

id-cov: check-cov cov-dir
	GOPATH=$(GOPATH) go test \
		-covermode=$(COVER_MODE) -coverprofile=$(COVER_PATH)/id.out \
		-ldflags "$(GOLDFLAGS)" $(PACKAGE)/id

simplepush-cov: check-cov cov-dir
	GOPATH=$(GOPATH) go test \
		-covermode=$(COVER_MODE) -coverprofile=$(COVER_PATH)/simplepush.out \
		-ldflags "$(GOLDFLAGS)" $(PACKAGE)/simplepush

# Merge coverage reports for each package. -coverprofile does not support
{'fraction_non_alphanumeric': 0.1572743253024506, 'fraction_numerical': 0.008685761555164926, 'mean_word_length': 4.526857142857143, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1801885', 'n_tokens_mistral': 3629, 'n_tokens_neox': 3511, 'n_words': 705}