-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.xml
472 lines (407 loc) · 22.5 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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
<?xml version="1.0" encoding="UTF-8" ?>
<project name="MyBB" default="full" basedir=".">
<!-- build settings -->
<property file="${project.basedir}/input/build.properties" />
<property name="sourceDirectory" value="${project.basedir}/input/source" />
<property name="previousSourceDirectory" value="${project.basedir}/input/previous-source" />
<property name="patchesDirectory" value="${project.basedir}/input/patches" />
<property name="packageAddendumDirectory" value="${project.basedir}/input/package-addendum" />
<property name="buildDirectory" value="${project.basedir}/build" />
<property name="gitDirectory" value="${buildDirectory}/git" />
<property name="previousSourceDirectoryInternal" value="${buildDirectory}/previous-source" />
<property name="outputDirectory" value="${project.basedir}/output" />
<!-- project settings -->
<propertyregex property="targetVersionCode" override="false" subject="${targetVersion}" pattern="[^0-9a-z]" replace="" match="$1" defaultValue="$0" />
<property name="inputFilesRepositoryBranch" override="false" value="${sourceRepositoryBranch}" />
<property name="installPackageSubdirectory" value="install" />
<property name="languageFilesPackageDirectory" value="inc/languages/english/" />
<property name="classCoreVersionRegex">public \$version = "([0-9a-zA-Z.-]+)";</property>
<property name="englishManifestVersionRegex">\$langinfo\['version'\] = "([0-9a-zA-Z.-]+)";</property>
<property name="masterThemeManifestVersionRegex"><![CDATA[<theme name="MyBB Master Style" version="([0-9a-zA-Z.-]+)">]]></property>
<property name="sourceGitRepository" value="https://github.com/mybb/mybb.git" />
<!-- output settings -->
<property name="distSetSourceSubdirectory" value="Upload" />
<property name="distSetPrefix" value="mybb_" />
<property name="updateSetPrefix" value="changed_files_" />
<property name="distChecksumsFilePrefix" value="checksums_" />
<property name="distChangedFilesFilePrefix" value="changed_files_list_" />
<property name="distRemovedFilesFilePrefix" value="removed_files_list_" />
<property name="distChangedTemplatesFilePrefix" value="changed_templates_list_" />
<property name="distPluginHooksFilePrefix" value="mybb18_plugin_hooks" />
<!-- files to exclude when copying files for distribution packages -->
<patternset id="meta_files">
<exclude name="**/.git/**"></exclude>
<exclude name="**/.github/**"></exclude>
<exclude name="**/.DS_Store"></exclude>
<exclude name="**/.DS_Store?"></exclude>
<exclude name="**/._*"></exclude>
<exclude name="**/.Spotlight-V100"></exclude>
<exclude name="**/.Trashes"></exclude>
<exclude name="**/ehthumbs.db"></exclude>
<exclude name="**/Thumbs.db"></exclude>
<exclude name=".editorconfig"></exclude>
<exclude name=".gitignore"></exclude>
<exclude name="**/.gitkeep"></exclude>
<exclude name="CODE_OF_CONDUCT.md"></exclude>
<exclude name="CONTRIBUTING.md"></exclude>
<exclude name="SECURITY.md"></exclude>
<exclude name="LICENSE"></exclude>
<exclude name="readme.md"></exclude>
<exclude name="README.md"></exclude>
</patternset>
<!-- files with varying EOL encoding -->
<selector id="varying_eol_encoding_files">
<or>
<filename name="**/.htaccess" />
<filename name="**/LICENSE" />
<filename name="**/*.css" />
<filename name="**/*.html" />
<filename name="**/*.js" />
<filename name="**/*.php" />
<filename name="**/*.txt" />
<filename name="**/*.xml" />
</or>
</selector>
<!-- files which should be writable -->
<selector id="writable_files">
<or>
<filename name="inc/settings.php" />
<filename name="inc/config.default.php" />
</or>
</selector>
<!-- directories which should be writable -->
<selector id="writable_directories">
<or>
<filename name="cache" />
<filename name="cache/themes" />
<filename name="uploads" />
<filename name="uploads/avatars" />
</or>
</selector>
<!-- internal properties -->
<property name="distSetName" value="${distSetPrefix}${targetVersionCode}" />
<property name="updateSetName" value="${updateSetPrefix}${targetVersionCode}" />
<property name="distSetDirectory" value="${buildDirectory}/${distSetName}" />
<property name="updateSetDirectory" value="${buildDirectory}/${updateSetName}" />
<property name="distChecksumsFile" value="${buildDirectory}/${distChecksumsFilePrefix}${distSetName}" />
<property name="distChangedFilesFile" value="${buildDirectory}/${distChangedFilesFilePrefix}${targetVersionCode}" />
<property name="distRemovedFilesFile" value="${buildDirectory}/${distRemovedFilesFilePrefix}${targetVersionCode}" />
<property name="distChangedTemplatesFile" value="${buildDirectory}/${distChangedTemplatesFilePrefix}${targetVersionCode}" />
<property name="distPluginHooksFile" value="${buildDirectory}/${distPluginHooksFilePrefix}.yml" />
<property name="distVersionDataFile" value="${buildDirectory}/${targetVersion}.md" />
<property name="distSetSourceDirectory" value="${distSetDirectory}/${distSetSourceSubdirectory}" />
<!-- group tasks -->
<target name="dist-set" description="Executes tasks to build the distribution package" depends="remote-data,prepare,copy-clean,hardcoded-versions,chmod,patch,normalize-eol,dist-checksums,plugin-hooks,addendum,package,package-determinism,package-checksums,version-data,output" />
<target name="full" description="Executes tasks to build both distribution and update packages" depends="remote-data,prepare,copy-clean,hardcoded-versions,chmod,patch,normalize-eol,dist-checksums,plugin-hooks,updateset,updateset-install-directory,changed-templates,addendum,package,updateset-package,package-determinism,updateset-package-determinism,package-checksums,updateset-package-checksums,version-data,output" />
<!-- build process -->
<!-- build process: output preparation -->
<target name="prepare" description="Creates an empty directory for build files">
<delete dir="${buildDirectory}" quiet="true" />
<mkdir dir="${buildDirectory}" />
</target>
<!-- build process: input preparation -->
<target name="remote-data" description="Fetches additional build files from specified repository">
<if>
<and>
<isset property="env.INPUT_FILES_REPOSITORY" />
<not>
<equals arg1="${env.INPUT_FILES_REPOSITORY}" arg2="" />
</not>
</and>
<then>
<mkdir dir="${gitDirectory}" />
<exec dir="${gitDirectory}" command="git clone ${env.INPUT_FILES_REPOSITORY} --depth=1 --branch=${inputFilesRepositoryBranch} ./" checkreturn="true" />
<copy todir="${project.basedir}" preservelastmodified="true">
<fileset dir="${gitDirectory}">
<include name="**" />
<patternset refid="meta_files" />
</fileset>
</copy>
<delete dir="${gitDirectory}" />
</then>
</if>
</target>
<target name="copy-clean" description="Copies files intended for distribution sets" depends="prepare">
<mkdir dir="${distSetDirectory}" />
<mkdir dir="${distSetSourceDirectory}" />
<mkdir dir="${previousSourceDirectoryInternal}" />
<if>
<isset property="sourceRepositoryBranch" />
<then>
<mkdir dir="${gitDirectory}" />
<property name="gitCloneCommand" value="git clone ${sourceGitRepository} --depth=1 --branch=${sourceRepositoryBranch} ./" override="true" />
<echo message="${gitCloneCommand}" />
<exec dir="${gitDirectory}" command="${gitCloneCommand}" checkreturn="true" />
<copy todir="${distSetSourceDirectory}" preservelastmodified="true">
<fileset dir="${gitDirectory}">
<include name="**" />
<patternset refid="meta_files" />
</fileset>
</copy>
<delete dir="${gitDirectory}" />
</then>
<else>
<copy todir="${distSetSourceDirectory}" preservelastmodified="true">
<fileset dir="${sourceDirectory}">
<include name="**" />
<patternset refid="meta_files" />
</fileset>
</copy>
</else>
</if>
<if>
<isset property="previousSourceRepositoryBranch" />
<then>
<mkdir dir="${gitDirectory}" />
<property name="gitCloneCommand" value="git clone ${sourceGitRepository} --depth=1 --branch=${previousSourceRepositoryBranch} ./" override="true" />
<echo message="${gitCloneCommand}" />
<exec dir="${gitDirectory}" command="${gitCloneCommand}" checkreturn="true" />
<copy todir="${previousSourceDirectoryInternal}" preservelastmodified="true">
<fileset dir="${gitDirectory}">
<include name="**" />
<patternset refid="meta_files" />
</fileset>
</copy>
<delete dir="${gitDirectory}" />
</then>
<else>
<copy todir="${previousSourceDirectoryInternal}" preservelastmodified="true">
<fileset dir="${previousSourceDirectory}">
<include name="**" />
<patternset refid="meta_files" />
</fileset>
</copy>
</else>
</if>
</target>
<!-- build process: input analysis -->
<target name="hardcoded-versions" description="Attempts to read versions hardcoded in source files">
<if>
<available file="${previousSourceDirectoryInternal}/inc/class_core.php" type="file" />
<then>
<loadfile property="previousCoreClassContent" file="${previousSourceDirectoryInternal}/inc/class_core.php" />
<propertyregex property="version" subject="${previousCoreClassContent}" pattern="${classCoreVersionRegex}" match="$1" defaultValue="Not found" override="true" />
<echo message="Version in previous inc/class_core.php: ${version}" />
</then>
</if>
<loadfile property="coreClassContent" file="${distSetSourceDirectory}/inc/class_core.php" />
<propertyregex property="version" subject="${coreClassContent}" pattern="${classCoreVersionRegex}" match="$1" defaultValue="Not found" override="true" />
<echo message="Version in inc/class_core.php: ${version}" />
<loadfile property="languageManifestContent" file="${distSetSourceDirectory}/inc/languages/english.php" />
<propertyregex property="version" subject="${languageManifestContent}" pattern="${englishManifestVersionRegex}" match="$1" defaultValue="Not found" override="true" />
<echo message="Version in inc/languages/english.php: ${version}" />
<loadfile property="themeManifestContent" file="${distSetSourceDirectory}/install/resources/mybb_theme.xml" />
<propertyregex property="version" subject="${themeManifestContent}" pattern="${masterThemeManifestVersionRegex}" match="$1" defaultValue="Not found" override="true" />
<echo message="Version in install/resources/mybb_theme.xml: ${version}" />
</target>
<!-- build process: distribution set operations -->
<target name="chmod" description="Applies file permissions to the target set" depends="copy-clean">
<chmod mode="0777" verbose="false">
<fileset dir="${distSetSourceDirectory}">
<selector refid="writable_directories" />
<type type="dir" />
</fileset>
</chmod>
<chmod mode="0666" verbose="false">
<fileset dir="${distSetSourceDirectory}">
<selector refid="writable_files" />
<type type="file" />
</fileset>
</chmod>
<chmod mode="0644" verbose="false">
<fileset dir="${distSetSourceDirectory}">
<include name="**" />
<not>
<selector refid="writable_files" />
</not>
<type type="file" />
</fileset>
</chmod>
</target>
<target name="patch" description="Applies attached git patches to the target file set" depends="copy-clean">
<if>
<available file="${patchesDirectory}" type="dir" />
<then>
<apply executable="git" dir="${distSetSourceDirectory}">
<arg value="apply" />
<arg value="--ignore-whitespace" />
<arg value="--verbose" />
<fileset dir="${patchesDirectory}">
<include name="**" />
</fileset>
</apply>
</then>
</if>
</target>
<target name="patch-reverse" description="Reverses attached git patches in the target file set" depends="copy-clean">
<apply executable="git" dir="${distSetSourceDirectory}">
<arg value="apply" />
<arg value="--reverse" />
<arg value="--ignore-whitespace" />
<fileset dir="${patchesDirectory}">
<include name="**" />
</fileset>
</apply>
</target>
<target name="normalize-eol" description="Converts line encoding in the target file set" depends="copy-clean">
<fileset dir="${distSetSourceDirectory}" id="varyingEolEncodingFiles">
<selector refid="varying_eol_encoding_files" />
<type type="file" />
</fileset>
<pathconvert pathsep="," property="varyingEolEncodingFiles" refid="varyingEolEncodingFiles" />
<exec passthru="true" command="php php/normalize-eol.php
--varyingEolEncodingFiles '${varyingEolEncodingFiles}'" />
</target>
<!-- build process: distribution set metadata -->
<target name="dist-checksums" description="Prints target file set checksums for different new line encodings" depends="copy-clean">
<delete file="${distChecksumsFile}" quiet="true" />
<fileset dir="${distSetSourceDirectory}" id="varyingEolEncodingFiles">
<selector refid="varying_eol_encoding_files" />
<type type="file" />
</fileset>
<pathconvert pathsep="," property="varyingEolEncodingFilesCsv" refid="varyingEolEncodingFiles" />
<fileset dir="${distSetSourceDirectory}" id="standardFiles">
<not>
<selector refid="varying_eol_encoding_files" />
</not>
<type type="file" />
</fileset>
<pathconvert pathsep="," property="standardFilesCsv" refid="standardFiles" />
<exec passthru="true" command="php php/dist-checksums.php
--standardFilesCsv '${standardFilesCsv}'
--varyingEolEncodingFilesCsv '${varyingEolEncodingFilesCsv}'
--distSetSourceDirectory '${distSetSourceDirectory}'
--distChecksumsFile '${distChecksumsFile}'
--algorithm 'sha512'" />
</target>
<target name="plugin-hooks" description="Generates a list of plugin hooks basing on the target file set" depends="copy-clean">
<delete file="${distPluginHooksFile}" quiet="true" />
<exec passthru="true" command="php php/plugin-hooks.php
--distSetSourceDirectory '${distSetSourceDirectory}'
--targetVersionCode '${targetVersionCode}'
--distPluginHooksFile '${distPluginHooksFile}'" />
</target>
<!-- build process: update set operations -->
<target name="updateset" description="Compares the target and previous file sets to generate the set of updated or new files" depends="copy-clean">
<delete dir="${updateSetDirectory}" quiet="true" />
<fileset dir="${distSetSourceDirectory}" id="distFiles">
<include name="**" />
<patternset refid="meta_files" />
</fileset>
<pathconvert pathsep="," property="distFilesCsv" refid="distFiles" />
<fileset dir="${previousSourceDirectoryInternal}" id="previousFiles">
<include name="**" />
<patternset refid="meta_files" />
</fileset>
<pathconvert pathsep="," property="previousFilesCsv" refid="previousFiles" />
<mkdir dir="${updateSetDirectory}" />
<exec passthru="true" command="php php/updateset.php
--distFilesCsv '${distFilesCsv}'
--previousFilesCsv '${previousFilesCsv}'
--previousSourceDirectory '${previousSourceDirectoryInternal}'
--distSetSourceDirectory '${distSetSourceDirectory}'
--outputDirectory '${updateSetDirectory}'
--distChangedFilesFile '${distChangedFilesFile}'
--distRemovedFilesFile '${distRemovedFilesFile}'" />
<copy todir="${updateSetDirectory}" preservelastmodified="true">
<filelist dir="${distSetSourceDirectory}" listfile="${distChangedFilesFile}" />
</copy>
</target>
<target name="updateset-install-directory" depends="updateset">
<if>
<istrue value="${includeInstallInUpdateSet}" />
<then>
<copy todir="${updateSetDirectory}/${installPackageSubdirectory}" preservelastmodified="true">
<fileset dir="${distSetSourceDirectory}/${installPackageSubdirectory}">
<include name="**" />
<patternset refid="meta_files" />
</fileset>
</copy>
</then>
<else>
<delete dir="${updateSetDirectory}/${installPackageSubdirectory}" />
</else>
</if>
</target>
<!-- build process: update set metadata -->
<target name="changed-templates" description="Generates a list of templates set to the target version" depends="updateset">
<delete file="${distChangedTemplatesFile}" quiet="true" />
<exec passthru="true" command="php php/changed-templates.php
--distSetSourceDirectory '${distSetSourceDirectory}'
--targetVersionCode '${targetVersionCode}'
--distChangedTemplatesFile '${distChangedTemplatesFile}'" />
</target>
<!-- build process: package operations -->
<target name="addendum" description="Copies additional files to the target file set" depends="copy-clean">
<copy todir="${distSetDirectory}" preservelastmodified="true">
<fileset dir="${packageAddendumDirectory}">
<include name="**" />
</fileset>
</copy>
</target>
<target name="package" description="Creates an archive from the target file set" depends="copy-clean">
<delete file="${buildDirectory}/${distSetName}.zip" quiet="true" />
<zip destfile="${buildDirectory}/${distSetName}.zip">
<fileset dir="${distSetDirectory}">
<include name="**" />
</fileset>
</zip>
</target>
<target name="updateset-package" description="Creates an archive from the update package set" depends="updateset">
<delete file="${buildDirectory}/${updateSetName}.zip" quiet="true" />
<zip destfile="${buildDirectory}/${updateSetName}.zip">
<fileset dir="${updateSetDirectory}">
<include name="**" />
</fileset>
</zip>
</target>
<target name="package-determinism" description="Strips non-deterministic information from the package archive" depends="package">
<php function="strtotime" returnProperty="packageDateTimestamp">
<param value="${packageDate}" />
</php>
<exec command="strip-nondeterminism --timestamp ${packageDateTimestamp} ${buildDirectory}/${distSetName}.zip" checkreturn="true" />
</target>
<target name="updateset-package-determinism" description="Strips non-deterministic information from the update set package archive" depends="updateset-package">
<php function="strtotime" returnProperty="packageDateTimestamp">
<param value="${packageDate}" />
</php>
<exec command="strip-nondeterminism --timestamp ${packageDateTimestamp} ${buildDirectory}/${updateSetName}.zip" checkreturn="true" />
</target>
<!-- build process: package metadata -->
<target name="package-checksums" description="Creates checksums of the target file set archive" depends="package">
<exec passthru="true" command="php php/file-checksums.php
--path '${buildDirectory}/${distSetName}.zip'
--algorithms 'md5,sha1,sha256,sha512'" />
</target>
<target name="updateset-package-checksums" description="Creates checksums of the update package set archive" depends="updateset-package">
<exec passthru="true" command="php php/file-checksums.php
--path '${buildDirectory}/${updateSetName}.zip'
--algorithms 'md5,sha1,sha256,sha512'" />
</target>
<target name="version-data" description="Generates a YAML data file for the target version" depends="package,package-checksums">
<delete file="${distVersionDataFile}" quiet="true" />
<exec passthru="true" command="php php/version-data.php
--buildDirectory '${buildDirectory}'
--distChangedFilesFile '${distChangedFilesFile}'
--distRemovedFilesFile '${distRemovedFilesFile}'
--distChangedTemplatesFile '${distChangedTemplatesFile}'
--updateSetDirectory '${updateSetDirectory}'
--languageFilesPackageDirectory '${languageFilesPackageDirectory}'
--distSetName '${distSetName}'
--updateSetName '${updateSetName}'
--targetVersion '${targetVersion}'
--targetVersionCode '${targetVersionCode}'
--distVersionDataFile '${distVersionDataFile}'" />
</target>
<!-- build process: output -->
<target name="output" description="Copies the build packages and metadata to the output directory">
<delete dir="${outputDirectory}" quiet="true" />
<mkdir dir="${outputDirectory}" />
<copy todir="${outputDirectory}" preservelastmodified="true">
<fileset dir="${buildDirectory}">
<include name="*" />
<type type="file" />
</fileset>
</copy>
</target>
</project>