2 # ex: set syntax=python:
10 from dateutil.tz import tzutc
11 from datetime import datetime, timedelta
13 from twisted.internet import defer
14 from twisted.python import log
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
43 if not os.path.exists("twistd.pid"):
44 with open("twistd.pid", "w") as pidfile:
45 pidfile.write("{}".format(os.getpid()))
47 # This is a sample buildmaster config file. It must be installed as
48 # 'master.cfg' in your buildmaster's base directory.
50 ini = configparser.ConfigParser()
51 ini.read(os.getenv("BUILDMASTER_CONFIG", "./config.ini"))
53 if "general" not in ini or "phase1" not in ini:
54 raise ValueError("Fix your configuration")
59 work_dir = os.path.abspath(ini['general'].get("workdir", "."))
60 scripts_dir = os.path.abspath("../scripts")
62 repo_url = ini['repo'].get("url")
64 rsync_defopts = ["-v", "-4", "--timeout=120"]
66 #if rsync_bin_url.find("::") > 0 or rsync_bin_url.find("rsync://") == 0:
67 # rsync_bin_defopts += ["--contimeout=20"]
71 def ini_parse_branch(section):
73 name = section.get("name")
76 raise ValueError("missing 'name' in " + repr(section))
78 raise ValueError("duplicate branch name in " + repr(section))
81 b["bin_url"] = section.get("binary_url")
82 b["bin_key"] = section.get("binary_password")
84 b["src_url"] = section.get("source_url")
85 b["src_key"] = section.get("source_password")
87 b["gpg_key"] = section.get("gpg_key")
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)
93 b["config_seed"] = section.get("config_seed")
95 b["kmod_archive"] = section.getboolean("kmod_archive", False)
98 log.msg("Configured branch: {}".format(name))
100 # PB port can be either a numeric port or a connection string
101 pb_port = inip1.get("port") or 9989
103 # This is the dictionary that the buildmaster pays attention to. We also use
104 # a shorter alias to save typing.
105 c = BuildmasterConfig = {}
107 ####### PROJECT IDENTITY
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.
113 c['title'] = ini['general'].get("title")
114 c['titleURL'] = ini['general'].get("title_url")
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
122 c['buildbotURL'] = inip1.get("buildbot_url")
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.
133 for section in ini.sections():
134 if section.startswith("branch "):
135 ini_parse_branch(ini[section])
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))
155 c['protocols'] = {'pb': {'port': pb_port}}
158 c['collapseRequests'] = True
160 # Reduce amount of backlog data
161 c['configurators'] = [util.JanitorConfigurator(
162 logHorizon=timedelta(days=3),
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.
174 @returns: datetime instance or None, via Deferred
177 bldrid = yield bldr.getBuilderId()
178 completed = yield bldr.master.data.get(
179 ('builders', bldrid, 'buildrequests'),
181 resultspec.Filter('complete', 'eq', [True]),
182 resultspec.Filter('results', 'ne', [results.SKIPPED]),
184 order=['-complete_at'], limit=1)
188 complete_at = completed[0]['complete_at']
190 last_build = yield bldr.master.data.get(
193 resultspec.Filter('builderid', 'eq', [bldrid]),
195 order=['-started_at'], limit=1)
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
204 @defer.inlineCallbacks
205 def prioritizeBuilders(master, builders):
206 """Returns sorted list of builders by their last timestamp of completed and
209 @returns: list of sorted builders
212 def is_building(bldr):
213 return bool(bldr.building) or bool(bldr.old_building)
216 d = defer.maybeDeferred(getNewestCompleteTime, bldr)
217 d.addCallback(lambda complete_at: (complete_at, bldr))
221 (complete_at, bldr) = item
225 complete_at = date.replace(tzinfo=tzutc())
227 if is_building(bldr):
229 complete_at = date.replace(tzinfo=tzutc())
231 return (complete_at, bldr.name)
233 results = yield defer.gatherResults([bldr_info(bldr) for bldr in builders])
234 results.sort(key=bldr_sort)
237 log.msg("prioritizeBuilders: {:>20} complete_at: {}".format(r[1].name, r[0]))
239 return [r[1] for r in results]
241 c['prioritizeBuilders'] = prioritizeBuilders
243 ####### CHANGESOURCES
245 branchNames = [branches[b]["name"] for b in branches]
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])
257 subprocess.call(["git", "clone", "--depth=1", "--branch="+branch, repo_url, sourcegit])
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)
264 line = findtargets.stdout.readline()
267 ta = line.decode().strip().split(' ')
270 subprocess.call(["rm", "-rf", sourcegit])
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.
277 c['change_source'] = []
278 c['change_source'].append(GitPoller(
280 workdir=work_dir+'/work.git', branches=branchNames,
281 pollAtLaunch=True, pollinterval=300))
285 # Configure the Schedulers, which decide how to react to incoming changes. In this
286 # case, just kick off a 'basebuild' build
288 class TagChoiceParameter(BaseParameter):
289 spec_attributes = ["strict", "choices"]
293 def __init__(self, name, label=None, **kw):
294 super().__init__(name, label, **kw)
295 self._choice_list = []
300 basever = re.search(r'-([0-9]+\.[0-9]+)$', "master") # XXX FIXME
303 findtags = subprocess.Popen(
304 ['git', 'ls-remote', '--tags', repo_url],
305 stdout = subprocess.PIPE)
308 line = findtags.stdout.readline()
313 tagver = re.search(r'\brefs/tags/v([0-9]+\.[0-9]+\.[0-9]+(?:-rc[0-9]+)?)$', line.decode().strip())
315 if tagver and tagver[1].find(basever[1]) == 0:
316 taglist.append(tagver[1])
318 taglist.sort(reverse=True, key=lambda tag: tag if re.search(r'-rc[0-9]+$', tag) else tag + '-z')
319 taglist.insert(0, '')
321 self._choice_list = taglist
323 return self._choice_list
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))
331 c['schedulers'].append(AnyBranchScheduler(
333 change_filter = util.ChangeFilter(branch=branchNames),
334 treeStableTimer = 15*60,
335 builderNames = list(targets)))
337 c['schedulers'].append(ForceScheduler(
339 buttonName = "Force builds",
340 label = "Force build details",
341 builderNames = [ "00_force_build" ],
344 util.CodebaseParameter(
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 = "")
354 reason = util.StringParameter(
357 default = "Trigger build",
363 util.NestedParameter(
365 label="Build Options",
368 util.ChoiceStringParameter(
370 label = "Build target",
372 choices = set( "all" ) | targets
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.
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)
394 def IsNoMasterBuild(step):
395 return step.getProperty("branch") != "master"
397 def IsUsignEnabled(step):
398 branch = step.getProperty("branch")
399 return branch and branches[branch].get("usign_key")
401 def IsSignEnabled(step):
402 branch = step.getProperty("branch")
403 return IsUsignEnabled(step) or branch and branches[branch].get("gpg_key")
405 def IsKmodArchiveEnabled(step):
406 branch = step.getProperty("branch")
407 return branch and branches[branch].get("kmod_archive")
409 def GetBaseVersion(branch):
410 if re.match(r"^[^-]+-[0-9]+\.[0-9]+$", branch):
411 return branch.split('-')[1]
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
427 def GetConfigSeed(props):
428 branch = props.getProperty("branch")
429 return branch and branches[branch].get("config_seed") or ""
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)
439 def GetUsignKey(props):
440 branch = props.getProperty("branch")
441 return branch and branches[branch].get("usign_key")
443 def GetNextBuild(builder, requests):
446 # order tagged build first
447 if r.properties.hasProperty("tag"):
449 # then order by branch order
450 pbranch = r.properties.getProperty("branch")
451 for name in branchNames:
456 log.msg("GetNextBuild: {:>20} id: {} bsid: {}".format(builder.name, r.id, r.bsid))
459 def MakeEnv(overrides=None, tryccache=False):
461 'CCC': Interpolate("%(prop:cc_command:-gcc)s"),
462 'CCXX': Interpolate("%(prop:cxx_command:-g++)s"),
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")
469 env['CC'] = env['CCC']
470 env['CXX'] = env['CCXX']
472 if overrides is not None:
473 env.update(overrides)
477 def NetLockDl(props):
479 if props.hasProperty("dl_lock"):
480 lock = NetLocks[props["dl_lock"]]
482 return [lock.access('exclusive')]
487 def NetLockUl(props):
489 if props.hasProperty("ul_lock"):
490 lock = NetLocks[props["ul_lock"]]
492 return [lock.access('exclusive')]
497 def TagPropertyValue(props):
498 if props.hasProperty("options"):
499 options = props.getProperty("options")
500 if type(options) is dict:
501 return options.get("tag")
504 def IsTargetSelected(target):
505 def CheckTargetProperty(step):
507 options = step.getProperty("options")
508 if type(options) is dict:
509 selected_target = options.get("target", "all")
510 if selected_target != "all" and selected_target != target:
517 return CheckTargetProperty
520 def UsignSec2Pub(props):
521 branch = props.getProperty("branch")
523 comment = branches[branch].get("usign_comment") or "untrusted comment: secret key"
524 seckey = branches[branch].get("usign_key")
525 seckey = base64.b64decode(seckey)
529 return "{}\n{}".format(re.sub(r"\bsecret key$", "public key", comment),
530 base64.b64encode(seckey[0:2] + seckey[32:40] + seckey[72:]))
535 dlLock = locks.WorkerLock("worker_dl")
539 for worker in c['workers']:
540 workerNames.append(worker.workername)
542 force_factory = BuildFactory()
544 c['builders'].append(BuilderConfig(
545 name = "00_force_build",
546 workernames = workerNames,
547 factory = force_factory))
549 for target in targets:
550 ts = target.split('/')
552 factory = BuildFactory()
554 # setup shared work directory if required
555 factory.addStep(ShellCommand(
557 description = "Setting up shared work directory",
558 command = 'test -L "$PWD" || (mkdir -p ../shared-workdir && rm -rf "$PWD" && ln -s shared-workdir "$PWD")',
560 haltOnFailure = True))
562 # find number of cores
563 factory.addStep(SetPropertyFromCommand(
566 description = "Finding number of CPUs",
567 command = ["nproc"]))
569 # find gcc and g++ compilers
570 factory.addStep(FileDownload(
571 name = "dlfindbinpl",
572 mastersrc = scripts_dir + '/findbin.pl',
573 workerdest = "../findbin.pl",
576 factory.addStep(SetPropertyFromCommand(
578 property = "cc_command",
579 description = "Finding gcc command",
581 "../findbin.pl", "gcc", "", "",
583 haltOnFailure = True))
585 factory.addStep(SetPropertyFromCommand(
587 property = "cxx_command",
588 description = "Finding g++ command",
590 "../findbin.pl", "g++", "", "",
592 haltOnFailure = True))
594 # see if ccache is available
595 factory.addStep(SetPropertyFromCommand(
596 property = "ccache_command",
597 command = ["which", "ccache"],
598 description = "Testing for ccache command",
599 haltOnFailure = False,
600 flunkOnFailure = False,
601 warnOnFailure = False,
604 # Workaround bug when switching from a checked out tag back to a branch
605 # Ref: http://lists.infradead.org/pipermail/openwrt-devel/2019-June/017809.html
606 factory.addStep(ShellCommand(
607 name = "gitcheckout",
608 description = "Ensure that Git HEAD is sane",
609 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"),
610 haltOnFailure = True))
612 # check out the source
614 # if repo doesn't exist: 'git clone repourl'
615 # method 'clean' runs 'git clean -d -f', method fresh runs 'git clean -d -f x'. Only works with mode='full'
616 # 'git fetch -t repourl branch; git reset --hard revision'
623 haltOnFailure = True,
627 factory.addStep(ShellCommand(
629 description = "Fetching Git remote refs",
630 command = ["git", "fetch", "origin", Interpolate("+refs/heads/%(prop:branch)s:refs/remotes/origin/%(prop:branch)s")],
635 factory.addStep(ShellCommand(
637 description = "Checking out Git tag",
638 command = ["git", "checkout", Interpolate("tags/v%(prop:tag:-)s")],
639 haltOnFailure = True,
640 doStepIf = IsTaggingRequested
643 # Verify that Git HEAD points to a tag or branch
644 # Ref: http://lists.infradead.org/pipermail/openwrt-devel/2019-June/017809.html
645 factory.addStep(ShellCommand(
647 description = "Ensure that Git HEAD is pointing to a branch or tag",
648 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]\\."',
649 haltOnFailure = True))
651 factory.addStep(ShellCommand(
653 description = "Remove tmp folder",
654 command=["rm", "-rf", "tmp/"]))
657 factory.addStep(ShellCommand(
658 name = "rmfeedlinks",
659 description = "Remove feed symlinks",
660 command=["rm", "-rf", "package/feeds/"]))
662 factory.addStep(StringDownload(
664 s = '#!/bin/sh\nexec ${CCACHE} ${CCC} "$@"\n',
665 workerdest = "../ccache_cc.sh",
669 factory.addStep(StringDownload(
671 s = '#!/bin/sh\nexec ${CCACHE} ${CCXX} "$@"\n',
672 workerdest = "../ccache_cxx.sh",
677 factory.addStep(ShellCommand(
678 name = "updatefeeds",
679 description = "Updating feeds",
680 command=["./scripts/feeds", "update"],
681 env = MakeEnv(tryccache=True),
682 haltOnFailure = True,
687 factory.addStep(ShellCommand(
688 name = "installfeeds",
689 description = "Installing feeds",
690 command=["./scripts/feeds", "install", "-a"],
691 env = MakeEnv(tryccache=True),
696 factory.addStep(StringDownload(
697 name = "dlconfigseed",
698 s = Interpolate("%(kw:seed)s\n", seed=GetConfigSeed),
699 workerdest = ".config",
704 factory.addStep(ShellCommand(
706 description = "Seeding .config",
707 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)
710 factory.addStep(ShellCommand(
712 description = "Removing output directory",
713 command = ["rm", "-rf", "bin/"]
716 factory.addStep(ShellCommand(
718 description = "Populating .config",
719 command = ["make", "defconfig"],
723 # check arch - exit early if does not exist - NB: some targets do not define CONFIG_TARGET_target_subtarget
724 factory.addStep(ShellCommand(
726 description = "Checking architecture",
727 command = 'grep -sq CONFIG_TARGET_%s=y .config && grep -sq CONFIG_TARGET_SUBTARGET=\\"%s\\" .config' %(ts[0], ts[1]),
731 haltOnFailure = True,
732 flunkOnFailure = False, # this is not a build FAILURE
736 factory.addStep(SetPropertyFromCommand(
739 description = "Finding libc suffix",
740 command = ["sed", "-ne", '/^CONFIG_LIBC=/ { s!^CONFIG_LIBC="\\(.*\\)"!\\1!; s!^musl$!!; s!.\\+!-&!p }', ".config"]))
743 factory.addStep(StringDownload(
744 name = "dlkeybuildpub",
745 s = Interpolate("%(kw:sec2pub)s", sec2pub=UsignSec2Pub),
746 workerdest = "key-build.pub",
748 doStepIf = IsUsignEnabled,
751 factory.addStep(StringDownload(
753 s = "# fake private key",
754 workerdest = "key-build",
756 doStepIf = IsUsignEnabled,
759 factory.addStep(StringDownload(
760 name = "dlkeybuilducert",
761 s = "# fake certificate",
762 workerdest = "key-build.ucert",
764 doStepIf = IsUsignEnabled,
768 factory.addStep(ShellCommand(
770 description = "Preparing dl/",
771 command = "mkdir -p $HOME/dl && rm -rf ./dl && ln -sf $HOME/dl ./dl",
777 factory.addStep(ShellCommand(
779 description = "Building and installing GNU tar",
780 command = ["make", Interpolate("-j%(prop:nproc:-1)s"), "tools/tar/compile", "V=s"],
781 env = MakeEnv(tryccache=True),
786 factory.addStep(ShellCommand(
788 description = "Populating dl/",
789 command = ["make", Interpolate("-j%(prop:nproc:-1)s"), "download", "V=s"],
792 locks = properties.FlattenList(NetLockDl, [dlLock.access('exclusive')]),
795 factory.addStep(ShellCommand(
797 description = "Cleaning base-files",
798 command=["make", "package/base-files/clean", "V=s"]
802 factory.addStep(ShellCommand(
804 description = "Building and installing tools",
805 command = ["make", Interpolate("-j%(prop:nproc:-1)s"), "tools/install", "V=s"],
806 env = MakeEnv(tryccache=True),
810 factory.addStep(ShellCommand(
812 description = "Building and installing toolchain",
813 command=["make", Interpolate("-j%(prop:nproc:-1)s"), "toolchain/install", "V=s"],
818 factory.addStep(ShellCommand(
820 description = "Building kmods",
821 command=["make", Interpolate("-j%(prop:nproc:-1)s"), "target/compile", "V=s", "IGNORE_ERRORS=n m", "BUILD_LOG=1"],
826 # find kernel version
827 factory.addStep(SetPropertyFromCommand(
828 name = "kernelversion",
829 property = "kernelversion",
830 description = "Finding the effective Kernel version",
831 command = "make --no-print-directory -C target/linux/ val.LINUX_VERSION val.LINUX_RELEASE val.LINUX_VERMAGIC | xargs printf '%s-%s-%s\\n'",
832 env = { 'TOPDIR': Interpolate("%(prop:builddir)s/build") }
835 factory.addStep(ShellCommand(
837 description = "Cleaning up package build",
838 command=["make", "package/cleanup", "V=s"]
841 factory.addStep(ShellCommand(
843 description = "Building packages",
844 command=["make", Interpolate("-j%(prop:nproc:-1)s"), "package/compile", "V=s", "IGNORE_ERRORS=n m", "BUILD_LOG=1"],
849 factory.addStep(ShellCommand(
851 description = "Installing packages",
852 command=["make", Interpolate("-j%(prop:nproc:-1)s"), "package/install", "V=s"],
857 factory.addStep(ShellCommand(
859 description = "Indexing packages",
860 command=["make", Interpolate("-j%(prop:nproc:-1)s"), "package/index", "V=s", "CONFIG_SIGNED_PACKAGES="],
865 factory.addStep(ShellCommand(
867 description = "Building and installing images",
868 command=["make", Interpolate("-j%(prop:nproc:-1)s"), "target/install", "V=s"],
873 factory.addStep(ShellCommand(
875 description = "Generating config.buildinfo, version.buildinfo and feeds.buildinfo",
876 command = "make -j1 buildinfo V=s || true",
881 factory.addStep(ShellCommand(
882 name = "json_overview_image_info",
883 description = "Generate profiles.json in target folder",
884 command = "make -j1 json_overview_image_info V=s || true",
889 factory.addStep(ShellCommand(
891 description = "Calculating checksums",
892 command=["make", "-j1", "checksum", "V=s"],
897 factory.addStep(ShellCommand(
899 description = "Creating kmod directory",
900 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])],
901 haltOnFailure = True,
902 doStepIf = IsKmodArchiveEnabled,
905 factory.addStep(ShellCommand(
906 name = "kmodprepare",
907 description = "Preparing kmod archive",
908 command=["rsync", "--include=/kmod-*.ipk", "--exclude=*", "-va",
909 Interpolate("bin/targets/%(kw:target)s/%(kw:subtarget)s%(prop:libc)s/packages/", target=ts[0], subtarget=ts[1]),
910 Interpolate("bin/targets/%(kw:target)s/%(kw:subtarget)s%(prop:libc)s/kmods/%(prop:kernelversion)s/", target=ts[0], subtarget=ts[1])],
911 haltOnFailure = True,
912 doStepIf = IsKmodArchiveEnabled,
915 factory.addStep(ShellCommand(
917 description = "Indexing kmod archive",
918 command=["make", Interpolate("-j%(prop:nproc:-1)s"), "package/index", "V=s", "CONFIG_SIGNED_PACKAGES=",
919 Interpolate("PACKAGE_SUBDIRS=bin/targets/%(kw:target)s/%(kw:subtarget)s%(prop:libc)s/kmods/%(prop:kernelversion)s/", target=ts[0], subtarget=ts[1])],
921 haltOnFailure = True,
922 doStepIf = IsKmodArchiveEnabled,
926 factory.addStep(MasterShellCommand(
927 name = "signprepare",
928 description = "Preparing temporary signing directory",
929 command = ["mkdir", "-p", "%s/signing" %(work_dir)],
930 haltOnFailure = True,
931 doStepIf = IsSignEnabled,
935 factory.addStep(ShellCommand(
937 description = "Packing files to sign",
938 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]),
939 haltOnFailure = True,
940 doStepIf = IsSignEnabled,
943 factory.addStep(FileUpload(
944 workersrc = "sign.tar.gz",
945 masterdest = "%s/signing/%s.%s.tar.gz" %(work_dir, ts[0], ts[1]),
946 haltOnFailure = True,
947 doStepIf = IsSignEnabled,
950 factory.addStep(MasterShellCommand(
952 description = "Signing files",
953 command = ["%s/signall.sh" %(scripts_dir), "%s/signing/%s.%s.tar.gz" %(work_dir, ts[0], ts[1]), Interpolate("%(prop:branch)s")],
954 env = { 'CONFIG_INI': os.getenv("BUILDMASTER_CONFIG", "./config.ini") },
955 haltOnFailure = True,
956 doStepIf = IsSignEnabled,
959 factory.addStep(FileDownload(
960 name = "dlsigntargz",
961 mastersrc = "%s/signing/%s.%s.tar.gz" %(work_dir, ts[0], ts[1]),
962 workerdest = "sign.tar.gz",
963 haltOnFailure = True,
964 doStepIf = IsSignEnabled,
967 factory.addStep(ShellCommand(
969 description = "Unpacking signed files",
970 command = ["tar", "-xzf", "sign.tar.gz"],
971 haltOnFailure = True,
972 doStepIf = IsSignEnabled,
976 factory.addStep(ShellCommand(
978 description = "Preparing upload directory structure",
979 command = ["mkdir", "-p", Interpolate("tmp/upload/%(kw:prefix)stargets/%(kw:target)s/%(kw:subtarget)s", target=ts[0], subtarget=ts[1], prefix=GetVersionPrefix)],
983 factory.addStep(ShellCommand(
984 name = "linkprepare",
985 description = "Preparing repository symlink",
986 command = ["ln", "-s", "-f", Interpolate("../packages-%(kw:basever)s", basever=util.Transform(GetBaseVersion, Property("branch"))), Interpolate("tmp/upload/%(kw:prefix)spackages", prefix=GetVersionPrefix)],
987 doStepIf = IsNoMasterBuild,
991 factory.addStep(ShellCommand(
992 name = "kmoddirprepare",
993 description = "Preparing kmod archive upload directory",
994 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)],
995 haltOnFailure = True,
996 doStepIf = IsKmodArchiveEnabled,
999 factory.addStep(ShellCommand(
1001 description = "Uploading directory structure",
1002 command = ["rsync", "-az"] + rsync_defopts + ["tmp/upload/", Interpolate("%(kw:url)s/", url=GetRsyncParams.withArgs("bin", "url"))],
1003 env={ 'RSYNC_PASSWORD': Interpolate("%(kw:key)s", key=GetRsyncParams.withArgs("bin", "key")) },
1004 haltOnFailure = True,
1009 # download remote sha256sums to 'target-sha256sums'
1010 factory.addStep(ShellCommand(
1011 name = "target-sha256sums",
1012 description = "Fetching remote sha256sums for target",
1013 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"],
1014 env={ 'RSYNC_PASSWORD': Interpolate("%(kw:key)s", key=GetRsyncParams.withArgs("bin", "key")) },
1016 haltOnFailure = False,
1017 flunkOnFailure = False,
1018 warnOnFailure = False,
1021 # build list of files to upload
1022 factory.addStep(FileDownload(
1023 name = "dlsha2rsyncpl",
1024 mastersrc = scripts_dir + '/sha2rsync.pl',
1025 workerdest = "../sha2rsync.pl",
1029 factory.addStep(ShellCommand(
1031 description = "Building list of files to upload",
1032 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"],
1033 haltOnFailure = True,
1036 factory.addStep(FileDownload(
1037 name = "dlrsync.sh",
1038 mastersrc = scripts_dir + '/rsync.sh',
1039 workerdest = "../rsync.sh",
1043 # upload new files and update existing ones
1044 factory.addStep(ShellCommand(
1045 name = "targetupload",
1046 description = "Uploading target files",
1047 command=["../rsync.sh", "--exclude=/kmods/", "--files-from=rsynclist", "--delay-updates", "--partial-dir=.~tmp~%s~%s" %(ts[0], ts[1])] + rsync_defopts +
1048 ["-a", Interpolate("bin/targets/%(kw:target)s/%(kw:subtarget)s%(prop:libc)s/", target=ts[0], subtarget=ts[1]),
1049 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)],
1050 env={ 'RSYNC_PASSWORD': Interpolate("%(kw:key)s", key=GetRsyncParams.withArgs("bin", "key")) },
1051 haltOnFailure = True,
1055 # delete files which don't exist locally
1056 factory.addStep(ShellCommand(
1057 name = "targetprune",
1058 description = "Pruning target files",
1059 command=["../rsync.sh", "--exclude=/kmods/", "--delete", "--existing", "--ignore-existing", "--delay-updates", "--partial-dir=.~tmp~%s~%s" %(ts[0], ts[1])] + rsync_defopts +
1060 ["-a", Interpolate("bin/targets/%(kw:target)s/%(kw:subtarget)s%(prop:libc)s/", target=ts[0], subtarget=ts[1]),
1061 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)],
1062 env={ 'RSYNC_PASSWORD': Interpolate("%(kw:key)s", key=GetRsyncParams.withArgs("bin", "key")) },
1063 haltOnFailure = True,
1068 factory.addStep(ShellCommand(
1069 name = "kmodupload",
1070 description = "Uploading kmod archive",
1071 command=["../rsync.sh", "--delete", "--delay-updates", "--partial-dir=.~tmp~%s~%s" %(ts[0], ts[1])] + rsync_defopts +
1072 ["-a", Interpolate("bin/targets/%(kw:target)s/%(kw:subtarget)s%(prop:libc)s/kmods/%(prop:kernelversion)s/", target=ts[0], subtarget=ts[1]),
1073 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)],
1074 env={ 'RSYNC_PASSWORD': Interpolate("%(kw:key)s", key=GetRsyncParams.withArgs("bin", "key")) },
1075 haltOnFailure = True,
1078 doStepIf = IsKmodArchiveEnabled,
1081 factory.addStep(ShellCommand(
1082 name = "sourcelist",
1083 description = "Finding source archives to upload",
1084 command = "find dl/ -maxdepth 1 -type f -not -size 0 -not -name '.*' -not -name '*.hash' -not -name '*.dl' -newer .config -printf '%f\\n' > sourcelist",
1085 haltOnFailure = True
1088 factory.addStep(ShellCommand(
1089 name = "sourceupload",
1090 description = "Uploading source archives",
1091 command=["../rsync.sh", "--files-from=sourcelist", "--size-only", "--delay-updates"] + rsync_defopts +
1092 [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"))],
1093 env={ 'RSYNC_PASSWORD': Interpolate("%(kw:key)s", key=GetRsyncParams.withArgs("src", "key")) },
1094 haltOnFailure = True,
1099 factory.addStep(ShellCommand(
1101 description = "Reporting disk usage",
1102 command=["df", "-h", "."],
1103 env={'LC_ALL': 'C'},
1104 haltOnFailure = False,
1105 flunkOnFailure = False,
1106 warnOnFailure = False,
1110 factory.addStep(ShellCommand(
1112 description = "Reporting estimated file space usage",
1113 command=["du", "-sh", "."],
1114 env={'LC_ALL': 'C'},
1115 haltOnFailure = False,
1116 flunkOnFailure = False,
1117 warnOnFailure = False,
1121 factory.addStep(ShellCommand(
1122 name = "ccachestat",
1123 description = "Reporting ccache stats",
1124 command=["ccache", "-s"],
1125 env = MakeEnv(overrides={ 'PATH': ["${PATH}", "./staging_dir/host/bin"] }),
1126 want_stderr = False,
1127 haltOnFailure = False,
1128 flunkOnFailure = False,
1129 warnOnFailure = False,
1133 c['builders'].append(BuilderConfig(name=target, workernames=workerNames, factory=factory, nextBuild=GetNextBuild))
1135 c['schedulers'].append(schedulers.Triggerable(name="trigger_%s" % target, builderNames=[ target ]))
1136 force_factory.addStep(steps.Trigger(
1137 name = "trigger_%s" % target,
1138 description = "Triggering %s build" % target,
1139 schedulerNames = [ "trigger_%s" % target ],
1140 set_properties = { "reason": Property("reason"), "tag": TagPropertyValue },
1141 doStepIf = IsTargetSelected(target)
1145 ####### STATUS TARGETS
1147 # 'status' is a list of Status Targets. The results of each build will be
1148 # pushed to these targets. buildbot/status/*.py has a variety to choose from,
1149 # including web pages, email senders, and IRC bots.
1151 if "status_bind" in inip1:
1153 'port': inip1.get("status_bind"),
1155 'waterfall_view': True,
1156 'console_view': True,
1161 if "status_user" in inip1 and "status_password" in inip1:
1162 c['www']['auth'] = util.UserPasswordAuth([
1163 (inip1.get("status_user"), inip1.get("status_password"))
1165 c['www']['authz'] = util.Authz(
1166 allowRules=[ util.AnyControlEndpointMatcher(role="admins") ],
1167 roleMatchers=[ util.RolesFromUsername(roles=["admins"], usernames=[inip1.get("status_user")]) ]
1171 if ini.has_section("irc"):
1173 irc_host = iniirc.get("host", None)
1174 irc_port = iniirc.getint("port", 6667)
1175 irc_chan = iniirc.get("channel", None)
1176 irc_nick = iniirc.get("nickname", None)
1177 irc_pass = iniirc.get("password", None)
1179 if irc_host and irc_nick and irc_chan:
1180 irc = reporters.IRC(irc_host, irc_nick,
1182 password = irc_pass,
1183 channels = [ irc_chan ],
1184 notify_events = [ 'exception', 'problem', 'recovery' ]
1187 c['services'].append(irc)
1189 c['revlink'] = util.RevlinkMatch([
1190 r'https://git.openwrt.org/openwrt/(.*).git'
1192 r'https://git.openwrt.org/?p=openwrt/\1.git;a=commit;h=%s')
1197 # This specifies what database buildbot uses to store its state. You can leave
1198 # this at its default for all but the largest installations.
1199 'db_url' : "sqlite:///state.sqlite",
1202 c['buildbotNetUsageData'] = None