forked from neo4j/cypher-shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
188 lines (141 loc) · 6.32 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
.DEFAULT: help
.PHONY: help build clean zip run untested-zip test integration-test tyrekicking-test mutation-test install info
gitdescribe := $(shell git describe --tags --match [0-9]*)
lasttag := $(shell git describe --tags --match [0-9]* --abbrev=0)
version ?= $(lasttag)
versionlabel = $(shell echo ${version} | awk '{ sub("^[0-9]+.[0-9]+.[0-9]+-?", "", $$1); print }')
versionnumber = $(shell echo ${version} | awk '{ sub("-.*$$", "", $$1); print }')
pkgversion ?= 1
# If no label it is assumed to be a stable release
ifeq ($(versionlabel),)
release := $(pkgversion)
distribution ?= stable
buildversion := $(version)
debversion := $(versionnumber)
else
release := 0.$(versionlabel).$(pkgversion)
distribution ?= unstable
buildversion := $(gitdescribe)
debversion := $(versionnumber)~$(versionlabel)
endif
rpmversion := $(versionnumber)-$(release)
GRADLE = ./gradlew -PbuildVersion=$(buildversion)
jarfile := cypher-shell-all.jar
rpmfile := cypher-shell-$(rpmversion).noarch.rpm
debfile := cypher-shell_$(debversion)_all.deb
outputs := cypher-shell cypher-shell.bat $(jarfile)
artifacts:=$(patsubst %,cypher-shell/build/install/cypher-shell/%,${outputs})
rpm_artifacts:=$(patsubst %,out/rpm/BUILD/%,${artifacts})
deb_artifacts:=$(patsubst %,out/debian/cypher-shell-$(debversion)/%,${artifacts})
deb_files:=$(wildcard packaging/debian/*)
deb_targets:=$(patsubst packaging/debian/%,out/debian/cypher-shell-$(debversion)/debian/%,${deb_files})
help: ## Print this help text
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
info: ## Print variables used in the build (some of which can be overridden)
@echo "--- Overridable ---"
@echo "version: ${version}"
@echo "pkgversion: ${pkgversion}"
@echo "--- Calculated ---"
@echo "versionnumber: ${versionnumber}"
@echo "versionlabel: ${versionlabel}"
@echo "distribution: ${distribution}"
@echo "buildversion: ${buildversion}"
@echo "release: ${release}"
@echo "debversion: ${debversion}"
@echo "rpmversion: ${rpmversion}"
run: $(artifacts) ## Build and run cypher-shell with no arguments
cypher-shell/build/install/cypher-shell/cypher-shell
zip: out/cypher-shell.zip test integration-test tyrekicking-test ## Build and run all tests on zip distribution file in 'out/'
untested-zip: out/cypher-shell.zip ## Build (but don't test) zip distribution file in 'out/'
build: $(artifacts) ## Build cypher-shell
test: cypher-shell/build/test-results/binary/test/results.bin ## Run all unit tests
integration-test: cypher-shell/build/test-results/binary/integrationTest/results.bin ## Run all integration tests
tyrekicking-test: tmp/.tests-pass ## Test that the shell script can actually start
mutation-test: cypher-shell/build/reports/pitest/index.html ## Generate a mutation testing report
clean: ## Clean build directories
rm -rf out
rm -rf tmp
$(GRADLE) clean
rmhosts: ## Remove known hosts file
rm -rf ~/.neo4j/known_hosts
launch: rmhosts clean build run ## Removes known hosts file, cleans, builds, and runs the shell
prefix ?= /usr/local
install: build cypher-shell.1 ## Install cypher-shell (requires pandoc for manual)
mkdir -p $(DESTDIR)/$(prefix)/bin
mkdir -p $(DESTDIR)/$(prefix)/share/cypher-shell/lib
mkdir -p $(DESTDIR)/$(prefix)/share/man/man1
cp cypher-shell/build/install/cypher-shell/cypher-shell $(DESTDIR)/$(prefix)/bin
cp cypher-shell/build/install/cypher-shell/$(jarfile) $(DESTDIR)/$(prefix)/share/cypher-shell/lib
cp cypher-shell.1 $(DESTDIR)/$(prefix)/share/man/man1
%.1: %.1.md
pandoc -s -o $@ $<
%/integrationTest/results.bin:
$(GRADLE) integrationTest
%/test/results.bin:
$(GRADLE) check
$(artifacts):
$(GRADLE) installDist
%/reports/pitest/index.html:
$(GRADLE) pitest
tmp/.tests-pass: tmp/cypher-shell.zip tyrekicking.sh
cp tyrekicking.sh tmp/
cd tmp && bash tyrekicking.sh
touch $@
tmp/cypher-shell.zip: tmp/temp/cypher-shell/cypher-shell
cd tmp/temp && zip -r cypher-shell.zip cypher-shell
mv tmp/temp/cypher-shell.zip tmp/cypher-shell.zip
tmp/temp/cypher-shell/cypher-shell: $(artifacts)
rm -rf tmp
mkdir -p tmp/temp
cp -r cypher-shell/build/install/cypher-shell tmp/temp/cypher-shell
out/cypher-shell.zip: tmp/cypher-shell.zip
mkdir -p out
cp $< $@
out/rpm/SPECS/cypher-shell.spec: packaging/rpm/cypher-shell.spec
mkdir -p $(dir $@)
VERSION=$(versionnumber) RELEASE=$(release) envsubst '$${VERSION} $${RELEASE}' < $< > $@
out/rpm/BUILD/%: %
mkdir -p $(dir $@)
cp $< $@
out/%.rpm: out/rpm/RPMS/noarch/%.rpm
mkdir -p $(dir $@)
cp $< $@
tmp/rpm-test/%.rpm: out/rpm/RPMS/noarch/%.rpm
mkdir -p $(dir $@)
cp $< $@
tmp/rpm-test/Dockerfile: packaging/test/rpm/Dockerfile
mkdir -p $(dir $@)
RPMFILE=$(rpmfile) envsubst '$${RPMFILE}' < $< > $@
out/rpm/RPMS/noarch/$(rpmfile): out/rpm/SPECS/cypher-shell.spec $(rpm_artifacts) out/rpm/BUILD/Makefile out/rpm/BUILD/cypher-shell.1.md
rpmbuild --define "_topdir $(CURDIR)/out/rpm" -bb --clean $<
.PHONY: rpm
rpm: out/$(rpmfile) ## Build the RPM package
DOCKERUUIDRPM := $(shell uuidgen)
.PHONY: rpm-test
rpm-test: tmp/rpm-test/$(rpmfile) tmp/rpm-test/Dockerfile ## Test the RPM package (requires Docker)
cd $(dir $<) && docker build . -t $(DOCKERUUIDRPM) && docker run --rm $(DOCKERUUIDRPM) --version
out/debian/cypher-shell-$(debversion)/debian/changelog: packaging/debian/changelog
mkdir -p $(dir $@)
VERSION=$(debversion) DISTRIBUTION=$(distribution) DATE="$(shell date -R)" envsubst '$${VERSION} $${DISTRIBUTION} $${DATE}' < $< > $@
out/debian/cypher-shell-$(debversion)/debian/%: packaging/debian/%
mkdir -p $(dir $@)
cp $< $@
out/debian/cypher-shell-$(debversion)/%: %
mkdir -p $(dir $@)
cp $< $@
out/debian/$(debfile): $(deb_artifacts) $(deb_targets) out/debian/cypher-shell-$(debversion)/cypher-shell.1.md
cd out/debian/cypher-shell-$(debversion) && debuild -A -uc -us
out/%.deb: out/debian/%.deb
cp $< $@
tmp/debian-test/%.deb: out/debian/%.deb
mkdir -p $(dir $@)
cp $< $@
tmp/debian-test/Dockerfile: packaging/test/debian/Dockerfile
mkdir -p $(dir $@)
DEBFILE=$(debfile) envsubst '$${DEBFILE}' < $< > $@
.PHONY: debian
debian: out/$(debfile) ## Build the Debian package
DOCKERUUIDDEB := $(shell uuidgen)
.PHONY: debian-test
debian-test: tmp/debian-test/$(debfile) tmp/debian-test/Dockerfile ## Test the Debian package (requires Docker)
cd $(dir $<) && docker build . -t $(DOCKERUUIDRPM) && docker run --rm $(DOCKERUUIDRPM) --version