4c8156a6ec9b998e9d30c44455656a9907f42adb
[buildbot.git] / phase1 / master.cfg
1 # -*- python -*-
2 # ex: set syntax=python:
3
4 import os
5 import re
6 import base64
7 import subprocess
8 import configparser
9
10 from dateutil.tz import tzutc
11 from datetime import datetime, timedelta
12
13 from twisted.internet import defer
14 from twisted.python import log
15
16 from buildbot import locks
17 from buildbot.data import resultspec
18 from buildbot.changes.gitpoller import GitPoller
19 from buildbot.config import BuilderConfig
20 from buildbot.plugins import reporters
21 from buildbot.plugins import schedulers
22 from buildbot.plugins import steps
23 from buildbot.plugins import util
24 from buildbot.process import properties
25 from buildbot.process import results
26 from buildbot.process.factory import BuildFactory
27 from buildbot.process.properties import Interpolate
28 from buildbot.process.properties import Property
29 from buildbot.schedulers.basic import AnyBranchScheduler
30 from buildbot.schedulers.forcesched import BaseParameter
31 from buildbot.schedulers.forcesched import ForceScheduler
32 from buildbot.schedulers.forcesched import ValidationError
33 from buildbot.steps.master import MasterShellCommand
34 from buildbot.steps.shell import SetPropertyFromCommand
35 from buildbot.steps.shell import ShellCommand
36 from buildbot.steps.source.git import Git
37 from buildbot.steps.transfer import FileDownload
38 from buildbot.steps.transfer import FileUpload
39 from buildbot.steps.transfer import StringDownload
40 from buildbot.worker import Worker
41
42
43 if not os.path.exists("twistd.pid"):
44 with open("twistd.pid", "w") as pidfile:
45 pidfile.write("{}".format(os.getpid()))
46
47 # This is a sample buildmaster config file. It must be installed as
48 # 'master.cfg' in your buildmaster's base directory.
49
50 ini = configparser.ConfigParser()
51 ini.read(os.getenv("BUILDMASTER_CONFIG", "./config.ini"))
52
53 if "general" not in ini or "phase1" not in ini:
54 raise ValueError("Fix your configuration")
55
56 inip1 = ini['phase1']
57
58 # Globals
59 work_dir = os.path.abspath(ini['general'].get("workdir", "."))
60 scripts_dir = os.path.abspath("../scripts")
61
62 repo_url = ini['repo'].get("url")
63
64 rsync_defopts = ["-v", "-4", "--timeout=120"]
65
66 #if rsync_bin_url.find("::") > 0 or rsync_bin_url.find("rsync://") == 0:
67 # rsync_bin_defopts += ["--contimeout=20"]
68
69 branches = {}
70
71 def ini_parse_branch(section):
72 b = {}
73 name = section.get("name")
74
75 if not name:
76 raise ValueError("missing 'name' in " + repr(section))
77 if name in branches:
78 raise ValueError("duplicate branch name in " + repr(section))
79
80 b["name"] = name
81 b["bin_url"] = section.get("binary_url")
82 b["bin_key"] = section.get("binary_password")
83
84 b["src_url"] = section.get("source_url")
85 b["src_key"] = section.get("source_password")
86
87 b["gpg_key"] = section.get("gpg_key")
88
89 b["usign_key"] = section.get("usign_key")
90 usign_comment = "untrusted comment: " + name.replace("-", " ").title() + " key"
91 b["usign_comment"] = section.get("usign_comment", usign_comment)
92
93 b["config_seed"] = section.get("config_seed")
94
95 b["kmod_archive"] = section.getboolean("kmod_archive", False)
96
97 branches[name] = b
98 log.msg("Configured branch: {}".format(name))
99
100 # PB port can be either a numeric port or a connection string
101 pb_port = inip1.get("port") or 9989
102
103 # This is the dictionary that the buildmaster pays attention to. We also use
104 # a shorter alias to save typing.
105 c = BuildmasterConfig = {}
106
107 ####### PROJECT IDENTITY
108
109 # the 'title' string will appear at the top of this buildbot
110 # installation's html.WebStatus home page (linked to the
111 # 'titleURL') and is embedded in the title of the waterfall HTML page.
112
113 c['title'] = ini['general'].get("title")
114 c['titleURL'] = ini['general'].get("title_url")
115
116 # the 'buildbotURL' string should point to the location where the buildbot's
117 # internal web server (usually the html.WebStatus page) is visible. This
118 # typically uses the port number set in the Waterfall 'status' entry, but
119 # with an externally-visible host name which the buildbot cannot figure out
120 # without some help.
121
122 c['buildbotURL'] = inip1.get("buildbot_url")
123
124 ####### BUILDWORKERS
125
126 # The 'workers' list defines the set of recognized buildworkers. Each element is
127 # a Worker object, specifying a unique worker name and password. The same
128 # worker name and password must be configured on the worker.
129
130 c['workers'] = []
131 NetLocks = dict()
132
133 for section in ini.sections():
134 if section.startswith("branch "):
135 ini_parse_branch(ini[section])
136
137 if section.startswith("worker "):
138 if ini.has_option(section, "name") and ini.has_option(section, "password") and \
139 (not ini.has_option(section, "phase") or ini.getint(section, "phase") == 1):
140 sl_props = { 'dl_lock':None, 'ul_lock':None }
141 name = ini.get(section, "name")
142 password = ini.get(section, "password")
143 if ini.has_option(section, "dl_lock"):
144 lockname = ini.get(section, "dl_lock")
145 sl_props['dl_lock'] = lockname
146 if lockname not in NetLocks:
147 NetLocks[lockname] = locks.MasterLock(lockname)
148 if ini.has_option(section, "ul_lock"):
149 lockname = ini.get(section, "ul_lock")
150 sl_props['ul_lock'] = lockname
151 if lockname not in NetLocks:
152 NetLocks[lockname] = locks.MasterLock(lockname)
153 c['workers'].append(Worker(name, password, max_builds = 1, properties = sl_props))
154
155 c['protocols'] = {'pb': {'port': pb_port}}
156
157 # coalesce builds
158 c['collapseRequests'] = True
159
160 # Reduce amount of backlog data
161 c['configurators'] = [util.JanitorConfigurator(
162 logHorizon=timedelta(days=3),
163 hour=6,
164 )]
165
166 @defer.inlineCallbacks
167 def getNewestCompleteTime(bldr):
168 """Returns the complete_at of the latest completed and not SKIPPED
169 build request for this builder, or None if there are no such build
170 requests. We need to filter out SKIPPED requests because we're
171 using collapseRequests=True which is unfortunately marking all
172 previous requests as complete when new buildset is created.
173
174 @returns: datetime instance or None, via Deferred
175 """
176
177 bldrid = yield bldr.getBuilderId()
178 completed = yield bldr.master.data.get(
179 ('builders', bldrid, 'buildrequests'),
180 [
181 resultspec.Filter('complete', 'eq', [True]),
182 resultspec.Filter('results', 'ne', [results.SKIPPED]),
183 ],
184 order=['-complete_at'], limit=1)
185 if not completed:
186 return
187
188 complete_at = completed[0]['complete_at']
189
190 last_build = yield bldr.master.data.get(
191 ('builds', ),
192 [
193 resultspec.Filter('builderid', 'eq', [bldrid]),
194 ],
195 order=['-started_at'], limit=1)
196
197 if last_build and last_build[0]:
198 last_complete_at = last_build[0]['complete_at']
199 if last_complete_at and (last_complete_at > complete_at):
200 return last_complete_at
201
202 return complete_at
203
204 @defer.inlineCallbacks
205 def prioritizeBuilders(master, builders):
206 """Returns sorted list of builders by their last timestamp of completed and
207 not skipped build.
208
209 @returns: list of sorted builders
210 """
211
212 def is_building(bldr):
213 return bool(bldr.building) or bool(bldr.old_building)
214
215 def bldr_info(bldr):
216 d = defer.maybeDeferred(getNewestCompleteTime, bldr)
217 d.addCallback(lambda complete_at: (complete_at, bldr))
218 return d
219
220 def bldr_sort(item):
221 (complete_at, bldr) = item
222
223 if not complete_at:
224 date = datetime.min
225 complete_at = date.replace(tzinfo=tzutc())
226
227 if is_building(bldr):
228 date = datetime.max
229 complete_at = date.replace(tzinfo=tzutc())
230
231 return (complete_at, bldr.name)
232
233 results = yield defer.gatherResults([bldr_info(bldr) for bldr in builders])
234 results.sort(key=bldr_sort)
235
236 for r in results:
237 log.msg("prioritizeBuilders: {:>20} complete_at: {}".format(r[1].name, r[0]))
238
239 return [r[1] for r in results]
240
241 c['prioritizeBuilders'] = prioritizeBuilders
242
243 ####### CHANGESOURCES
244
245 branchNames = [branches[b]["name"] for b in branches]
246
247 # find targets
248 targets = set()
249
250 def populateTargets():
251 log.msg("Populating targets, this will take time")
252 sourcegit = work_dir + '/source.git'
253 for branch in branchNames:
254 if os.path.isdir(sourcegit):
255 subprocess.call(["rm", "-rf", sourcegit])
256
257 subprocess.call(["git", "clone", "-q", "--depth=1", "--branch="+branch, repo_url, sourcegit])
258
259 os.makedirs(sourcegit + '/tmp', exist_ok=True)
260 findtargets = subprocess.Popen(['./scripts/dump-target-info.pl', 'targets'],
261 stdout = subprocess.PIPE, stderr = subprocess.DEVNULL, cwd = sourcegit)
262
263 while True:
264 line = findtargets.stdout.readline()
265 if not line:
266 break
267 ta = line.decode().strip().split(' ')
268 targets.add(ta[0])
269
270 subprocess.call(["rm", "-rf", sourcegit])
271
272 populateTargets()
273
274 # the 'change_source' setting tells the buildmaster how it should find out
275 # about source code changes. Here we point to the buildbot clone of pyflakes.
276
277 c['change_source'] = []
278 c['change_source'].append(GitPoller(
279 repo_url,
280 workdir=work_dir+'/work.git', branches=branchNames,
281 pollAtLaunch=True, pollinterval=300))
282
283 ####### SCHEDULERS
284
285 # Configure the Schedulers, which decide how to react to incoming changes. In this
286 # case, just kick off a 'basebuild' build
287
288 class TagChoiceParameter(BaseParameter):
289 spec_attributes = ["strict", "choices"]
290 type = "list"
291 strict = True
292
293 def __init__(self, name, label=None, **kw):
294 super().__init__(name, label, **kw)
295 self._choice_list = []
296
297 @property
298 def choices(self):
299 taglist = []
300 basever = re.search(r'-([0-9]+\.[0-9]+)$', "master") # XXX FIXME
301
302 if basever:
303 findtags = subprocess.Popen(
304 ['git', 'ls-remote', '--tags', repo_url],
305 stdout = subprocess.PIPE)
306
307 while True:
308 line = findtags.stdout.readline()
309
310 if not line:
311 break
312
313 tagver = re.search(r'\brefs/tags/v([0-9]+\.[0-9]+\.[0-9]+(?:-rc[0-9]+)?)$', line.decode().strip())
314
315 if tagver and tagver[1].find(basever[1]) == 0:
316 taglist.append(tagver[1])
317
318 taglist.sort(reverse=True, key=lambda tag: tag if re.search(r'-rc[0-9]+$', tag) else tag + '-z')
319 taglist.insert(0, '')
320
321 self._choice_list = taglist
322
323 return self._choice_list
324
325 def parse_from_arg(self, s):
326 if self.strict and s not in self._choice_list:
327 raise ValidationError("'%s' does not belong to list of available choices '%s'" % (s, self._choice_list))
328 return s
329
330 c['schedulers'] = []
331 c['schedulers'].append(AnyBranchScheduler(
332 name = "all",
333 change_filter = util.ChangeFilter(branch=branchNames),
334 treeStableTimer = 15*60,
335 builderNames = list(targets)))
336
337 c['schedulers'].append(ForceScheduler(
338 name = "force",
339 buttonName = "Force builds",
340 label = "Force build details",
341 builderNames = [ "00_force_build" ],
342
343 codebases = [
344 util.CodebaseParameter(
345 "",
346 label = "Repository",
347 branch = util.FixedParameter(name = "branch", default = ""),
348 revision = util.FixedParameter(name = "revision", default = ""),
349 repository = util.FixedParameter(name = "repository", default = ""),
350 project = util.FixedParameter(name = "project", default = "")
351 )
352 ],
353
354 reason = util.StringParameter(
355 name = "reason",
356 label = "Reason",
357 default = "Trigger build",
358 required = True,
359 size = 80
360 ),
361
362 properties = [
363 util.NestedParameter(
364 name="options",
365 label="Build Options",
366 layout="vertical",
367 fields=[
368 util.ChoiceStringParameter(
369 name = "target",
370 label = "Build target",
371 default = "all",
372 choices = set( "all" ) | targets
373 ),
374 TagChoiceParameter(
375 name = "tag",
376 label = "Build tag",
377 default = ""
378 )
379 ]
380 )
381 ]
382 ))
383
384 ####### BUILDERS
385
386 # The 'builders' list defines the Builders, which tell Buildbot how to perform a build:
387 # what steps, and which workers can execute them. Note that any particular build will
388 # only take place on one worker.
389
390 def IsTaggingRequested(step):
391 tag = step.getProperty("tag")
392 return tag and re.match(r"^[0-9]+\.[0-9]+\.[0-9]+(?:-rc[0-9]+)?$", tag)
393
394 def IsNoMasterBuild(step):
395 return step.getProperty("branch") != "master"
396
397 def IsUsignEnabled(step):
398 branch = step.getProperty("branch")
399 return branch and branches[branch].get("usign_key")
400
401 def IsSignEnabled(step):
402 branch = step.getProperty("branch")
403 return IsUsignEnabled(step) or branch and branches[branch].get("gpg_key")
404
405 def IsKmodArchiveEnabled(step):
406 branch = step.getProperty("branch")
407 return branch and branches[branch].get("kmod_archive")
408
409 def GetBaseVersion(branch):
410 if re.match(r"^[^-]+-[0-9]+\.[0-9]+$", branch):
411 return branch.split('-')[1]
412 else:
413 return "master"
414
415 @properties.renderer
416 def GetVersionPrefix(props):
417 branch = props.getProperty("branch")
418 basever = GetBaseVersion(branch)
419 if props.hasProperty("tag") and re.match(r"^[0-9]+\.[0-9]+\.[0-9]+(?:-rc[0-9]+)?$", props["tag"]):
420 return "%s/" % props["tag"]
421 elif basever != "master":
422 return "%s-SNAPSHOT/" % basever
423 else:
424 return ""
425
426 @util.renderer
427 def GetConfigSeed(props):
428 branch = props.getProperty("branch")
429 return branch and branches[branch].get("config_seed") or ""
430
431 @util.renderer
432 def GetRsyncParams(props, srcorbin, urlorkey):
433 # srcorbin: 'bin' or 'src'; urlorkey: 'url' or 'key'
434 branch = props.getProperty("branch")
435 opt = srcorbin + "_" + urlorkey
436 return branch and branches[branch].get(opt)
437
438 @util.renderer
439 def GetUsignKey(props):
440 branch = props.getProperty("branch")
441 return branch and branches[branch].get("usign_key")
442
443 def GetNextBuild(builder, requests):
444 for r in requests:
445 if r.properties:
446 # order tagged build first
447 if r.properties.hasProperty("tag"):
448 return r
449 # then order by branch order
450 pbranch = r.properties.getProperty("branch")
451 for name in branchNames:
452 if pbranch == name:
453 return r
454
455 r = requests[0]
456 log.msg("GetNextBuild: {:>20} id: {} bsid: {}".format(builder.name, r.id, r.bsid))
457 return r
458
459 def MakeEnv(overrides=None, tryccache=False):
460 env = {
461 'CCC': Interpolate("%(prop:cc_command:-gcc)s"),
462 'CCXX': Interpolate("%(prop:cxx_command:-g++)s"),
463 }
464 if tryccache:
465 env['CC'] = Interpolate("%(prop:builddir)s/ccache_cc.sh")
466 env['CXX'] = Interpolate("%(prop:builddir)s/ccache_cxx.sh")
467 env['CCACHE'] = Interpolate("%(prop:ccache_command:-)s")
468 else:
469 env['CC'] = env['CCC']
470 env['CXX'] = env['CCXX']
471 env['CCACHE'] = ''
472 if overrides is not None:
473 env.update(overrides)
474 return env
475
476 @properties.renderer
477 def NetLockDl(props, extralock=None):
478 lock = None
479 locks = []
480 if props.hasProperty("dl_lock"):
481 lock = NetLocks[props["dl_lock"]]
482 if lock is not None:
483 locks.append(lock.access('exclusive'))
484 if extralock is not None:
485 locks.append(extralock)
486 return locks
487
488 @properties.renderer
489 def NetLockUl(props):
490 lock = None
491 if props.hasProperty("ul_lock"):
492 lock = NetLocks[props["ul_lock"]]
493 if lock is not None:
494 return [lock.access('exclusive')]
495 else:
496 return []
497
498 @util.renderer
499 def TagPropertyValue(props):
500 if props.hasProperty("options"):
501 options = props.getProperty("options")
502 if type(options) is dict:
503 return options.get("tag")
504 return None
505
506 def IsTargetSelected(target):
507 def CheckTargetProperty(step):
508 try:
509 options = step.getProperty("options")
510 if type(options) is dict:
511 selected_target = options.get("target", "all")
512 if selected_target != "all" and selected_target != target:
513 return False
514 except KeyError:
515 pass
516
517 return True
518
519 return CheckTargetProperty
520
521 @util.renderer
522 def UsignSec2Pub(props):
523 branch = props.getProperty("branch")
524 try:
525 comment = branches[branch].get("usign_comment") or "untrusted comment: secret key"
526 seckey = branches[branch].get("usign_key")
527 seckey = base64.b64decode(seckey)
528 except:
529 return None
530
531 return "{}\n{}".format(re.sub(r"\bsecret key$", "public key", comment),
532 base64.b64encode(seckey[0:2] + seckey[32:40] + seckey[72:]))
533
534
535 c['builders'] = []
536
537 dlLock = locks.WorkerLock("worker_dl")
538
539 workerNames = [ ]
540
541 for worker in c['workers']:
542 workerNames.append(worker.workername)
543
544 force_factory = BuildFactory()
545
546 c['builders'].append(BuilderConfig(
547 name = "00_force_build",
548 workernames = workerNames,
549 factory = force_factory))
550
551 for target in targets:
552 ts = target.split('/')
553
554 factory = BuildFactory()
555
556 # setup shared work directory if required
557 factory.addStep(ShellCommand(
558 name = "sharedwd",
559 description = "Setting up shared work directory",
560 command = 'test -L "$PWD" || (mkdir -p ../shared-workdir && rm -rf "$PWD" && ln -s shared-workdir "$PWD")',
561 workdir = ".",
562 haltOnFailure = True))
563
564 # find number of cores
565 factory.addStep(SetPropertyFromCommand(
566 name = "nproc",
567 property = "nproc",
568 description = "Finding number of CPUs",
569 command = ["nproc"]))
570
571 # find gcc and g++ compilers
572 factory.addStep(FileDownload(
573 name = "dlfindbinpl",
574 mastersrc = scripts_dir + '/findbin.pl',
575 workerdest = "../findbin.pl",
576 mode = 0o755))
577
578 factory.addStep(SetPropertyFromCommand(
579 name = "gcc",
580 property = "cc_command",
581 description = "Finding gcc command",
582 command = [
583 "../findbin.pl", "gcc", "", "",
584 ],
585 haltOnFailure = True))
586
587 factory.addStep(SetPropertyFromCommand(
588 name = "g++",
589 property = "cxx_command",
590 description = "Finding g++ command",
591 command = [
592 "../findbin.pl", "g++", "", "",
593 ],
594 haltOnFailure = True))
595
596 # see if ccache is available
597 factory.addStep(SetPropertyFromCommand(
598 name = "ccache",
599 property = "ccache_command",
600 command = ["which", "ccache"],
601 description = "Testing for ccache command",
602 haltOnFailure = False,
603 flunkOnFailure = False,
604 warnOnFailure = False,
605 hideStepIf = lambda r, s: r==results.FAILURE,
606 ))
607
608 # Workaround bug when switching from a checked out tag back to a branch
609 # Ref: http://lists.infradead.org/pipermail/openwrt-devel/2019-June/017809.html
610 factory.addStep(ShellCommand(
611 name = "gitcheckout",
612 description = "Ensure that Git HEAD is sane",
613 command = Interpolate("if [ -d .git ]; then git checkout -f %(prop:branch)s && git branch --set-upstream-to origin/%(prop:branch)s || rm -fr .git; else exit 0; fi"),
614 haltOnFailure = True))
615
616 # check out the source
617 # Git() runs:
618 # if repo doesn't exist: 'git clone repourl'
619 # method 'clean' runs 'git clean -d -f', method fresh runs 'git clean -d -f x'. Only works with mode='full'
620 # 'git fetch -t repourl branch; git reset --hard revision'
621 factory.addStep(Git(
622 name = "git",
623 repourl = repo_url,
624 mode = 'full',
625 method = 'fresh',
626 locks = NetLockDl,
627 haltOnFailure = True,
628 ))
629
630 # update remote refs
631 factory.addStep(ShellCommand(
632 name = "fetchrefs",
633 description = "Fetching Git remote refs",
634 command = ["git", "fetch", "origin", Interpolate("+refs/heads/%(prop:branch)s:refs/remotes/origin/%(prop:branch)s")],
635 haltOnFailure = True
636 ))
637
638 # switch to tag
639 factory.addStep(ShellCommand(
640 name = "switchtag",
641 description = "Checking out Git tag",
642 command = ["git", "checkout", Interpolate("tags/v%(prop:tag:-)s")],
643 haltOnFailure = True,
644 doStepIf = IsTaggingRequested
645 ))
646
647 # Verify that Git HEAD points to a tag or branch
648 # Ref: http://lists.infradead.org/pipermail/openwrt-devel/2019-June/017809.html
649 factory.addStep(ShellCommand(
650 name = "gitverify",
651 description = "Ensure that Git HEAD is pointing to a branch or tag",
652 command = 'git rev-parse --abbrev-ref HEAD | grep -vxqF HEAD || git show-ref --tags --dereference 2>/dev/null | sed -ne "/^$(git rev-parse HEAD) / { s|^.*/||; s|\\^.*||; p }" | grep -qE "^v[0-9][0-9]\\."',
653 haltOnFailure = True))
654
655 factory.addStep(ShellCommand(
656 name = "rmtmp",
657 description = "Remove tmp folder",
658 command=["rm", "-rf", "tmp/"]))
659
660 # feed
661 factory.addStep(ShellCommand(
662 name = "rmfeedlinks",
663 description = "Remove feed symlinks",
664 command=["rm", "-rf", "package/feeds/"]))
665
666 factory.addStep(StringDownload(
667 name = "ccachecc",
668 s = '#!/bin/sh\nexec ${CCACHE} ${CCC} "$@"\n',
669 workerdest = "../ccache_cc.sh",
670 mode = 0o755,
671 ))
672
673 factory.addStep(StringDownload(
674 name = "ccachecxx",
675 s = '#!/bin/sh\nexec ${CCACHE} ${CCXX} "$@"\n',
676 workerdest = "../ccache_cxx.sh",
677 mode = 0o755,
678 ))
679
680 # feed
681 factory.addStep(ShellCommand(
682 name = "updatefeeds",
683 description = "Updating feeds",
684 command=["./scripts/feeds", "update"],
685 env = MakeEnv(tryccache=True),
686 haltOnFailure = True,
687 locks = NetLockDl,
688 ))
689
690 # feed
691 factory.addStep(ShellCommand(
692 name = "installfeeds",
693 description = "Installing feeds",
694 command=["./scripts/feeds", "install", "-a"],
695 env = MakeEnv(tryccache=True),
696 haltOnFailure = True
697 ))
698
699 # seed config
700 factory.addStep(StringDownload(
701 name = "dlconfigseed",
702 s = Interpolate("%(kw:seed)s\n", seed=GetConfigSeed),
703 workerdest = ".config",
704 mode = 0o644
705 ))
706
707 # configure
708 factory.addStep(ShellCommand(
709 name = "newconfig",
710 description = "Seeding .config",
711 command = Interpolate("printf 'CONFIG_TARGET_%(kw:target)s=y\\nCONFIG_TARGET_%(kw:target)s_%(kw:subtarget)s=y\\nCONFIG_SIGNED_PACKAGES=%(kw:usign:#?|y|n)s\\n' >> .config", target=ts[0], subtarget=ts[1], usign=GetUsignKey)
712 ))
713
714 factory.addStep(ShellCommand(
715 name = "delbin",
716 description = "Removing output directory",
717 command = ["rm", "-rf", "bin/"]
718 ))
719
720 factory.addStep(ShellCommand(
721 name = "defconfig",
722 description = "Populating .config",
723 command = ["make", "defconfig"],
724 env = MakeEnv()
725 ))
726
727 # check arch - exit early if does not exist - NB: some targets do not define CONFIG_TARGET_target_subtarget
728 factory.addStep(ShellCommand(
729 name = "checkarch",
730 description = "Checking architecture",
731 command = 'grep -sq CONFIG_TARGET_%s=y .config && grep -sq CONFIG_TARGET_SUBTARGET=\\"%s\\" .config' %(ts[0], ts[1]),
732 logEnviron = False,
733 want_stdout = False,
734 want_stderr = False,
735 haltOnFailure = True,
736 flunkOnFailure = False, # this is not a build FAILURE
737 ))
738
739 # find libc suffix
740 factory.addStep(SetPropertyFromCommand(
741 name = "libc",
742 property = "libc",
743 description = "Finding libc suffix",
744 command = ["sed", "-ne", '/^CONFIG_LIBC=/ { s!^CONFIG_LIBC="\\(.*\\)"!\\1!; s!^musl$!!; s!.\\+!-&!p }', ".config"]))
745
746 # install build key
747 factory.addStep(StringDownload(
748 name = "dlkeybuildpub",
749 s = Interpolate("%(kw:sec2pub)s", sec2pub=UsignSec2Pub),
750 workerdest = "key-build.pub",
751 mode = 0o600,
752 doStepIf = IsUsignEnabled,
753 ))
754
755 factory.addStep(StringDownload(
756 name = "dlkeybuild",
757 s = "# fake private key",
758 workerdest = "key-build",
759 mode = 0o600,
760 doStepIf = IsUsignEnabled,
761 ))
762
763 factory.addStep(StringDownload(
764 name = "dlkeybuilducert",
765 s = "# fake certificate",
766 workerdest = "key-build.ucert",
767 mode = 0o600,
768 doStepIf = IsUsignEnabled,
769 ))
770
771 # prepare dl
772 factory.addStep(ShellCommand(
773 name = "dldir",
774 description = "Preparing dl/",
775 command = "mkdir -p $HOME/dl && rm -rf ./dl && ln -sf $HOME/dl ./dl",
776 logEnviron = False,
777 want_stdout = False
778 ))
779
780 # prepare tar
781 factory.addStep(ShellCommand(
782 name = "dltar",
783 description = "Building and installing GNU tar",
784 command = ["make", Interpolate("-j%(prop:nproc:-1)s"), "tools/tar/compile", "V=s"],
785 env = MakeEnv(tryccache=True),
786 haltOnFailure = True
787 ))
788
789 # populate dl
790 factory.addStep(ShellCommand(
791 name = "dlrun",
792 description = "Populating dl/",
793 command = ["make", Interpolate("-j%(prop:nproc:-1)s"), "download", "V=s"],
794 env = MakeEnv(),
795 logEnviron = False,
796 locks = NetLockDl.withArgs(dlLock.access('exclusive')),
797 ))
798
799 factory.addStep(ShellCommand(
800 name = "cleanbase",
801 description = "Cleaning base-files",
802 command=["make", "package/base-files/clean", "V=s"]
803 ))
804
805 # build
806 factory.addStep(ShellCommand(
807 name = "tools",
808 description = "Building and installing tools",
809 command = ["make", Interpolate("-j%(prop:nproc:-1)s"), "tools/install", "V=s"],
810 env = MakeEnv(tryccache=True),
811 haltOnFailure = True
812 ))
813
814 factory.addStep(ShellCommand(
815 name = "toolchain",
816 description = "Building and installing toolchain",
817 command=["make", Interpolate("-j%(prop:nproc:-1)s"), "toolchain/install", "V=s"],
818 env = MakeEnv(),
819 haltOnFailure = True
820 ))
821
822 factory.addStep(ShellCommand(
823 name = "kmods",
824 description = "Building kmods",
825 command=["make", Interpolate("-j%(prop:nproc:-1)s"), "target/compile", "V=s", "IGNORE_ERRORS=n m", "BUILD_LOG=1"],
826 env = MakeEnv(),
827 haltOnFailure = True
828 ))
829
830 # find kernel version
831 factory.addStep(SetPropertyFromCommand(
832 name = "kernelversion",
833 property = "kernelversion",
834 description = "Finding the effective Kernel version",
835 command = "make --no-print-directory -C target/linux/ val.LINUX_VERSION val.LINUX_RELEASE val.LINUX_VERMAGIC | xargs printf '%s-%s-%s\\n'",
836 env = { 'TOPDIR': Interpolate("%(prop:builddir)s/build") }
837 ))
838
839 factory.addStep(ShellCommand(
840 name = "pkgclean",
841 description = "Cleaning up package build",
842 command=["make", "package/cleanup", "V=s"]
843 ))
844
845 factory.addStep(ShellCommand(
846 name = "pkgbuild",
847 description = "Building packages",
848 command=["make", Interpolate("-j%(prop:nproc:-1)s"), "package/compile", "V=s", "IGNORE_ERRORS=n m", "BUILD_LOG=1"],
849 env = MakeEnv(),
850 haltOnFailure = True
851 ))
852
853 factory.addStep(ShellCommand(
854 name = "pkginstall",
855 description = "Installing packages",
856 command=["make", Interpolate("-j%(prop:nproc:-1)s"), "package/install", "V=s"],
857 env = MakeEnv(),
858 haltOnFailure = True
859 ))
860
861 factory.addStep(ShellCommand(
862 name = "pkgindex",
863 description = "Indexing packages",
864 command=["make", Interpolate("-j%(prop:nproc:-1)s"), "package/index", "V=s", "CONFIG_SIGNED_PACKAGES="],
865 env = MakeEnv(),
866 haltOnFailure = True
867 ))
868
869 factory.addStep(ShellCommand(
870 name = "images",
871 description = "Building and installing images",
872 command=["make", Interpolate("-j%(prop:nproc:-1)s"), "target/install", "V=s"],
873 env = MakeEnv(),
874 haltOnFailure = True
875 ))
876
877 factory.addStep(ShellCommand(
878 name = "buildinfo",
879 description = "Generating config.buildinfo, version.buildinfo and feeds.buildinfo",
880 command = "make -j1 buildinfo V=s || true",
881 env = MakeEnv(),
882 haltOnFailure = True
883 ))
884
885 factory.addStep(ShellCommand(
886 name = "json_overview_image_info",
887 description = "Generate profiles.json in target folder",
888 command = "make -j1 json_overview_image_info V=s || true",
889 env = MakeEnv(),
890 haltOnFailure = True
891 ))
892
893 factory.addStep(ShellCommand(
894 name = "checksums",
895 description = "Calculating checksums",
896 command=["make", "-j1", "checksum", "V=s"],
897 env = MakeEnv(),
898 haltOnFailure = True
899 ))
900
901 factory.addStep(ShellCommand(
902 name = "kmoddir",
903 description = "Creating kmod directory",
904 command=["mkdir", "-p", Interpolate("bin/targets/%(kw:target)s/%(kw:subtarget)s%(prop:libc)s/kmods/%(prop:kernelversion)s", target=ts[0], subtarget=ts[1])],
905 haltOnFailure = True,
906 doStepIf = IsKmodArchiveEnabled,
907 ))
908
909 factory.addStep(ShellCommand(
910 name = "kmodprepare",
911 description = "Preparing kmod archive",
912 command=["rsync", "--include=/kmod-*.ipk", "--exclude=*", "-va",
913 Interpolate("bin/targets/%(kw:target)s/%(kw:subtarget)s%(prop:libc)s/packages/", target=ts[0], subtarget=ts[1]),
914 Interpolate("bin/targets/%(kw:target)s/%(kw:subtarget)s%(prop:libc)s/kmods/%(prop:kernelversion)s/", target=ts[0], subtarget=ts[1])],
915 haltOnFailure = True,
916 doStepIf = IsKmodArchiveEnabled,
917 ))
918
919 factory.addStep(ShellCommand(
920 name = "kmodindex",
921 description = "Indexing kmod archive",
922 command=["make", Interpolate("-j%(prop:nproc:-1)s"), "package/index", "V=s", "CONFIG_SIGNED_PACKAGES=",
923 Interpolate("PACKAGE_SUBDIRS=bin/targets/%(kw:target)s/%(kw:subtarget)s%(prop:libc)s/kmods/%(prop:kernelversion)s/", target=ts[0], subtarget=ts[1])],
924 env = MakeEnv(),
925 haltOnFailure = True,
926 doStepIf = IsKmodArchiveEnabled,
927 ))
928
929 # sign
930 factory.addStep(MasterShellCommand(
931 name = "signprepare",
932 description = "Preparing temporary signing directory",
933 command = ["mkdir", "-p", "%s/signing" %(work_dir)],
934 haltOnFailure = True,
935 doStepIf = IsSignEnabled,
936
937 ))
938
939 factory.addStep(ShellCommand(
940 name = "signpack",
941 description = "Packing files to sign",
942 command = Interpolate("find bin/targets/%(kw:target)s/%(kw:subtarget)s%(prop:libc)s/ bin/targets/%(kw:target)s/%(kw:subtarget)s%(prop:libc)s/kmods/ -mindepth 1 -maxdepth 2 -type f -name sha256sums -print0 -or -name Packages -print0 | xargs -0 tar -czf sign.tar.gz", target=ts[0], subtarget=ts[1]),
943 haltOnFailure = True,
944 doStepIf = IsSignEnabled,
945 ))
946
947 factory.addStep(FileUpload(
948 workersrc = "sign.tar.gz",
949 masterdest = "%s/signing/%s.%s.tar.gz" %(work_dir, ts[0], ts[1]),
950 haltOnFailure = True,
951 doStepIf = IsSignEnabled,
952 ))
953
954 factory.addStep(MasterShellCommand(
955 name = "signfiles",
956 description = "Signing files",
957 command = ["%s/signall.sh" %(scripts_dir), "%s/signing/%s.%s.tar.gz" %(work_dir, ts[0], ts[1]), Interpolate("%(prop:branch)s")],
958 env = { 'CONFIG_INI': os.getenv("BUILDMASTER_CONFIG", "./config.ini") },
959 haltOnFailure = True,
960 doStepIf = IsSignEnabled,
961 ))
962
963 factory.addStep(FileDownload(
964 name = "dlsigntargz",
965 mastersrc = "%s/signing/%s.%s.tar.gz" %(work_dir, ts[0], ts[1]),
966 workerdest = "sign.tar.gz",
967 haltOnFailure = True,
968 doStepIf = IsSignEnabled,
969 ))
970
971 factory.addStep(ShellCommand(
972 name = "signunpack",
973 description = "Unpacking signed files",
974 command = ["tar", "-xzf", "sign.tar.gz"],
975 haltOnFailure = True,
976 doStepIf = IsSignEnabled,
977 ))
978
979 # upload
980 factory.addStep(ShellCommand(
981 name = "dirprepare",
982 description = "Preparing upload directory structure",
983 command = ["mkdir", "-p", Interpolate("tmp/upload/%(kw:prefix)stargets/%(kw:target)s/%(kw:subtarget)s", target=ts[0], subtarget=ts[1], prefix=GetVersionPrefix)],
984 haltOnFailure = True
985 ))
986
987 factory.addStep(ShellCommand(
988 name = "linkprepare",
989 description = "Preparing repository symlink",
990 command = ["ln", "-s", "-f", Interpolate("../packages-%(kw:basever)s", basever=util.Transform(GetBaseVersion, Property("branch"))), Interpolate("tmp/upload/%(kw:prefix)spackages", prefix=GetVersionPrefix)],
991 doStepIf = IsNoMasterBuild,
992 haltOnFailure = True
993 ))
994
995 factory.addStep(ShellCommand(
996 name = "kmoddirprepare",
997 description = "Preparing kmod archive upload directory",
998 command = ["mkdir", "-p", Interpolate("tmp/upload/%(kw:prefix)stargets/%(kw:target)s/%(kw:subtarget)s/kmods/%(prop:kernelversion)s", target=ts[0], subtarget=ts[1], prefix=GetVersionPrefix)],
999 haltOnFailure = True,
1000 doStepIf = IsKmodArchiveEnabled,
1001 ))
1002
1003 factory.addStep(ShellCommand(
1004 name = "dirupload",
1005 description = "Uploading directory structure",
1006 command = ["rsync", "-az"] + rsync_defopts + ["tmp/upload/", Interpolate("%(kw:url)s/", url=GetRsyncParams.withArgs("bin", "url"))],
1007 env={ 'RSYNC_PASSWORD': Interpolate("%(kw:key)s", key=GetRsyncParams.withArgs("bin", "key")) },
1008 haltOnFailure = True,
1009 logEnviron = False,
1010 locks = NetLockUl,
1011 ))
1012
1013 # download remote sha256sums to 'target-sha256sums'
1014 factory.addStep(ShellCommand(
1015 name = "target-sha256sums",
1016 description = "Fetching remote sha256sums for target",
1017 command = ["rsync", "-z"] + rsync_defopts + [Interpolate("%(kw:url)s/%(kw:prefix)stargets/%(kw:target)s/%(kw:subtarget)s/sha256sums", url=GetRsyncParams.withArgs("bin", "url"), target=ts[0], subtarget=ts[1], prefix=GetVersionPrefix), "target-sha256sums"],
1018 env={ 'RSYNC_PASSWORD': Interpolate("%(kw:key)s", key=GetRsyncParams.withArgs("bin", "key")) },
1019 logEnviron = False,
1020 haltOnFailure = False,
1021 flunkOnFailure = False,
1022 warnOnFailure = False,
1023 ))
1024
1025 # build list of files to upload
1026 factory.addStep(FileDownload(
1027 name = "dlsha2rsyncpl",
1028 mastersrc = scripts_dir + '/sha2rsync.pl',
1029 workerdest = "../sha2rsync.pl",
1030 mode = 0o755,
1031 ))
1032
1033 factory.addStep(ShellCommand(
1034 name = "buildlist",
1035 description = "Building list of files to upload",
1036 command = ["../sha2rsync.pl", "target-sha256sums", Interpolate("bin/targets/%(kw:target)s/%(kw:subtarget)s%(prop:libc)s/sha256sums", target=ts[0], subtarget=ts[1]), "rsynclist"],
1037 haltOnFailure = True,
1038 ))
1039
1040 factory.addStep(FileDownload(
1041 name = "dlrsync.sh",
1042 mastersrc = scripts_dir + '/rsync.sh',
1043 workerdest = "../rsync.sh",
1044 mode = 0o755
1045 ))
1046
1047 # upload new files and update existing ones
1048 factory.addStep(ShellCommand(
1049 name = "targetupload",
1050 description = "Uploading target files",
1051 command=["../rsync.sh", "--exclude=/kmods/", "--files-from=rsynclist", "--delay-updates", "--partial-dir=.~tmp~%s~%s" %(ts[0], ts[1])] + rsync_defopts +
1052 ["-a", Interpolate("bin/targets/%(kw:target)s/%(kw:subtarget)s%(prop:libc)s/", target=ts[0], subtarget=ts[1]),
1053 Interpolate("%(kw:url)s/%(kw:prefix)stargets/%(kw:target)s/%(kw:subtarget)s/", url=GetRsyncParams.withArgs("bin", "url"), target=ts[0], subtarget=ts[1], prefix=GetVersionPrefix)],
1054 env={ 'RSYNC_PASSWORD': Interpolate("%(kw:key)s", key=GetRsyncParams.withArgs("bin", "key")) },
1055 haltOnFailure = True,
1056 logEnviron = False,
1057 ))
1058
1059 # delete files which don't exist locally
1060 factory.addStep(ShellCommand(
1061 name = "targetprune",
1062 description = "Pruning target files",
1063 command=["../rsync.sh", "--exclude=/kmods/", "--delete", "--existing", "--ignore-existing", "--delay-updates", "--partial-dir=.~tmp~%s~%s" %(ts[0], ts[1])] + rsync_defopts +
1064 ["-a", Interpolate("bin/targets/%(kw:target)s/%(kw:subtarget)s%(prop:libc)s/", target=ts[0], subtarget=ts[1]),
1065 Interpolate("%(kw:url)s/%(kw:prefix)stargets/%(kw:target)s/%(kw:subtarget)s/", url=GetRsyncParams.withArgs("bin", "url"), target=ts[0], subtarget=ts[1], prefix=GetVersionPrefix)],
1066 env={ 'RSYNC_PASSWORD': Interpolate("%(kw:key)s", key=GetRsyncParams.withArgs("bin", "key")) },
1067 haltOnFailure = True,
1068 logEnviron = False,
1069 locks = NetLockUl,
1070 ))
1071
1072 factory.addStep(ShellCommand(
1073 name = "kmodupload",
1074 description = "Uploading kmod archive",
1075 command=["../rsync.sh", "--delete", "--delay-updates", "--partial-dir=.~tmp~%s~%s" %(ts[0], ts[1])] + rsync_defopts +
1076 ["-a", Interpolate("bin/targets/%(kw:target)s/%(kw:subtarget)s%(prop:libc)s/kmods/%(prop:kernelversion)s/", target=ts[0], subtarget=ts[1]),
1077 Interpolate("%(kw:url)s/%(kw:prefix)stargets/%(kw:target)s/%(kw:subtarget)s/kmods/%(prop:kernelversion)s/", url=GetRsyncParams.withArgs("bin", "url"), target=ts[0], subtarget=ts[1], prefix=GetVersionPrefix)],
1078 env={ 'RSYNC_PASSWORD': Interpolate("%(kw:key)s", key=GetRsyncParams.withArgs("bin", "key")) },
1079 haltOnFailure = True,
1080 logEnviron = False,
1081 locks = NetLockUl,
1082 doStepIf = IsKmodArchiveEnabled,
1083 ))
1084
1085 factory.addStep(ShellCommand(
1086 name = "sourcelist",
1087 description = "Finding source archives to upload",
1088 command = "find dl/ -maxdepth 1 -type f -not -size 0 -not -name '.*' -not -name '*.hash' -not -name '*.dl' -newer .config -printf '%f\\n' > sourcelist",
1089 haltOnFailure = True
1090 ))
1091
1092 factory.addStep(ShellCommand(
1093 name = "sourceupload",
1094 description = "Uploading source archives",
1095 command=["../rsync.sh", "--files-from=sourcelist", "--size-only", "--delay-updates"] + rsync_defopts +
1096 [Interpolate("--partial-dir=.~tmp~%(kw:target)s~%(kw:subtarget)s~%(prop:workername)s", target=ts[0], subtarget=ts[1]), "-a", "dl/", Interpolate("%(kw:url)s/", url=GetRsyncParams.withArgs("src", "url"))],
1097 env={ 'RSYNC_PASSWORD': Interpolate("%(kw:key)s", key=GetRsyncParams.withArgs("src", "key")) },
1098 haltOnFailure = True,
1099 logEnviron = False,
1100 locks = NetLockUl,
1101 ))
1102
1103 factory.addStep(ShellCommand(
1104 name = "df",
1105 description = "Reporting disk usage",
1106 command=["df", "-h", "."],
1107 env={'LC_ALL': 'C'},
1108 haltOnFailure = False,
1109 flunkOnFailure = False,
1110 warnOnFailure = False,
1111 alwaysRun = True
1112 ))
1113
1114 factory.addStep(ShellCommand(
1115 name = "du",
1116 description = "Reporting estimated file space usage",
1117 command=["du", "-sh", "."],
1118 env={'LC_ALL': 'C'},
1119 haltOnFailure = False,
1120 flunkOnFailure = False,
1121 warnOnFailure = False,
1122 alwaysRun = True
1123 ))
1124
1125 factory.addStep(ShellCommand(
1126 name = "ccachestat",
1127 description = "Reporting ccache stats",
1128 command=["ccache", "-s"],
1129 env = MakeEnv(overrides={ 'PATH': ["${PATH}", "./staging_dir/host/bin"] }),
1130 want_stderr = False,
1131 haltOnFailure = False,
1132 flunkOnFailure = False,
1133 warnOnFailure = False,
1134 hideStepIf = lambda r, s: r==results.FAILURE,
1135 ))
1136
1137 c['builders'].append(BuilderConfig(name=target, workernames=workerNames, factory=factory, nextBuild=GetNextBuild))
1138
1139 c['schedulers'].append(schedulers.Triggerable(name="trigger_%s" % target, builderNames=[ target ]))
1140 force_factory.addStep(steps.Trigger(
1141 name = "trigger_%s" % target,
1142 description = "Triggering %s build" % target,
1143 schedulerNames = [ "trigger_%s" % target ],
1144 set_properties = { "reason": Property("reason"), "tag": TagPropertyValue },
1145 doStepIf = IsTargetSelected(target)
1146 ))
1147
1148
1149 ####### STATUS TARGETS
1150
1151 # 'status' is a list of Status Targets. The results of each build will be
1152 # pushed to these targets. buildbot/status/*.py has a variety to choose from,
1153 # including web pages, email senders, and IRC bots.
1154
1155 if "status_bind" in inip1:
1156 c['www'] = {
1157 'port': inip1.get("status_bind"),
1158 'plugins': {
1159 'waterfall_view': True,
1160 'console_view': True,
1161 'grid_view': True
1162 }
1163 }
1164
1165 if "status_user" in inip1 and "status_password" in inip1:
1166 c['www']['auth'] = util.UserPasswordAuth([
1167 (inip1.get("status_user"), inip1.get("status_password"))
1168 ])
1169 c['www']['authz'] = util.Authz(
1170 allowRules=[ util.AnyControlEndpointMatcher(role="admins") ],
1171 roleMatchers=[ util.RolesFromUsername(roles=["admins"], usernames=[inip1.get("status_user")]) ]
1172 )
1173
1174 c['services'] = []
1175 if ini.has_section("irc"):
1176 iniirc = ini['irc']
1177 irc_host = iniirc.get("host", None)
1178 irc_port = iniirc.getint("port", 6667)
1179 irc_chan = iniirc.get("channel", None)
1180 irc_nick = iniirc.get("nickname", None)
1181 irc_pass = iniirc.get("password", None)
1182
1183 if irc_host and irc_nick and irc_chan:
1184 irc = reporters.IRC(irc_host, irc_nick,
1185 port = irc_port,
1186 password = irc_pass,
1187 channels = [ irc_chan ],
1188 notify_events = [ 'exception', 'problem', 'recovery' ]
1189 )
1190
1191 c['services'].append(irc)
1192
1193 c['revlink'] = util.RevlinkMatch([
1194 r'https://git.openwrt.org/openwrt/(.*).git'
1195 ],
1196 r'https://git.openwrt.org/?p=openwrt/\1.git;a=commit;h=%s')
1197
1198 ####### DB URL
1199
1200 c['db'] = {
1201 # This specifies what database buildbot uses to store its state. You can leave
1202 # this at its default for all but the largest installations.
1203 'db_url' : "sqlite:///state.sqlite",
1204 }
1205
1206 c['buildbotNetUsageData'] = None