# -*- python -*-
# ex: set syntax=python:

# This is a sample buildmaster config file. It must be installed as
# 'master.cfg' in your buildmaster's base directory.

# This is the dictionary that the buildmaster pays attention to. We also use
# a shorter alias to save typing.
c = BuildmasterConfig = {}

####### BUILDSLAVES

# The 'slaves' list defines the set of recognized buildslaves. Each element is
# a BuildSlave object, specifying a unique slave name and password.  The same
# slave name and password must be configured on the slave.
from buildbot.buildslave import BuildSlave

from slaves import slaves
def slmap(p): return BuildSlave(p[0], p[1]) 
c['slaves'] = map(slmap, slaves)

# 'slavePortnum' defines the TCP port to listen on for connections from slaves.
# This must match the value configured into the buildslaves (with their
# --master option)
c['slavePortnum'] = 9989

####### CHANGESOURCES

# the 'change_source' setting tells the buildmaster how it should find out
# about source code changes.  Here we point to the buildbot clone of pyflakes.

from buildbot.changes.gitpoller import GitPoller
c['change_source'] = []
c['change_source'].append(GitPoller(
        'https://github.com/justincormack/ljsyscall.git',
        workdir='gitpoller-workdir', branches=['master'],
        pollinterval=30))

####### SCHEDULERS

# Configure the Schedulers, which decide how to react to incoming changes.  In this
# case, just kick off a 'runtests' build

from buildbot.schedulers.basic import SingleBranchScheduler
from buildbot.schedulers.forcesched import ForceScheduler
from buildbot.changes import filter
c['schedulers'] = []
c['schedulers'].append(SingleBranchScheduler(
                            name="all",
                            change_filter=filter.ChangeFilter(branch='master'),
                            treeStableTimer=None,
                            builderNames=["runtests-glibc-x64", "runtests-glibc-x86", "runtests-glibc-ppc", "runtests-linux-mips", "runtests-netbsd-x86", "runtests-netbsd-x64", "runtests-freebsd10", "runtests-openbsd54", "globals", "runtests-rump-linux-x64", "runtests-rump-linux-x86", "runtests-rump-linux-ppc", "runtests-rump-netbsd-x64", "runtests-rump-netbsd-x86", "runtests-rump-freebsd10"]))
#c['schedulers'].append(ForceScheduler(
#                            name="force",
#                            builderNames=["runtests-glibc-x64", "runtests-glibc-x86", "runtests-glibc-arm", "runtests-glibc-ppc", "globals", "ctest-linux-x64", "ctest-linux-x86", "ctest-linux-ppc", "runtests-rump-linux-x64", "runtests-rump-linux-x86", "runtests-rump-linux-arm", "runtests-rump-linux-ppc", "runtests-netbsd-x86", "runtests-rump-netbsd-x86", "ctest-netbsd-x86"]))

####### BUILDERS

# The 'builders' list defines the Builders, which tell Buildbot how to perform a build:
# what steps, and which slaves can execute them.  Note that any particular build will
# only take place on one slave.

from buildbot.process.factory import BuildFactory
from buildbot.steps.source.git import Git
from buildbot.steps.shell import ShellCommand

test = BuildFactory()
test.addStep(Git(repourl='https://github.com/justincormack/ljsyscall.git', mode='incremental', workdir='build', timeout=2400))
test.addStep(ShellCommand(command=["git","submodule","update","--init","--recursive"]))
test.addStep(ShellCommand(command=["luajit", "test/test.lua"]))
test.addStep(ShellCommand(command="mkdir -p obj"))
test.addStep(ShellCommand(command="luajit test/ctest.lua > obj/ctest.c"))
test.addStep(ShellCommand(command=["cc", "-std=c99", "obj/ctest.c", "-o", "obj/ctest"]))
test.addStep(ShellCommand(command=["./obj/ctest"]))

test32 = BuildFactory()
test32.addStep(Git(repourl='https://github.com/justincormack/ljsyscall.git', mode='incremental', workdir='build', timeout=2400))
test32.addStep(ShellCommand(command=["git","submodule","update","--init","--recursive"]))
test32.addStep(ShellCommand(command=["luajit", "test/test.lua"]))
test32.addStep(ShellCommand(command="mkdir -p obj"))
test32.addStep(ShellCommand(command="luajit test/ctest.lua > obj/ctest.c"))
test32.addStep(ShellCommand(command=["cc", "-m32", "-std=c99", "obj/ctest.c", "-o", "obj/ctest"]))
test32.addStep(ShellCommand(command=["./obj/ctest"]))

testmips = BuildFactory()
testmips.addStep(Git(repourl='https://github.com/justincormack/ljsyscall.git', mode='incremental', workdir='build', timeout=2400))
testmips.addStep(ShellCommand(command=["git","submodule","update","--init","--recursive"]))
testmips.addStep(ShellCommand(command=["luajit", "test/test.lua"]))
testmips.addStep(ShellCommand(command="mkdir -p obj"))
testmips.addStep(ShellCommand(command="luajit test/ctest.lua > obj/ctest.c"))
testmips.addStep(ShellCommand(command=["cc", "-mabi=32", "-std=c99", "obj/ctest.c", "-o", "obj/ctest"]))
testmips.addStep(ShellCommand(command=["./obj/ctest"]))

