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

from buildbot.plugins import *

# 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 = {}

####### WORKERS

# The 'workers' list defines the set of recognized workers. Each element is
# a Worker object, specifying a unique worker name and password.  The same
# worker name and password must be configured on the worker.
c['workers'] = [
    worker.Worker('', ''), #NEED TO BE CONFIGURED
    worker.Worker('', ''), #NEED TO BE CONFIGURED
    worker.Worker('', '') #NEED TO BE CONFIGURED
]

# 'protocols' contains information about protocols which master will use for
# communicating with workers. You must define at least 'port' option that workers
# could connect to your master with this protocol.
# 'port' must match the value configured into the workers (with their
# --master option)
c['protocols'] = {'pb': {'port': 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.

c['change_source'] = []

#GLIBC PROJECT
c['change_source'].append(changes.GitPoller(
        'git://sourceware.org/git/glibc.git',
        workdir='gitpoller-workdir', branch='master',
        pollinterval=300, project='glibc'))

#GDB PROJECT
c['change_source'].append(changes.GitPoller(
        'git://sourceware.org/git/binutils-gdb.git',
        workdir='gitpoller-workdir', branch='master',
        pollinterval=300, project='gdb'))

#GCC PROJECT
c['change_source'].append(changes.GitPoller(
        'git://gcc.gnu.org/git/gcc.git',
        workdir='gitpoller-workdir', branch='master',
        pollinterval=300, project='gcc'))

####### SCHEDULERS

# Configure the Schedulers, which decide how to react to incoming changes.

c['schedulers']=[]

#GLIBC PROJECT
glibc_filter = util.ChangeFilter(project='glibc', branch='master')

c['schedulers'].append(schedulers.SingleBranchScheduler(
                            name="glibc_build",
                            change_filter=glibc_filter,
                            treeStableTimer=None,
                            builderNames=["glibctests"]))
c['schedulers'].append(schedulers.ForceScheduler(
                            name="force_glibc",
                            builderNames=["glibctests"]))

#GDB PROJECT
gdb_filter = util.ChangeFilter(project='gdb', branch='master')

c['schedulers'].append(schedulers.SingleBranchScheduler(
                            name="gdb_build",
                            change_filter=gdb_filter,
                            treeStableTimer=None,
                            builderNames=["gdbtests"]))
c['schedulers'].append(schedulers.ForceScheduler(
                            name="force_gdb",
                            builderNames=["gdbtests"]))

#GDB PROJECT
gcc_filter = util.ChangeFilter(project='gcc', branch='master')

c['schedulers'].append(schedulers.SingleBranchScheduler(
                            name="gcc_build",
                            change_filter=gcc_filter,
                            treeStableTimer=None,
                            builderNames=["gcctests"]))
c['schedulers'].append(schedulers.ForceScheduler(
                            name="force_gcc",
                            builderNames=["gcctests"]))


####### BUILDERS

# The 'builders' list defines the Builders, which tell Buildbot how to perform a build:
# what steps, and which workers can execute them.


#GLIBCPROJECT
glibc_build =[
        steps.Git(repourl='git://sourceware.org/git/glibc.git', mode='incremental'),
        steps.ShellCommand(command=["../build/configure", "--prefix=/usr"], workdir = "bin"),
        steps.ShellCommand(command=["make"], workdir = "bin"),
        steps.ShellCommand(command=["make", "check"], workdir = "bin"),
        steps.ShellCommand(command=[ "/bin/sh", "-c",
            'cp tests.sum ~/buildbot/glibc_logs/`date +"Glibc-BasicTest-%H:%M_%m-%d-%Y.sum"`'], workdir = "bin")
        ]

glibc_factory = util.BuildFactory(glibc_build)

c['builders'] = []
c['builders'].append(
    util.BuilderConfig(name="glibctests",
      workernames=[""], #NEED TO BE CONFIGURED
      factory=glibc_factory))

#GDB PROJECT
gdb_build = [
        steps.Git(repourl='git://sourceware.org/git/binutils-gdb.git', mode='incremental'),
        steps.ShellCommand(command=["../build/configure", "--prefix=/usr"], workdir = "bin"),
        steps.ShellCommand(command=["make"], workdir = "bin"),
        steps.ShellCommand(command=["make", "check-gdb"], workdir = "bin"),
       #steps.ShellCommand(command=["cp", "tests.sum", "~/Tests.sum"], workdir = "bin")
        ]

gdb_factory = util.BuildFactory(gdb_build)
c['builders'].append(
    util.BuilderConfig(name="gdbtests",
        workernames=[""], #NEED TO BE CONFIGURED
        factory=gdb_factory))

#GCC PROJECT
gcc_build = [
        steps.Git(repourl='git://gcc.gnu.org/git/gcc.git', mode='incremental'),
        steps.ShellCommand(command=["../build/configure", "--prefix=/usr"], workdir= "bin"),
        steps.ShellCommand(command=["make"], workdir = "bin"),
        steps.ShellCommand(command=["make", "check-gcc"], workdir= "bin", timeout=7200),
        ]
gcc_factory = util.BuildFactory(gcc_build)
c['builders'].append(
        util.BuilderConfig(name="gcctests",
            workernames=[""], #NEED TO BE CONFIGURED
            factory=gcc_factory))

####### BUILDBOT SERVICES

# 'services' is a list of BuildbotService items like reporter targets. The
# status of each build will be pushed to these targets. buildbot/reporters/*.py
# has a variety to choose from, like IRC bots.

c['services'] = []

####### PROJECT IDENTITY

# the 'title' string will appear at the top of this buildbot installation's
# home pages (linked to the 'titleURL').

c['title'] = "OpenPower"
c['titleURL'] = "http://openpower.ic.unicamp.br/"

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

c['buildbotURL'] = "" #NEED TO BE CONFIGURED

# minimalistic config to activate new web UI
c['www'] = dict(port= , #NEED TO BE CONFIGURED
                plugins=dict(waterfall_view={False}, console_view={False}, grid_view={True}))

# login for administrators
authz = util.Authz(
  allowRules=[
    util.AnyControlEndpointMatcher(role="admins"),
  ],
  roleMatchers=[
    util.RolesFromEmails(admins=["ADMIN_1", "ADMIN_2"]) #NEED TO BE CONFIGURED
  ]
)
auth=util.UserPasswordAuth({'ADMIN_1': 'PASS_1', 'ADMIN_2' : 'PASS_2'}) #NEED TO BE CONFIGURED
c['www']['auth'] = auth
c['www']['authz'] = authz

####### 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",
}
