tail is not head
[ci.git] / build.py
blob9b646998ff3907ad487b796fbc026c366d723209
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.web import *
43 from hbuild.output import ConsolePrinter
45 def create_checkout_task(name, url):
46 if url.startswith("wip://"):
47 return RsyncCheckoutTask(name, url[6:])
48 else:
49 return BzrCheckoutTask(name, url)
51 # Command-line options
52 args = argparse.ArgumentParser(description='HelenOS integration build')
53 args.add_argument('--helenos-repository', default='bzr://helenos.org/mainline', dest='helenos_repository',
54 metavar='PATH',
55 help='HelenOS repository path'
57 args.add_argument('--coastline-repository', default='bzr://helenos.org/coastline', dest='coastline_repository',
58 metavar='PATH',
59 help='Coastline repository path'
61 args.add_argument('--build-id', default='0', dest='build_id',
62 metavar='ID',
63 help='Build id (typically sequence number).',
65 args.add_argument('--rss-url', default='', dest='rss_url',
66 metavar='URL_WITH_RSS',
67 help='URL of RSS for latest builds.'
69 args.add_argument('--resource-path', default=None, dest='web_resource_path',
70 metavar='RELATIVE_PATH',
71 help='Path where static web resources are stored (when specified, the resources are NOT copied).'
73 args.add_argument('--build-directory', default=os.path.abspath('tmp'), dest='build_directory',
74 metavar='DIR',
75 help='Where to build (space for temporary files).',
77 args.add_argument('--artefact-directory', default=os.path.abspath('out/'), dest='artefact_directory',
78 metavar='DIR',
79 help='Where to place downloadable files and HTML report.'
81 args.add_argument('--platforms', default='ALL', dest='platforms',
82 metavar='PLATFORM1[,PLATFORM2[,...]',
83 help='Which platforms to build (defaults to all detected ones; can be either machine specific "ia64/ski" or architecture specific "ia64/*").'
85 args.add_argument('--harbours', default='ALL', dest='harbours',
86 metavar='HARBOUR1[,HARBOUR2[,...]',
87 help='Which harbours to build (defaults to all detected ones).'
89 args.add_argument('--tests', default='ALL', dest='tests',
90 metavar='TEST1[,TEST2[,...]]',
91 help='Which tests to run (shell wildcards supported).'
93 args.add_argument('--vm-memory-size', default=256, dest='vm_memory_size',
94 type=int,
95 metavar='RAM_SIZE_IN_MB',
96 help='How much memory to give the virtual machine running the tests.'
98 args.add_argument('--archive-format', default='tar.xz', dest='archive_format',
99 choices=['tar.xz', 'tar.gz'],
100 metavar='FORMAT',
101 help='Format of the archives (tar.gz or tar.xz).'
103 args.add_argument('--jobs', default=multiprocessing.cpu_count(), dest='jobs',
104 type=int,
105 metavar='COUNT',
106 help='Number of concurrent jobs.'
108 args.add_argument('--no-colors', default=False, dest='no_colors',
109 action='store_true',
110 help='Disable colorful output'
112 args.add_argument('--debug', default=False, dest='debug',
113 action='store_true',
114 help='Print debugging messages'
117 config = args.parse_args()
118 config.artefact_directory = os.path.abspath(config.artefact_directory)
119 config.build_directory = os.path.abspath(config.build_directory)
120 config.self_path = os.path.dirname(os.path.realpath(sys.argv[0]))
122 printer = ConsolePrinter(config.no_colors)
124 if config.vm_memory_size < 8:
125 printer.print_warning("VM memory size too small, upgrading to 8MB.")
126 config.vm_memory_size = 8
128 scheduler = BuildScheduler(
129 max_workers=config.jobs,
130 build=config.build_directory,
131 artefact=config.artefact_directory,
132 build_id=config.build_id,
133 printer=printer,
134 debug=config.debug
138 # Check-out both HelenOS and coastline repositories
139 scheduler.submit("Checking-out HelenOS",
140 "helenos-checkout",
141 create_checkout_task("helenos", config.helenos_repository))
142 scheduler.submit("Checking-out Coastline",
143 "coastline-checkout",
144 create_checkout_task("coastline", config.coastline_repository))
147 # HelenOS (mainline): get list of profiles (i.e. supported architectures
148 # and platforms) and build all of them
149 scheduler.submit("Determininig available profiles",
150 "helenos-get-profiles",
151 HelenOSGetProfilesTask(config.platforms.split(',')),
152 ["helenos-checkout"])
155 scheduler.submit("Schedule HelenOS builds",
156 "helenos-build",
157 HelenOSScheduleBuildsTask(scheduler),
158 ["helenos-get-profiles"])
162 # Coastline: get list of harbours (i.e. ported software) and build all of them
163 # for all HelenOS builds
164 scheduler.submit("Determining available harbours",
165 "coastline-get-harbours",
166 CoastlineGetHarboursTask(config.harbours.split(',')),
167 ["coastline-checkout"])
169 scheduler.submit("Schedule harbour tarballs fetches",
170 "coastline-fetch",
171 CoastlineScheduleFetchesTask(scheduler),
172 ["coastline-get-harbours" ])
175 scheduler.submit("Schedule Coastline builds",
176 "coastline-build",
177 CoastlineScheduleBuildsTask(scheduler, config.archive_format),
179 # Data dependencies
180 "helenos-get-profiles", "coastline-get-harbours",
181 # Task dependencies
182 "helenos-build", "coastline-fetch"
186 extra_builds = HelenOSExtraBuildsManager(scheduler)
189 # Tests
190 scheduler.submit("Determine available test scenarios",
191 "tests-get-list",
192 GetTestListTask(config.self_path, config.tests.split(',')),
195 scheduler.submit("Schedule tests",
196 "tests-schedule",
197 ScheduleTestsTask(scheduler,
198 extra_builds,
199 config.self_path,
200 [ "--memory={}".format(config.vm_memory_size) ]
203 "tests-get-list",
204 "helenos-build",
205 "coastline-build"
210 # Wait for all builds (and everything) to complete before creating
211 # the web page with results.
212 scheduler.barrier()
214 scheduler.close_report()
216 scheduler.submit("Generate HTML report",
217 "html-report",
218 MakeHtmlReportTask(config.self_path, config.rss_url, config.web_resource_path))
221 scheduler.done()