test-in-vm: better farewell message
[ci.git] / build.py
blob490b41570a4422980f434c7c16e39cecd6783eb8
1 #!/usr/bin/env python3
4 # Copyright (c) 2017 Vojtech Horky
5 # All rights reserved.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
11 # - Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # - Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
16 # - The name of the author may not be used to endorse or promote products
17 # derived from this software without specific prior written permission.
19 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 import subprocess
32 import os
33 import time
34 import sys
35 import argparse
36 import multiprocessing
37 from hbuild.scheduler import BuildScheduler
38 from hbuild.cvs import *
39 from hbuild.builders.helenos import *
40 from hbuild.builders.coastline import *
41 from hbuild.builders.tests import *
42 from hbuild.gendoc import BrowsableSourcesViaGnuGlobalTask, DoxygenTask
43 from hbuild.checkers.sycek import SycekBuildTask, SycekCheckTask
44 from hbuild.web import *
45 from hbuild.output import ConsolePrinter
47 def create_checkout_task(name, url):
48 if url.startswith("wip://"):
49 return RsyncCheckoutTask(name, url[6:])
50 else:
51 return GitCheckoutTask(name, url)
53 # Command-line options
54 args = argparse.ArgumentParser(description='HelenOS integration build')
55 args.add_argument('--helenos-repository', default='https://github.com/HelenOS/helenos.git', dest='helenos_repository',
56 metavar='PATH',
57 help='HelenOS repository path'
59 args.add_argument('--coastline-repository', default='https://github.com/HelenOS/harbours.git', dest='coastline_repository',
60 metavar='PATH',
61 help='Coastline repository path'
63 args.add_argument('--build-id', default='0', dest='build_id',
64 metavar='ID',
65 help='Build id (typically sequence number).',
67 args.add_argument('--rss-url', default='', dest='rss_url',
68 metavar='URL_WITH_RSS',
69 help='URL of RSS for latest builds.'
71 args.add_argument('--resource-path', default=None, dest='web_resource_path',
72 metavar='RELATIVE_PATH',
73 help='Path where static web resources are stored (when specified, the resources are NOT copied).'
75 args.add_argument('--build-directory', default=os.path.abspath('tmp'), dest='build_directory',
76 metavar='DIR',
77 help='Where to build (space for temporary files).',
79 args.add_argument('--artefact-directory', default=os.path.abspath('out/'), dest='artefact_directory',
80 metavar='DIR',
81 help='Where to place downloadable files and HTML report.'
83 args.add_argument('--platforms', default='ALL', dest='platforms',
84 metavar='PLATFORM1[,PLATFORM2[,...]',
85 help='Which platforms to build (defaults to all detected ones; can be either machine specific "ia64/ski" or architecture specific "ia64/*").'
87 args.add_argument('--harbours', default='ALL', dest='harbours',
88 metavar='HARBOUR1[,HARBOUR2[,...]',
89 help='Which harbours to build (defaults to all detected ones).'
91 args.add_argument('--tests', default='ALL', dest='tests',
92 metavar='TEST1[,TEST2[,...]]',
93 help='Which tests to run (shell wildcards supported).'
95 args.add_argument('--vm-memory-size', default=256, dest='vm_memory_size',
96 type=int,
97 metavar='RAM_SIZE_IN_MB',
98 help='How much memory to give the virtual machine running the tests.'
100 args.add_argument('--inline-log-lines', default=10, dest='inline_log_lines',
101 type=int,
102 metavar='LINES',
103 help='How many lines of log to show on the web page.'
105 args.add_argument('--archive-format', default='tar.xz', dest='archive_format',
106 choices=['tar.xz', 'tar.gz'],
107 metavar='FORMAT',
108 help='Format of the archives (tar.gz or tar.xz).'
110 args.add_argument('--no-source-browser', default=True, dest='code_browser',
111 action='store_false',
112 help='Do not generate source code browser.'
114 args.add_argument('--no-style-check', default=True, dest='style_check',
115 action='store_false',
116 help='Do not check C style.'
118 args.add_argument('--no-doxygen', default=True, dest='doxygen',
119 action='store_false',
120 help='Do not run Doxygen.'
122 args.add_argument('--jobs', default=multiprocessing.cpu_count(), dest='jobs',
123 type=int,
124 metavar='COUNT',
125 help='Number of concurrent jobs.'
127 args.add_argument('--no-colors', default=False, dest='no_colors',
128 action='store_true',
129 help='Disable colorful output'
131 args.add_argument('--debug', default=False, dest='debug',
132 action='store_true',
133 help='Print debugging messages'
136 config = args.parse_args()
137 config.artefact_directory = os.path.abspath(config.artefact_directory)
138 config.build_directory = os.path.abspath(config.build_directory)
139 config.self_path = os.path.dirname(os.path.realpath(sys.argv[0]))
141 printer = ConsolePrinter(config.no_colors)
143 if config.vm_memory_size < 8:
144 printer.print_warning("VM memory size too small, upgrading to 8MB.")
145 config.vm_memory_size = 8
147 scheduler = BuildScheduler(
148 max_workers=config.jobs,
149 build=config.build_directory,
150 artefact=config.artefact_directory,
151 build_id=config.build_id,
152 printer=printer,
153 inline_log_lines=config.inline_log_lines,
154 debug=config.debug
158 # Check-out both HelenOS and coastline repositories
159 scheduler.submit("Checking-out HelenOS",
160 "helenos-checkout",
161 create_checkout_task("helenos", config.helenos_repository))
162 scheduler.submit("Checking-out Coastline",
163 "coastline-checkout",
164 create_checkout_task("coastline", config.coastline_repository))
167 # Build browsable sources
168 if config.code_browser:
169 scheduler.submit("Browsable sources",
170 "helenos-browsable-sources",
171 BrowsableSourcesViaGnuGlobalTask(),
172 ["helenos-checkout"])
174 if config.doxygen:
175 scheduler.submit("Generate Doxygen documentation",
176 "helenos-doxygen",
177 DoxygenTask(),
178 ["helenos-checkout"])
181 # C style check
182 if config.style_check:
183 scheduler.submit("Build Sycek C style checker",
184 "sycek-build",
185 SycekBuildTask(),
188 scheduler.submit("Check C style with Sycek",
189 "helenos-sycek-check",
190 SycekCheckTask(),
191 ["helenos-checkout", "sycek-build"])
194 # HelenOS (mainline): get list of profiles (i.e. supported architectures
195 # and platforms) and build all of them
196 scheduler.submit("Determininig available profiles",
197 "helenos-get-profiles",
198 HelenOSGetProfilesTask(config.platforms.split(',')),
199 ["helenos-checkout"])
202 scheduler.submit("Schedule HelenOS builds",
203 "helenos-build",
204 HelenOSScheduleBuildsTask(scheduler),
205 ["helenos-get-profiles"])
209 # Coastline: get list of harbours (i.e. ported software) and build all of them
210 # for all HelenOS builds
211 scheduler.submit("Determining available harbours",
212 "coastline-get-harbours",
213 CoastlineGetHarboursTask(config.harbours.split(',')),
214 ["coastline-checkout"])
216 scheduler.submit("Schedule harbour tarballs fetches",
217 "coastline-fetch",
218 CoastlineScheduleFetchesTask(scheduler),
219 ["coastline-get-harbours" ])
222 scheduler.submit("Schedule Coastline builds",
223 "coastline-build",
224 CoastlineScheduleBuildsTask(scheduler, config.archive_format),
226 # Data dependencies
227 "helenos-get-profiles", "coastline-get-harbours",
228 # Task dependencies
229 "helenos-build", "coastline-fetch"
233 extra_builds = HelenOSExtraBuildsManager(scheduler)
236 # Tests
237 scheduler.submit("Determine available test scenarios",
238 "tests-get-list",
239 GetTestListTask(config.self_path, config.tests.split(',')),
242 scheduler.submit("Schedule tests",
243 "tests-schedule",
244 ScheduleTestsTask(scheduler,
245 extra_builds,
246 config.self_path,
247 [ "--memory={}".format(config.vm_memory_size) ]
250 "tests-get-list",
251 "helenos-build",
252 "coastline-build"
257 # Wait for all builds (and everything) to complete before creating
258 # the web page with results.
259 scheduler.barrier()
261 scheduler.close_report()
263 scheduler.submit("Generate HTML report",
264 "html-report",
265 MakeHtmlReportTask(config.self_path, config.rss_url, config.web_resource_path))
268 scheduler.done()