rump = BuildFactory()
rump.addStep(Git(repourl='https://github.com/justincormack/ljsyscall.git', mode='incremental', workdir='build'))
rump.addStep(ShellCommand(command=["git","submodule","update","--init","--recursive"]))
rump.addStep(ShellCommand(command='cd ./include/buildrump.sh && rm -rf obj rump && ./buildrump.sh -qq -j1 -V NOSTATICLIB=1 checkout fullbuild && cd ../..', timeout=3600))
rump.addStep(ShellCommand(env = {"LD_DYNAMIC_WEAK":"1","LD_LIBRARY_PATH":"./include/buildrump.sh/rump/lib"},command=["luajit", "test/test.lua", "rump"]))

rump32 = BuildFactory()
rump32.addStep(Git(repourl='https://github.com/justincormack/ljsyscall.git', mode='incremental', workdir='build'))
rump32.addStep(ShellCommand(command=["git","submodule","update","--init","--recursive"]))
rump32.addStep(ShellCommand(command='cd ./include/buildrump.sh && rm -rf obj rump && ./buildrump.sh -F ACLFLAGS=-m32 -qq -j1 -V NOSTATICLIB=1 checkout fullbuild && cd ../..', timeout=3600))
rump32.addStep(ShellCommand(env = {"LD_DYNAMIC_WEAK":"1","LD_LIBRARY_PATH":"./include/buildrump.sh/rump/lib"},command=["luajit", "test/test.lua", "rump"]))

globals = BuildFactory()
globals.addStep(Git(repourl='https://github.com/justincormack/ljsyscall.git', mode='incremental', workdir='build'))
globals.addStep(ShellCommand(command=["./test/globals.sh"]))

from buildbot.config import BuilderConfig

c['builders'] = []
c['builders'].append(
    BuilderConfig(name="runtests-glibc-x64",
      slavenames=["ubuntu64"],
      factory=test))
c['builders'].append(
    BuilderConfig(name="runtests-glibc-x86",
      slavenames=["ubuntu32"],
      factory=test))
#c['builders'].append(
#    BuilderConfig(name="runtests-glibc-arm",
#      slavenames=["cubox-glibc-arm"],
#      factory=test))
c['builders'].append(
    BuilderConfig(name="runtests-linux-mips",
      slavenames=["erl-linux-mips"],
      factory=testmips))
c['builders'].append(
    BuilderConfig(name="runtests-glibc-ppc",
      slavenames=["pike-glibc-ppc"],
      factory=test32))
c['builders'].append(
    BuilderConfig(name="runtests-netbsd-x86",
      slavenames=["netbsd32"],
      factory=test))
c['builders'].append(
    BuilderConfig(name="runtests-netbsd-x64",
      slavenames=["netbsd64"],
      factory=test))
c['builders'].append(
    BuilderConfig(name="runtests-freebsd10",
      slavenames=["freebsd10"],
      factory=test))
c['builders'].append(
    BuilderConfig(name="runtests-openbsd54",
      slavenames=["openbsd54"],
      factory=test))
c['builders'].append(
    BuilderConfig(name="runtests-rump-linux-x64",
      slavenames=["ubuntu64"],
      factory=rump))
c['builders'].append(
    BuilderConfig(name="runtests-rump-linux-x86",
      slavenames=["ubuntu32"],
      factory=rump))
#c['builders'].append(
#    BuilderConfig(name="runtests-rump-linux-arm",
#      slavenames=["cubox-glibc-arm"],
#      factory=rump))
c['builders'].append(
    BuilderConfig(name="runtests-rump-linux-ppc",
      slavenames=["pike-glibc-ppc"],
      factory=rump32))
c['builders'].append(
    BuilderConfig(name="runtests-rump-netbsd-x86",
      slavenames=["netbsd32"],
      factory=rump))
c['builders'].append(
    BuilderConfig(name="runtests-rump-netbsd-x64",
      slavenames=["netbsd64"],
      factory=rump))
c['builders'].append(
    BuilderConfig(name="runtests-rump-freebsd10",
      slavenames=["freebsd10"],
      factory=rump))
c['builders'].append(
    BuilderConfig(name="globals",
      slavenames=["ubuntu64"],
      factory=globals))

####### STATUS TARGETS

# 'status' is a list of Status Targets. The results of each build will be
# pushed to these targets. buildbot/status/*.py has a variety to choose from,
# including web pages, email senders, and IRC bots.

c['status'] = []

from buildbot.status import html
from buildbot.status.web import authz, auth

authz_cfg=authz.Authz(
    # change any of these to True to enable; see the manual for more
    # options
    gracefulShutdown = False,
    forceBuild = False,
    forceAllBuilds = False,
    pingBuilder = False,
    stopBuild = False,
    stopAllBuilds = False,
    cancelPendingBuild = False,
)
c['status'].append(html.WebStatus(http_port=8010))

from buildbot.status.mail import MailNotifier
mn = MailNotifier(fromaddr="buildbot@myriabit.eu", lookup="specialbusservice.com", mode="problem")
c['status'].append(mn)


####### PROJECT IDENTITY

# the 'title' string will appear at the top of this buildbot
# installation's html.WebStatus home page (linked to the
# 'titleURL') and is embedded in the title of the waterfall HTML page.

c['title'] = "ljsyscall"
c['titleURL'] = "https://github.com/justincormack/ljsyscall"

# the 'buildbotURL' string should point to the location where the buildbot's
# internal web server (usually the html.WebStatus page) is visible. This
# typically uses the port number set in the Waterfall 'status' entry, but
# with an externally-visible host name which the buildbot cannot figure out
# without some help.

c['buildbotURL'] = "http://build.myriabit.eu:8010/"

####### DB URL

c['db'] = {
    # This specifies what database buildbot uses to store its state.  You can leave
    # this at its default for all but the largest installations.
    'db_url' : "sqlite:///state.sqlite",
}
