This repository has been archived by the owner on Mar 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Makefile
135 lines (110 loc) · 3.31 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
MAKEFLAGS += --warn-undefined-variables
SHELL := /bin/bash
.SHELLFLAGS := -o pipefail -euc
.DEFAULT_GOAL := test
export PROJECT = toscalib
IMPORT_PATH := github.com/CiscoCloud/${PROJECT}
# Windows environment?
CYG_CHECK := $(shell hash cygpath 2>/dev/null && echo 1)
ifeq ($(CYG_CHECK),1)
VBOX_CHECK := $(shell hash VBoxManage 2>/dev/null && echo 1)
# Docker Toolbox (pre-Windows 10)
ifeq ($(VBOX_CHECK),1)
ROOT := /${PROJECT}
else
# Docker Windows
ROOT := $(shell cygpath -m -a "$(shell pwd)")
endif
else
# all non-windows environments
ROOT := $(shell pwd)
endif
INSTALL_VENDOR := $(shell [ ! -d vendor ] && echo 1)
FORCE_VENDOR_INSTALL ?=
ifneq ($(strip $(FORCE_VENDOR_INSTALL)),)
INSTALL_VENDOR := 1
endif
CI ?= false
DEV_IMAGE := ${PROJECT}_dev
DOCKERRUN := docker run --rm \
-v ${ROOT}/vendor:/go/src \
-v ${ROOT}:/${PROJECT}/src/${IMPORT_PATH} \
-w /${PROJECT}/src/${IMPORT_PATH} \
${DEV_IMAGE}
DOCKERNOVENDOR := docker run --rm -i \
-e CI="${CI}" \
-v ${ROOT}:/${PROJECT}/src/${IMPORT_PATH} \
-w /${PROJECT}/src/${IMPORT_PATH} \
${DEV_IMAGE}
clean:
@${DOCKERRUN} bash -c 'rm -rf cover'
## Same as clean but also removes cached dependencies.
veryclean: clean
@${DOCKERRUN} bash -c 'rm -rf tmp .glide vendor'
## prefix before other make targets to run in your local dev environment
local: | quiet
@$(eval DOCKERRUN= )
@$(eval DOCKERNOVENDOR= )
@mkdir -p tmp
@touch tmp/dev_image_id
quiet: # this is silly but shuts up 'Nothing to be done for `local`'
@:
## builds the dev container
prepare: tmp/dev_image_id
tmp/dev_image_id: Dockerfile.dev
@mkdir -p tmp
@docker rmi -f ${DEV_IMAGE} > /dev/null 2>&1 || true
@echo "## Building dev container"
@docker build --quiet -t ${DEV_IMAGE} -f Dockerfile.dev .
@docker inspect -f "{{ .ID }}" ${DEV_IMAGE} > tmp/dev_image_id
# ----------------------------------------------
# dependencies
# NOTE: glide will be replaced with `dep` when its production-ready
# ref https://github.com/golang/dep
## Install dependencies using glide if glide.yaml changed.
vendor: tmp/glide-installed
tmp/glide-installed: tmp/dev_image_id glide.yaml
@mkdir -p vendor
${DOCKERRUN} glide install
@date > tmp/glide-installed
## Install all dependencies using glide.
dep-install: prepare
@mkdir -p vendor
${DOCKERRUN} glide install
@date > tmp/glide-installed
## Update dependencies using glide.
dep-update: prepare
${DOCKERRUN} glide up
# usage DEP=github.com/owner/package make dep-add
## Add new dependencies to glide and install.
dep-add: prepare
ifeq ($(strip $(DEP)),)
$(error "No dependency provided. Expected: DEP=<go import path>")
endif
${DOCKERNOVENDOR} glide get --skip-test ${DEP}
# ----------------------------------------------
# develop and test
.PHONY: format
format: tmp/glide-installed
${DOCKERNOVENDOR} bash ./scripts/fmt.sh
.PHONY: check
check: format
${DOCKERNOVENDOR} bash ./scripts/check.sh
# default task
.PHONY: test
test: check
${DOCKERRUN} bash ./scripts/test.sh
# run unit tests and write out test coverage
.PHONY: cover
cover: check
@rm -rf cover/
@mkdir -p cover
${DOCKERRUN} bash ./scripts/cover.sh
# ------ Generator
.PHONY: generate
generate: prepare NormativeTypes/*
${DOCKERRUN} go-bindata -pkg=toscalib -prefix=NormativeTypes/ -o normative_definitions.go NormativeTypes/
# ------ Minishift / Docker Machine Helpers
.PHONY: setup
setup:
@bash ./scripts/setup.sh