2 # ex: set syntax=python:
9 from buildbot import locks
11 # This is a sample buildmaster config file. It must be installed as
12 # 'master.cfg' in your buildmaster's base directory.
14 ini = ConfigParser.ConfigParser()
15 ini.read("./config.ini")
17 # This is the dictionary that the buildmaster pays attention to. We also use
18 # a shorter alias to save typing.
19 c = BuildmasterConfig = {}
23 # The 'slaves' list defines the set of recognized buildslaves. Each element is
24 # a BuildSlave object, specifying a unique slave name and password. The same
25 # slave name and password must be configured on the slave.
26 from buildbot.buildslave import BuildSlave
30 for section in ini.sections():
31 if section.startswith("slave "):
32 if ini.has_option(section, "name") and ini.has_option(section, "password"):
33 name = ini.get(section, "name")
34 password = ini.get(section, "password")
36 if ini.has_option(section, "builds"):
37 max_builds = ini.getint(section, "builds")
38 c['slaves'].append(BuildSlave(name, password, max_builds = max_builds))
40 # 'slavePortnum' defines the TCP port to listen on for connections from slaves.
41 # This must match the value configured into the buildslaves (with their
43 c['slavePortnum'] = 9989
46 c['mergeRequests'] = True
50 home_dir = os.path.abspath(ini.get("general", "homedir"))
52 repo_url = ini.get("repo", "url")
54 rsync_bin_url = ini.get("rsync", "binary_url")
55 rsync_bin_key = ini.get("rsync", "binary_password")
60 if ini.has_option("rsync", "source_url"):
61 rsync_src_url = ini.get("rsync", "source_url")
62 rsync_src_key = ini.get("rsync", "source_password")
67 findtargets = subprocess.Popen([home_dir+'/dumpinfo.pl', 'targets'],
68 stdout = subprocess.PIPE, cwd = home_dir+'/source.git')
71 line = findtargets.stdout.readline()
74 ta = line.strip().split(' ')
78 # the 'change_source' setting tells the buildmaster how it should find out
79 # about source code changes. Here we point to the buildbot clone of pyflakes.
81 from buildbot.changes.gitpoller import GitPoller
82 c['change_source'] = []
83 c['change_source'].append(GitPoller(
85 workdir=home_dir+'/source.git', branch='master',
90 # Configure the Schedulers, which decide how to react to incoming changes. In this
91 # case, just kick off a 'basebuild' build
93 from buildbot.schedulers.basic import SingleBranchScheduler
94 from buildbot.schedulers.forcesched import ForceScheduler
95 from buildbot.changes import filter
97 c['schedulers'].append(SingleBranchScheduler(
99 change_filter=filter.ChangeFilter(branch='master'),
101 builderNames=targets))
103 c['schedulers'].append(ForceScheduler(
105 builderNames=targets))
109 # The 'builders' list defines the Builders, which tell Buildbot how to perform a build:
110 # what steps, and which slaves can execute them. Note that any particular build will
111 # only take place on one slave.
113 from buildbot.process.factory import BuildFactory
114 from buildbot.steps.source import Git
115 from buildbot.steps.shell import ShellCommand
116 from buildbot.steps.shell import SetProperty
117 from buildbot.steps.transfer import FileDownload
118 from buildbot.process.properties import WithProperties
122 "^tools/": "tools/clean",
123 "^toolchain/": "toolchain/clean",
124 "^target/linux/": "target/linux/clean",
125 "^(config|include)/": "dirclean"
128 def IsAffected(pattern):
129 def CheckAffected(change):
130 for request in change.build.requests:
131 for source in request.sources:
132 for change in source.changes:
133 for file in change.files:
134 if re.match(pattern, file):
139 def isPathBuiltin(path):
142 conf = open(".config", "r")
145 line = conf.readline()
148 m = re.match("^(CONFIG_PACKAGE_.+?)=y", line)
150 incl[m.group(1)] = True
154 deps = open("tmp/.packagedeps", "r")
157 line = deps.readline()
160 m = re.match("^package-\$\((CONFIG_PACKAGE_.+?)\) \+= (\S+)", line)
161 if m and incl.get(m.group(1)) == True:
162 pkgs["package/%s" % m.group(2)] = True
167 if pkgs.get(path) == True:
169 path = os.path.dirname(path)
173 def isChangeBuiltin(change):
175 # for request in change.build.requests:
176 # for source in request.sources:
177 # for change in source.changes:
178 # for file in change.files:
179 # if isPathBuiltin(file):
186 dlLock = locks.SlaveLock("slave_dl")
188 checkBuiltin = re.sub('[\t\n ]+', ' ', """
190 local symbol op path file;
191 for file in $CHANGED_FILES; do
197 while read symbol op path; do
198 case "$symbol" in package-*)
199 symbol="${symbol##*(}";
200 symbol="${symbol%)}";
201 for file in $CHANGED_FILES; do
202 case "$file" in "package/$path/"*)
203 grep -qsx "$symbol=y" .config && return 0
207 done < tmp/.packagedeps;
213 class IfBuiltinShellCommand(ShellCommand):
214 def _quote(self, str):
215 if re.search("[^a-zA-Z0-9/_.-]", str):
216 return "'%s'" %(re.sub("'", "'\"'\"'", str))
219 def setCommand(self, command):
220 if not isinstance(command, (str, unicode)):
221 command = ' '.join(map(self._quote, command))
224 '%s; if checkBuiltin; then %s; else exit 0; fi' %(checkBuiltin, command)
227 def setupEnvironment(self, cmd):
228 slaveEnv = self.slaveEnvironment
232 for request in self.build.requests:
233 for source in request.sources:
234 for change in source.changes:
235 for file in change.files:
236 changedFiles[file] = True
237 fullSlaveEnv = slaveEnv.copy()
238 fullSlaveEnv['CHANGED_FILES'] = ' '.join(changedFiles.keys())
239 cmd.args['env'] = fullSlaveEnv
243 for slave in c['slaves']:
244 slaveNames.append(slave.slavename)
246 for target in targets:
247 ts = target.split('/')
249 factory = BuildFactory()
251 # find number of cores
252 factory.addStep(SetProperty(
255 description = "Finding number of CPUs",
256 command = ["nproc"]))
258 # check out the source
259 factory.addStep(Git(repourl=repo_url, mode='update'))
261 factory.addStep(ShellCommand(
263 description = "Remove tmp folder",
264 command=["rm", "-rf", "tmp/"]))
267 # factory.addStep(ShellCommand(
268 # name = "feedsconf",
269 # description = "Copy the feeds.conf",
270 # command='''cp ~/feeds.conf ./feeds.conf''' ))
273 factory.addStep(ShellCommand(
274 name = "updatefeeds",
275 description = "Updating feeds",
276 command=["./scripts/feeds", "update"]))
279 factory.addStep(ShellCommand(
280 name = "installfeeds",
281 description = "Installing feeds",
282 command=["./scripts/feeds", "install", "-a"]))
285 factory.addStep(ShellCommand(
287 description = "Seeding .config",
288 command='''cat <<EOT > .config
290 CONFIG_TARGET_%s_%s=y
291 CONFIG_ALL_NONSHARED=y
294 # CONFIG_IB_STANDALONE is not set
297 CONFIG_SIGNED_PACKAGES=y
298 # CONFIG_PER_FEED_REPO_ADD_COMMENTED is not set
299 CONFIG_KERNEL_KALLSYMS=y
300 CONFIG_COLLECT_KERNEL_DEBUG=y
301 EOT''' %(ts[0], ts[0], ts[1]) ))
303 factory.addStep(ShellCommand(
305 description = "Removing output directory",
306 command = ["rm", "-rf", "bin/"]
309 factory.addStep(ShellCommand(
311 description = "Populating .config",
312 command = ["make", "defconfig"]
316 factory.addStep(ShellCommand(
318 description = "Checking architecture",
319 command = ["grep", "-sq", "CONFIG_TARGET_%s=y" %(ts[0]), ".config"],
326 factory.addStep(ShellCommand(
328 description = "Checking libc flavor",
329 command = ["grep", "-sq", 'CONFIG_LIBC="musl"', ".config"],
337 factory.addStep(FileDownload(mastersrc=home_dir+'/key-build', slavedest="key-build", mode=0600))
338 factory.addStep(FileDownload(mastersrc=home_dir+'/key-build.pub', slavedest="key-build.pub", mode=0600))
341 factory.addStep(ShellCommand(
343 description = "Preparing dl/",
344 command = "mkdir -p $HOME/dl && ln -sf $HOME/dl ./dl",
350 factory.addStep(ShellCommand(
352 description = "Populating dl/",
353 command = ["make", WithProperties("-j%(nproc:~4)s"), "download", "V=s"],
355 locks = [dlLock.access('exclusive')]
358 factory.addStep(ShellCommand(
360 description = "Cleaning base-files",
361 command=["make", "package/base-files/clean", "V=s"]
364 # optional clean steps
365 for pattern, maketarget in MakeTargetMap.items():
366 factory.addStep(ShellCommand(
368 description = maketarget,
369 command=["make", maketarget, "V=s"], doStepIf=IsAffected(pattern)
373 factory.addStep(ShellCommand(
375 description = "Building tools",
376 command = ["make", WithProperties("-j%(nproc:~4)s"), "tools/install", "V=s"],
380 factory.addStep(ShellCommand(
382 description = "Building toolchain",
383 command=["make", WithProperties("-j%(nproc:~4)s"), "toolchain/install", "V=s"],
387 factory.addStep(ShellCommand(
389 description = "Building kmods",
390 command=["make", WithProperties("-j%(nproc:~4)s"), "target/compile", "V=s", "IGNORE_ERRORS=n m", "BUILD_LOG=1"],
391 #env={'BUILD_LOG_DIR': 'bin/%s' %(ts[0])},
395 factory.addStep(ShellCommand(
397 description = "Building packages",
398 command=["make", WithProperties("-j%(nproc:~4)s"), "package/compile", "V=s", "IGNORE_ERRORS=n m", "BUILD_LOG=1"],
399 #env={'BUILD_LOG_DIR': 'bin/%s' %(ts[0])},
403 # factory.addStep(IfBuiltinShellCommand(
404 factory.addStep(ShellCommand(
406 description = "Installing packages",
407 command=["make", WithProperties("-j%(nproc:~4)s"), "package/install", "V=s"],
408 doStepIf = isChangeBuiltin,
412 factory.addStep(ShellCommand(
414 description = "Indexing packages",
415 command=["make", WithProperties("-j%(nproc:~4)s"), "package/index", "V=s"],
419 #factory.addStep(IfBuiltinShellCommand(
420 factory.addStep(ShellCommand(
422 description = "Building images",
423 command=["make", "-j1", "target/install", "V=s"],
424 doStepIf = isChangeBuiltin,
429 factory.addStep(ShellCommand(
430 name = "uploadprepare",
431 description = "Preparing target directory",
432 command=["rsync", "-av", "--include", "/%s/" %(ts[0]), "--include", "/%s/%s/" %(ts[0], ts[1]), "--exclude", "/*", "--exclude", "/*/*", "--exclude", "/%s/%s/*" %(ts[0], ts[1]), "bin/targets/", "%s/targets/" %(rsync_bin_url)],
433 env={'RSYNC_PASSWORD': rsync_bin_key},
434 haltOnFailure = True,
438 factory.addStep(ShellCommand(
439 name = "targetupload",
440 description = "Uploading target files",
441 command=["rsync", "--delete", "--delay-updates", WithProperties("--partial-dir=.~tmp~%(buildername)s"), "-avz", "bin/targets/%s/%s/" %(ts[0], ts[1]), "%s/targets/%s/%s/" %(rsync_bin_url, ts[0], ts[1])],
442 env={'RSYNC_PASSWORD': rsync_bin_key},
443 haltOnFailure = True,
447 if rsync_src_url is not None:
448 factory.addStep(ShellCommand(
449 name = "sourceupload",
450 description = "Uploading source archives",
451 command=["rsync", "--delay-updates", WithProperties("--partial-dir=.~tmp~%(buildername)s"), "-avz", "dl/", "%s/" %(rsync_src_url)],
452 env={'RSYNC_PASSWORD': rsync_src_key},
453 haltOnFailure = True,
458 factory.addStep(ShellCommand(
459 name = "packageupload",
460 description = "Uploading package files",
461 command=["rsync", "--delete", "--delay-updates", WithProperties("--partial-dir=.~tmp~%(buildername)s"), "-avz", "bin/packages/", "%s/packages/" %(rsync_bin_url)],
462 env={'RSYNC_PASSWORD': rsync_bin_key},
463 haltOnFailure = False,
469 factory.addStep(ShellCommand(
471 description = "Uploading logs",
472 command=["rsync", "--delete", "--delay-updates", WithProperties("--partial-dir=.~tmp~%(buildername)s"), "-avz", "logs/", "%s/logs/%s/%s/" %(rsync_bin_url, ts[0], ts[1])],
473 env={'RSYNC_PASSWORD': rsync_bin_key},
474 haltOnFailure = False,
479 from buildbot.config import BuilderConfig
481 c['builders'].append(BuilderConfig(name=target, slavenames=slaveNames, factory=factory))
484 ####### STATUS TARGETS
486 # 'status' is a list of Status Targets. The results of each build will be
487 # pushed to these targets. buildbot/status/*.py has a variety to choose from,
488 # including web pages, email senders, and IRC bots.
492 from buildbot.status import html
493 from buildbot.status.web import authz, auth
495 if ini.has_option("status", "bind"):
496 if ini.has_option("status", "user") and ini.has_option("status", "password"):
497 authz_cfg=authz.Authz(
498 # change any of these to True to enable; see the manual for more
500 auth=auth.BasicAuth([(ini.get("status", "user"), ini.get("status", "password"))]),
501 gracefulShutdown = False,
502 forceBuild = 'auth', # use this to test your slave once it is set up
503 forceAllBuilds = 'auth',
506 stopAllBuilds = 'auth',
507 cancelPendingBuild = 'auth',
509 c['status'].append(html.WebStatus(http_port=ini.get("status", "bind"), authz=authz_cfg))
511 c['status'].append(html.WebStatus(http_port=ini.get("status", "bind")))
514 from buildbot.status import words
516 if ini.has_option("irc", "host") and ini.has_option("irc", "nickname") and ini.has_option("irc", "channel"):
517 irc_host = ini.get("irc", "host")
519 irc_chan = ini.get("irc", "channel")
520 irc_nick = ini.get("irc", "nickname")
523 if ini.has_option("irc", "port"):
524 irc_port = ini.getint("irc", "port")
526 if ini.has_option("irc", "password"):
527 irc_pass = ini.get("irc", "password")
529 irc = words.IRC(irc_host, irc_nick, port = irc_port, password = irc_pass,
530 channels = [{ "channel": irc_chan }],
533 'successToFailure': 1,
534 'failureToSuccess': 1
538 c['status'].append(irc)
541 ####### PROJECT IDENTITY
543 # the 'title' string will appear at the top of this buildbot
544 # installation's html.WebStatus home page (linked to the
545 # 'titleURL') and is embedded in the title of the waterfall HTML page.
547 c['title'] = ini.get("general", "title")
548 c['titleURL'] = ini.get("general", "title_url")
550 # the 'buildbotURL' string should point to the location where the buildbot's
551 # internal web server (usually the html.WebStatus page) is visible. This
552 # typically uses the port number set in the Waterfall 'status' entry, but
553 # with an externally-visible host name which the buildbot cannot figure out
556 c['buildbotURL'] = ini.get("general", "buildbot_url")
561 # This specifies what database buildbot uses to store its state. You can leave
562 # this at its default for all but the largest installations.
563 'db_url' : "sqlite:///state.sqlite",