forked from BrightcoveOS/Diamond
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.xml
312 lines (263 loc) · 11.6 KB
/
build.xml
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
<project name="diamond" default="dist" basedir=".">
<description>
Build file for diamond.
</description>
<!-- load properties file -->
<property file="build.properties"/>
<!-- set global properties -->
<property name="src" location="src" />
<property name="conf" location="conf" />
<property name="dist" location="dist" />
<property name="test" location="test" />
<property name="tmp" location="tmp"/>
<property name="build" location="build"/>
<property name="stage" location="${build}/stage/${ant.project.name}-${build-version}.${build-number}"/>
<property name="examples" location="examples" />
<!-- target: set os properties -->
<target name="check-os">
<echo message="os.name: ${os.name}"/>
<echo message="os.name: ${os.version}"/>
<!-- check if platform is ubuntu -->
<condition property="is.debian" value="true">
<available file="/etc/debian_version"/>
</condition>
<!-- check if platform is redhat -->
<condition property="is.redhat" value="true">
<available file="/etc/redhat-release"/>
</condition>
<echo message="is.debian: ${is.debian}"/>
<echo message="is.readhat: ${is.redhat}"/>
</target>
<!-- target: setup diamond install dirs -->
<target name="setup-install-paths" depends="check-os,setup-debian-install-paths,setup-redhat-install-paths">
<!-- output install paths -->
<echo message="diamond-lib-dir: ${diamond-lib-dir}"/>
<echo message="diamond-conf-dir: ${diamond-conf-dir}"/>
<echo message="diamond-log-dir: ${diamond-log-dir}"/>
<echo message="diamond-data-dir: ${diamond-data-dir}"/>
</target>
<!-- target: setup diamond install dirs for debian -->
<target name="setup-debian-install-paths" if="is.debian">
<!-- setup build dir -->
<property name="build" location="build-debian"/>
<!-- get python libs dir -->
<exec executable="python" outputproperty="python-libs-dir">
<arg line="-c 'from distutils.sysconfig import get_python_lib; print get_python_lib()'"/>
</exec>
<!-- setup debian install paths -->
<property name="diamond-lib-dir" value="/usr/lib/diamond"/>
<property name="diamond-conf-dir" value="/etc/diamond"/>
<property name="diamond-log-dir" value="/var/log/diamond"/>
<property name="diamond-data-dir" value="/usr/share/diamond"/>
</target>
<!-- target: setup diamond install dirs for redhat -->
<target name="setup-redhat-install-paths" if="is.redhat">
<!-- setup build dir -->
<property name="build" location="build-redhat"/>
<!-- setup redhat install paths -->
<exec executable="rpm" outputproperty="diamond-lib-dir">
<arg line="--eval '%{_libdir}'/diamond"/>
</exec>
<exec executable="rpm" outputproperty="diamond-conf-dir">
<arg line="--eval '%{_sysconfdir}'/diamond"/>
</exec>
<exec executable="rpm" outputproperty="diamond-log-dir">
<arg line="--eval '%{_localstatedir}'/log/diamond"/>
</exec>
<exec executable="rpm" outputproperty="diamond-data-dir">
<arg line="--eval '%{_datadir}'/diamond"/>
</exec>
</target>
<!-- target: setup filters -->
<target name="setup-filters" depends="setup-install-paths">
<filterset id="diamond-filters">
<filter token="topdir" value="${build}"/>
<filter token="build-version" value="${build-version}"/>
<filter token="build-number" value="${build-number}"/>
<filter token="build-release" value="${build-release}"/>
<filter token="install-root" value="${install-root}"/>
<filter token="diamond-user" value="${diamond-user}"/>
<filter token="diamond-group" value="${diamond-group}"/>
<filter token="diamond-lib-dir" value="${diamond-lib-dir}"/>
<filter token="diamond-conf-dir" value="${diamond-conf-dir}"/>
<filter token="diamond-log-dir" value="${diamond-log-dir}"/>
<filter token="diamond-data-dir" value="${diamond-data-dir}"/>
</filterset>
</target>
<!-- target: stage sources for install -->
<target name="stage" depends="clean,setup-filters">
<!-- create build directory and structure -->
<mkdir dir="${stage}" />
<mkdir dir="${stage}/src/" />
<mkdir dir="${stage}/examples/" />
<mkdir dir="${stage}/conf/" />
<mkdir dir="${stage}/dist/" />
<mkdir dir="${stage}/test/" />
<!-- Copy the source files -->
<copy todir="${stage}/src/" verbose="true">
<fileset dir="${src}/">
<exclude name="**/*.pyc"/>
<exclude name="**/*.pyo"/>
</fileset>
</copy>
<!-- Copy the test files -->
<copy todir="${stage}/test/" verbose="true">
<fileset dir="${test}/">
<exclude name="**/*.pyc"/>
<exclude name="**/*.pyo"/>
</fileset>
</copy>
<!-- Copy the example files -->
<copy todir="${stage}/examples/" verbose="true">
<fileset dir="${examples}">
<exclude name="**/*.pyc"/>
<exclude name="**/*.pyo"/>
</fileset>
</copy>
<!-- Copy the dist files -->
<copy todir="${stage}/dist/" verbose="true" filtering="true">
<fileset dir="${dist}/">
<exclude name="**/*.pyc"/>
<exclude name="**/*.pyo"/>
</fileset>
<filterset refid="diamond-filters"/>
<globmapper from="*.in" to="*"/>
</copy>
<!-- Copy other files -->
<copy todir="${stage}/" verbose="true">
<fileset dir=".">
<include name="LICENSE"/>
<include name="README"/>
<include name="README.md"/>
</fileset>
</copy>
</target>
<target name="tar" depends="stage">
<!-- Create the tar file under the RPM build root -->
<tar destfile="${build}/${ant.project.name}-${build-version}.${build-number}.tar.gz" longfile="gnu" compression="gzip">
<tarfileset dir="${build}/stage" preserveLeadingSlashes="false" />
</tar>
</target>
<!-- target: install diamond to install-root -->
<target name="install" depends="stage">
<property name="install-root" location="/"/>
<!-- setup install-root directory structure -->
<mkdir dir="${install-root}/"/>
<mkdir dir="${install-root}${diamond-lib-dir}"/>
<mkdir dir="${install-root}${diamond-lib-dir}/collectors/"/>
<mkdir dir="${install-root}${diamond-conf-dir}"/>
<mkdir dir="${install-root}${diamond-log-dir}"/>
<mkdir dir="${install-root}${diamond-log-dir}/archive/"/>
<mkdir dir="${install-root}${diamond-data-dir}"/>
<mkdir dir="${install-root}${diamond-data-dir}/examples/"/>
<!-- run setup.py to install libs -->
<exec executable="python" dir="${stage}">
<arg line="dist/setup.py install -O1 --install-layout=deb --prefix=/usr --root ${install-root}"/>
</exec>
<!-- copy collectors -->
<copy todir="${install-root}/${diamond-lib-dir}/collectors/"
verbose="true">
<fileset dir="${stage}/src/collectors/">
<exclude name="**/*.pyc"/>
<exclude name="**/*.pyo"/>
<exclude name="snmp/*"/>
</fileset>
</copy>
<!-- copy examples -->
<copy todir="${install-root}/${diamond-data-dir}/examples/"
verbose="true">
<fileset dir="${stage}/examples/">
<exclude name="**/*.pyc"/>
<exclude name="**/*.pyo"/>
</fileset>
</copy>
<!-- copy config -->
<copy todir="${install-root}/${diamond-conf-dir}/"
file="${stage}/dist/diamond.cfg"
verbose="true">
</copy>
<!-- copy init -->
<copy tofile="${install-root}/etc/init.d/diamond"
file="${stage}/dist/diamond.init"
verbose="true">
</copy>
<chmod file="${install-root}/etc/init.d/diamond" perm="755"/>
</target>
<!-- Target: create an rpm package -->
<target name="rpm" depends="tar" if="is.redhat">
<!-- move tar file to rpm dir -->
<move file="${build}/${ant.project.name}-${build-version}.${build-number}.tar.gz" todir="${build}/SOURCES"/>
<!-- setup rpm dirs -->
<mkdir dir="${build}/BUILD" />
<mkdir dir="${build}/SPECS" />
<mkdir dir="${build}/SOURCES" />
<mkdir dir="${build}/SRPMS" />
<mkdir dir="${build}/RPMS" />
<!-- Copy the spec file replacing the spec file tokens -->
<copy file="${dist}/${ant.project.name}.spec.in"
tofile="${build}/SPECS/${ant.project.name}.spec"
verbose="true"
filtering="true">
<filterset refid="diamond-filters"/>
</copy>
<!-- Create the rpm -->
<rpm specFile="${ant.project.name}.spec"
topDir="${build}/"
cleanBuildDir="true"
failOnError="true"/>
</target>
<!-- target: create a deb package -->
<target name="deb" depends="stage" if="is.debian">
<!-- setup install root -->
<property name="install-root" location="${build}/root"/>
<echo message="install-root: ${install-root}"/>
<!-- do install target now -->
<antcall target="install"/>
<!-- make debian directory -->
<mkdir dir="${install-root}/DEBIAN"/>
<!-- Copy debian control files -->
<copy todir="${install-root}/DEBIAN/"
verbose="true">
<fileset dir="${stage}/dist/debian"/>
</copy>
<chmod file="${install-root}/DEBIAN/preinst" perm="755"/>
<chmod file="${install-root}/DEBIAN/postinst" perm="755"/>
<chmod file="${install-root}/DEBIAN/prerm" perm="755"/>
<chmod file="${install-root}/DEBIAN/postrm" perm="755"/>
<!-- Copy other files -->
<copy todir="${install-root}/${diamond-data-dir}/"
verbose="true">
<fileset dir="${stage}/">
<include name="LICENSE"/>
<include name="README"/>
<include name="README.md"/>
</fileset>
</copy>
<!-- build dpkg -->
<exec executable="dpkg-deb" dir="${install-root}">
<arg line="-D --build . ${build}/${ant.project.name}-${build-version}.${build-number}-${build-release}.deb"/>
</exec>
</target>
<!-- Target: create packege depending on os -->
<target name="package" depends="rpm,deb">
</target>
<!-- target: run diamond server -->
<target name="run" depends="clean">
<mkdir dir="${tmp}"/>
<exec executable="python">
<arg line="${src}/diamond/server.py -c conf/diamond.cfg -f -v -s"/>
</exec>
</target>
<!-- target: clean up directories -->
<target name="clean">
<delete includeemptydirs="true" failonerror="false" verbose="true">
<fileset dir="${tmp}" />
</delete>
<delete includeemptydirs="true" failonerror="false" verbose="true">
<fileset dir="${build}" />
</delete>
</target>
<target name="test">
<!-- run unit tests -->
</target>
</project>