forked from boostorg/release-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci_boost_release.py
executable file
·365 lines (320 loc) · 16.5 KB
/
ci_boost_release.py
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
#!/usr/bin/env python
# Copyright Rene Rivera 2016
#
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
import os.path
import time
import shutil
import site
import hashlib
from ci_boost_common import main, utils, script_common, parallel_call
class script(script_common):
'''
Main script to build/test Boost C++ Libraries continuous releases. This base
is not usable by itself, as it needs some setup for the particular CI
environment before execution.
'''
archive_tag = "-snapshot"
def __init__(self, ci_klass, **kargs):
os.environ["PATH"] += os.pathsep + os.path.join(site.getuserbase(), 'bin')
utils.log("PATH = %s"%(os.environ["PATH"]))
script_common.__init__(self, ci_klass, **kargs)
def init(self, opt, kargs):
kargs = super(script,self).init(opt,kargs)
opt.add_option( '--eol',
help='type of EOLs to check out files as for packaging (LF or CRLF)')
self.eol=os.getenv('EOL', os.getenv('RELEASE_BUILD', 'LF'))
opt.add_option( '--mode', help="mode ('build' or 'check', default 'build')" )
self.mode = os.getenv( 'MODE', 'build' )
return kargs
def start(self):
super(script,self).start()
# The basename we will use for the release archive.
self.boost_release_name = 'boost_'+self.boost_version.replace('.','_')
# Common test commands in the order they should be executed..
def command_info(self):
super(script,self).command_info()
utils.check_call('xsltproc','--version')
def command_install(self):
super(script,self).command_install()
self.command_install_rapidxml()
self.command_install_docutils()
self.command_install_docbook()
self.command_install_sphinx()
self.command_install_asciidoctor()
def command_install_rapidxml(self):
os.chdir(self.build_dir)
# We use RapidXML for some doc building tools.
if not os.path.exists(os.path.join(self.build_dir,'rapidxml.zip')):
utils.check_call("wget","-O","rapidxml.zip","http://sourceforge.net/projects/rapidxml/files/latest/download")
utils.check_call("unzip","-n","-d","rapidxml","rapidxml.zip")
def command_install_docutils(self):
os.chdir(self.build_dir)
# Need docutils for building some docs.
utils.check_call("pip","install","--user","docutils")
os.chdir(self.root_dir)
def command_install_sphinx(self):
os.chdir(self.build_dir)
# Need Sphinx for building some docs (ie boost python).
utils.make_file(os.path.join(self.build_dir,'constraints.txt'), 'Sphinx==1.5.6')
utils.check_call("pip","install","--user","Sphinx==1.5.6")
utils.check_call("pip","install","--user","sphinx-boost>0.0.2")
utils.check_call("pip","install","--user","-c", os.path.join(self.build_dir,'constraints.txt'), "git+https://github.com/rtfd/recommonmark@50be4978d7d91d0b8a69643c63450c8cd92d1212")
os.chdir(self.root_dir)
def command_install_docbook(self):
os.chdir(self.build_dir)
# Local DocBook schema and stylesheets.
if not os.path.exists(os.path.join(self.build_dir,'docbook-xml.zip')):
utils.check_call("wget","-O","docbook-xml.zip","http://www.docbook.org/xml/4.5/docbook-xml-4.5.zip")
utils.check_call("unzip","-n","-d","docbook-xml","docbook-xml.zip")
if not os.path.exists(os.path.join(self.build_dir,'docbook-xsl.zip')):
utils.check_call("wget","-O","docbook-xsl.zip","https://sourceforge.net/projects/docbook/files/docbook-xsl/1.79.1/docbook-xsl-1.79.1.zip/download")
utils.check_call("unzip","-n","-d","docbook-xsl","docbook-xsl.zip")
def command_install_asciidoctor(self):
os.chdir(self.build_dir)
utils.check_call("gem","install","asciidoctor")
utils.check_call("asciidoctor","--version")
utils.check_call("gem","install","pygments.rb")
utils.check_call("pip","install","--user","Pygments")
utils.check_call("pip","install","--user","https://github.com/bfgroup/jam_pygments/archive/master.zip")
os.chdir(self.root_dir)
def command_before_build(self):
super(script,self).command_before_build()
# Fetch the rest of the Boost submodules in the appropriate
# EOL style.
if self.eol == 'LF':
utils.check_call("git","config","--global","core.eol","lf")
utils.check_call("git","config","--global","core.autocrlf","input")
else:
utils.check_call("git","config","--global","core.eol","crlf")
utils.check_call("git","config","--global","core.autocrlf","true")
utils.check_call("git","rm","--quiet","--cache","-r",".")
utils.check_call("git","reset","--quiet","--hard","HEAD")
utils.check_call("git","submodule","--quiet","foreach","--recursive","git","rm","--quiet","--cache","-r",".")
utils.check_call("git","submodule","--quiet","foreach","--recursive","git","reset","--quiet","--hard","HEAD")
def command_build(self):
super(script,self).command_build()
# Build a packaged release. This involves building a fresh set
# of docs and selectively packging parts of the tree. We try and
# avoid creating extra files in the base tree to avoid including
# extra stuff in the archives. Which means that we reset the git
# tree state to cleanup after building.
# Set up where we will "install" built tools.
utils.makedirs(os.path.join(self.build_dir,'dist','bin'))
os.environ['PATH'] = os.path.join(self.build_dir,'dist','bin')+':'+os.environ['PATH']
os.environ['BOOST_BUILD_PATH'] = self.build_dir
# Bootstrap Boost Build engine.
os.chdir(os.path.join(self.root_dir,"tools","build"))
utils.check_call("./bootstrap.sh")
shutil.copy2("b2", os.path.join(self.build_dir,"dist","bin","b2"))
utils.check_call("git","clean","-dfqx")
# Generate include dir structure.
os.chdir(self.root_dir)
self.b2("-q","-d0","headers")
# Determine if we generate index on the docs. Which we limit as they
# horrendous amounts of time to generate.
enable_auto_index = self.ci.time_limit > 60 and self.branch == "master" and self.mode == "build"
# Build various tools:
# * Quickbook documentation tool.
# * auto-index documentation tool.
self.b2('-q','-d0','--build-dir=%s'%(self.build_dir),'--distdir=%s'%(os.path.join(self.build_dir,'dist')),
'tools/quickbook',
'tools/auto_index/build' if enable_auto_index else '')
# Clean up build byproducts.
os.chdir(os.path.join(self.root_dir,"tools","quickbook"))
utils.check_call("git","clean","-dfqx")
os.chdir(os.path.join(self.root_dir,"tools","auto_index"))
utils.check_call("git","clean","-dfqx")
# Set up build config.
utils.make_file(os.path.join(self.build_dir,'site-config.jam'),
'using quickbook : "%s" ;'%(os.path.join(self.build_dir,'dist','bin','quickbook')),
'using auto-index : "%s" ;'%(os.path.join(self.build_dir,'dist','bin','auto_index')) if enable_auto_index else '',
'using docutils ;',
'using doxygen ;',
'using boostbook : "%s" : "%s" ;'%(
os.path.join(self.build_dir,'docbook-xsl','docbook-xsl-1.79.1'),
os.path.join(self.build_dir,'docbook-xml')),
'using asciidoctor ;')
# Build the full docs, and all the submodule docs.
os.chdir(os.path.join(self.root_dir,"doc"))
if self.mode == "check":
self.b2('-q','-d0','-n',
'--build-dir=%s'%(self.build_dir),
'--distdir=%s'%(os.path.join(self.build_dir,'dist')),
'--release-build',
'auto-index=off')
return
doc_build = self.b2('-q','-d0',
'--build-dir=%s'%(self.build_dir),
'--distdir=%s'%(os.path.join(self.build_dir,'dist')),
'--release-build',
'auto-index=on' if enable_auto_index else 'auto-index=off',
'--enable-index' if enable_auto_index else '',
parallel=True)
while doc_build.is_alive():
time.sleep(3*60)
print("--- Building ---")
utils.mem_info()
doc_build.join()
# Download some generated files.
os.chdir(self.root_dir)
utils.check_call('wget', '-O', 'libs/libraries.htm', 'http://www.boost.org/doc/generate.php?page=libs/libraries.htm&version=%s'%(self.branch));
utils.check_call('wget', '-O', 'index.html', 'http://www.boost.org/doc/generate.php?page=index.html&version=%s'%(self.branch));
# Clean up some extra build files that creep in. These are
# from stuff that doesn't obey the build-dir options.
utils.rmtree(os.path.join(self.root_dir,"libs","config","checks","architecture","bin"))
utils.check_call("git","submodule","--quiet","foreach","rm","-fr","doc/bin")
# Make the real distribution tree from the base tree.
os.chdir(os.path.join(self.build_dir))
utils.check_call('wget','https://raw.githubusercontent.com/boostorg/release-tools/develop/MakeBoostDistro.py')
utils.check_call('chmod','+x','MakeBoostDistro.py')
os.chdir(os.path.dirname(self.root_dir))
utils.check_call('python',os.path.join(self.build_dir,'MakeBoostDistro.py'),
self.root_dir,self.boost_release_name)
packages = []
archive_files = []
# Create packages for LF style content.
if self.eol == 'LF':
os.chdir(os.path.dirname(self.root_dir))
os.environ['GZIP'] = "-9";
os.environ['BZIP2'] = "-9";
archive_files.append(
'%s%s.tar.gz'%(self.boost_release_name, self.archive_tag));
packages.append(parallel_call(
'tar','-zcf',
'%s%s.tar.gz'%(self.boost_release_name, self.archive_tag),
self.boost_release_name))
archive_files.append(
'%s%s.tar.bz2'%(self.boost_release_name, self.archive_tag));
packages.append(parallel_call(
'tar','-jcf',
'%s%s.tar.bz2'%(self.boost_release_name, self.archive_tag),
self.boost_release_name))
# Create packages for CRLF style content.
if self.eol == 'CRLF':
os.chdir(os.path.dirname(self.root_dir))
archive_files.append(
'%s%s.zip'%(self.boost_release_name, self.archive_tag));
packages.append(parallel_call(
'zip','-qr','-9',
'%s%s.zip'%(self.boost_release_name, self.archive_tag),
self.boost_release_name))
archive_files.append(
'%s%s.7z'%(self.boost_release_name, self.archive_tag));
with open('/dev/null') as dev_null:
utils.check_call(
'7z','a','-bd','-m0=lzma','-mx=9','-mfb=64','-md=32m','-ms=on',
'%s%s.7z'%(self.boost_release_name, self.archive_tag),
self.boost_release_name, stdout=dev_null)
for package in packages:
package.join()
# Create archive info data files.
for archive_file in archive_files:
sha256_sum = hashlib.sha256(open(archive_file).read()).hexdigest()
utils.make_file("%s.json"%(archive_file),
"{",
'"sha256":"%s",'%(sha256_sum),
'"file":"%s",'%(archive_file),
'"branch":"%s",'%(self.branch),
'"commit":"%s"'%(self.commit),
"}")
# List the results for debugging.
utils.check_call('ls','-la')
def upload_archives(self, *filenames):
if not self.sf_releases_key and not self.bintray_key:
return
curl_cfg_data = []
curl_cfg = os.path.join(self.build_dir,'curl.cfg')
if self.sf_releases_key:
curl_cfg_data += [
'data = "api_key=%s"'%(self.sf_releases_key),
]
if self.bintray_key:
curl_cfg_data += [
'user = "%s:%s"'%('boostsys',self.bintray_key),
]
utils.make_file(curl_cfg,*curl_cfg_data)
# Create version ahead of uploading to avoid invalid version errors.
if self.bintray_key:
utils.make_file(
os.path.join(self.build_dir,'bintray_release.json'),
'{ "name" : "%s", "desc" : "" }'%(self.commit))
utils.check_call('curl',
'-K',curl_cfg,
'-T',os.path.join(self.build_dir,'bintray_release.json'),
'https://api.bintray.com/packages/boostorg/%s/snapshot/versions'%(
# repo
self.branch))
# Setup before we can upload to the release services.
for filename in filenames:
if self.sf_releases_key:
pass
if self.bintray_key:
# You'd think that we would need to specify api.bintray.com/content/boostorg/*/snapshot/
# as the root path to delete the existing archive. But Bintray has an API
# (where A == asymetric), and hence nothing is intuitive.
utils.check_call('curl',
'-K',curl_cfg,
'-X','DELETE',
'https://api.bintray.com/content/boostorg/%s/%s'%(
# repo, file
self.branch,filename))
utils.check_call('curl',
'-K',curl_cfg,
'-X','DELETE',
'https://api.bintray.com/content/boostorg/%s/%s.asc'%(
# repo, file
self.branch,filename))
# The uploads to the release services happen in parallel to minimize clock time.
uploads = []
for filename in filenames:
if self.sf_releases_key:
uploads.append(parallel_call(
'sshpass','-e',
'rsync','-e','ssh',
filename,
'%[email protected]:/home/frs/project/boost/boost/snapshots/%s/'%(
os.environ['SSHUSER'], self.branch)))
if self.bintray_key:
# You'd think that we would need to specify api.bintray.com/content/boostorg/*/snapshot/
# as the root path to delete the existing archive. But Bintray has an API
# (where A == asymetric), and hence nothing is intuitive.
uploads.append(parallel_call('curl',
'-K',curl_cfg,
'-T',filename,
'https://api.bintray.com/content/boostorg/%s/snapshot/%s/%s?publish=1&override=1'%(
# repo, version, file
self.branch,self.commit,filename)))
for upload in uploads:
upload.join()
# Configuration after uploads, like setting uploaded file properties.
for filename in filenames:
if self.sf_releases_key:
pass
if self.bintray_key:
pass
def command_after_success(self):
super(script,self).command_after_success()
# Publish created packages depending on the EOL style and branch.
# We post archives to distribution services.
if self.branch not in ['master', 'develop']:
return
if self.mode == "check":
return
if self.eol == 'LF':
os.chdir(os.path.dirname(self.root_dir))
self.upload_archives(
'%s%s.tar.gz'%(self.boost_release_name, self.archive_tag),
'%s%s.tar.gz.json'%(self.boost_release_name, self.archive_tag),
'%s%s.tar.bz2'%(self.boost_release_name, self.archive_tag),
'%s%s.tar.bz2.json'%(self.boost_release_name, self.archive_tag))
if self.eol == 'CRLF':
os.chdir(os.path.dirname(self.root_dir))
self.upload_archives(
'%s%s.zip'%(self.boost_release_name, self.archive_tag),
'%s%s.zip.json'%(self.boost_release_name, self.archive_tag),
'%s%s.7z'%(self.boost_release_name, self.archive_tag),
'%s%s.7z.json'%(self.boost_release_name, self.archive_tag))
main(script)