Adapt CI for changes in https://github.com/HelenOS/harbours/pull/1 (#1)
[ci.git] / build.py
blob3f10eef576387d8d409cbec81730f966ea8a1ee0
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
43 from hbuild.web import *
44 from hbuild.output import ConsolePrinter
46 def create_checkout_task(name, url):
47 if url.startswith("wip://"):
48 return RsyncCheckoutTask(name, url[6:])
49 else:
50 return GitCheckoutTask(name, url)
52 # Command-line options
53 args = argparse.ArgumentParser(description='HelenOS integration build')
54 args.add_argument('--helenos-repository', default='https://github.com/HelenOS/helenos.git', dest='helenos_repository',
55 metavar='PATH',
56 help='HelenOS repository path'
58 args.add_argument('--coastline-repository', default='https://github.com/HelenOS/harbours.git', dest='coastline_repository',
59 metavar='PATH',
60 help='Coastline repository path'
62 args.add_argument('--build-id', default='0', dest='build_id',
63 metavar='ID',
64 help='Build id (typically sequence number).',
66 args.add_argument('--rss-url', default='', dest='rss_url',
67 metavar='URL_WITH_RSS',
68 help='URL of RSS for latest builds.'
70 args.add_argument('--resource-path', default=None, dest='web_resource_path',
71 metavar='RELATIVE_PATH',
72 help='Path where static web resources are stored (when specified, the resources are NOT copied).'
74 args.add_argument('--build-directory', default=os.path.abspath('tmp'), dest='build_directory',
75 metavar='DIR',
76 help='Where to build (space for temporary files).',
78 args.add_argument('--artefact-directory', default=os.path.abspath('out/'), dest='artefact_directory',
79 metavar='DIR',
80 help='Where to place downloadable files and HTML report.'
82 args.add_argument('--platforms', default='ALL', dest='platforms',
83 metavar='PLATFORM1[,PLATFORM2[,...]',
84 help='Which platforms to build (defaults to all detected ones; can be either machine specific "ia64/ski" or architecture specific "ia64/*").'
86 args.add_argument('--harbours', default='ALL', dest='harbours',
87 metavar='HARBOUR1[,HARBOUR2[,...]',
88 help='Which harbours to build (defaults to all detected ones).'
90 args.add_argument('--tests', default='ALL', dest='tests',
91 metavar='TEST1[,TEST2[,...]]',
92 help='Which tests to run (shell wildcards supported).'
94 args.add_argument('--vm-memory-size', default=256, dest='vm_memory_size',
95 type=int,
96 metavar='RAM_SIZE_IN_MB',
97 help='How much memory to give the virtual machine running the tests.'
99 args.add_argument('--inline-log-lines', default=10, dest='inline_log_lines',
100 type=int,
101 metavar='LINES',
102 help='How many lines of log to show on the web page.'
104 args.add_argument('--archive-format', default='tar.xz', dest='archive_format',
105 choices=['tar.xz', 'tar.gz'],
106 metavar='FORMAT',
107 help='Format of the archives (tar.gz or tar.xz).'
109 args.add_argument('--jobs', default=multiprocessing.cpu_count(), dest='jobs',
110 type=int,
111 metavar='COUNT',
112 help='Number of concurrent jobs.'
114 args.add_argument('--no-colors', default=False, dest='no_colors',
115 action='store_true',
116 help='Disable colorful output'
118 args.add_argument('--debug', default=False, dest='debug',
119 action='store_true',
120 help='Print debugging messages'
123 config = args.parse_args()
124 config.artefact_directory = os.path.abspath(config.artefact_directory)
125 config.build_directory = os.path.abspath(config.build_directory)
126 config.self_path = os.path.dirname(os.path.realpath(sys.argv[0]))
128 printer = ConsolePrinter(config.no_colors)
130 if config.vm_memory_size < 8:
131 printer.print_warning("VM memory size too small, upgrading to 8MB.")
132 config.vm_memory_size = 8
134 scheduler = BuildScheduler(
135 max_workers=config.jobs,
136 build=config.build_directory,
137 artefact=config.artefact_directory,
138 build_id=config.build_id,
139 printer=printer,
140 inline_log_lines=config.inline_log_lines,
141 debug=config.debug
145 # Check-out both HelenOS and coastline repositories
146 scheduler.submit("Checking-out HelenOS",
147 "helenos-checkout",
148 create_checkout_task("helenos", config.helenos_repository))
149 scheduler.submit("Checking-out Coastline",
150 "coastline-checkout",
151 create_checkout_task("coastline", config.coastline_repository))
154 # Build browsable sources
155 scheduler.submit("Browsable sources",
156 "helenos-browsable-sources",
157 BrowsableSourcesViaGnuGlobalTask(),
158 ["helenos-checkout"])
161 # HelenOS (mainline): get list of profiles (i.e. supported architectures
162 # and platforms) and build all of them
163 scheduler.submit("Determininig available profiles",
164 "helenos-get-profiles",
165 HelenOSGetProfilesTask(config.platforms.split(',')),
166 ["helenos-checkout"])
169 scheduler.submit("Schedule HelenOS builds",
170 "helenos-build",
171 HelenOSScheduleBuildsTask(scheduler),
172 ["helenos-get-profiles"])
176 # Coastline: get list of harbours (i.e. ported software) and build all of them
177 # for all HelenOS builds
178 scheduler.submit("Determining available harbours",
179 "coastline-get-harbours",
180 CoastlineGetHarboursTask(config.harbours.split(',')),
181 ["coastline-checkout"])
183 scheduler.submit("Schedule harbour tarballs fetches",
184 "coastline-fetch",
185 CoastlineScheduleFetchesTask(scheduler),
186 ["coastline-get-harbours" ])
189 scheduler.submit("Schedule Coastline builds",
190 "coastline-build",
191 CoastlineScheduleBuildsTask(scheduler, config.archive_format),
193 # Data dependencies
194 "helenos-get-profiles", "coastline-get-harbours",
195 # Task dependencies
196 "helenos-build", "coastline-fetch"
200 extra_builds = HelenOSExtraBuildsManager(scheduler)
203 # Tests
204 scheduler.submit("Determine available test scenarios",
205 "tests-get-list",
206 GetTestListTask(config.self_path, config.tests.split(',')),
209 scheduler.submit("Schedule tests",
210 "tests-schedule",
211 ScheduleTestsTask(scheduler,
212 extra_builds,
213 config.self_path,
214 [ "--memory={}".format(config.vm_memory_size) ]
217 "tests-get-list",
218 "helenos-build",
219 "coastline-build"
224 # Wait for all builds (and everything) to complete before creating
225 # the web page with results.
226 scheduler.barrier()
228 scheduler.close_report()
230 scheduler.submit("Generate HTML report",
231 "html-report",
232 MakeHtmlReportTask(config.self_path, config.rss_url, config.web_resource_path))
235 scheduler.done()