# -*- 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
c['slaves'] = [BuildSlave("example-slave", "pass")]

# 'protocols' contains information about protocols which master will use for
# communicating with slaves.
# You must define at least 'port' option that slaves could connect to your master
# with this protocol.
# 'port' must match the value configured into the buildslaves (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.

from buildbot.changes.gitpoller import GitPoller
from buildbot.changes import pb
c['change_source'] = []
c['change_source'].append(GitPoller(
        'file:///home/cdoucet/Documents/soutien/matherials/codes/simol',
        branches=True,
        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=["Ubuntu-12.04"]))
c['schedulers'].append(ForceScheduler(
                            name="force",
                            builderNames=["Ubuntu-12.04"]))

####### 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 import shell
from buildbot.steps.shell import ShellCommand
from buildbot.steps.shell import Compile

#==================================
# STEP 1: source cleaning with Make
#==================================
makeClean = ShellCommand( name        = "Cleaning",
                          command     = ["rm","-rf","*"],
                          description = "Cleaning",
                          descriptionDone = "Cleaning")
#==============================
# STEP 2: trunk update with SVN
#==============================
update = Git(repourl='file:///home/cdoucet/Documents/soutien/matherials/codes/simol', 
             name="Git clone",
             description="Git clone",
             descriptionDone="Git clone",
             mode='incremental',
             haltOnFailure=True)

#========================
# STEP 5: static analysis
#========================

cppcheck = Compile( command     = "cppcheck --enable=all --template gcc core/* LinearAlgebra/* ODE/* StatisticalPhysics/* QuantumChemistry/*",
                            name = "Static analysis",
                            description = "Static analysis",
                            descriptionDone = "Static analysis",
                            workdir     = "build/src",
                            warningPattern = ".*(error|style).*",
                            warnOnWarnings = True )

#=================================
# STEP 4: configuration with CMake
#=================================
cmake = shell.Configure( command="cmake -D ENABLE_DOWNLOAD=True ..",
                         workdir="build/Linux",
                         description = "Configuration",
                            name = "Configuration",
                            descriptionDone = "Configuration",
		     warnOnWarnings = True,
                     haltOnFailure = True )

#================================
# STEP 4: code building with Make
#================================
#make = shell.Compile( command     = ["make"],
#                     description = "Building",
#                            name = "Building",
#                            descriptionDone = "Building",
#                     workdir     = "build/Linux",
#                      warnOnWarnings = True,
#                     warningPattern = ".*attention.*",
#                     haltOnFailure = True)
make = ShellCommand( name        = "Building",
                          command     = ["make"],
                     workdir     = "build/Linux",
                     description = "Building",
                            descriptionDone = "Building",
                    #env={'http_proxy': 'http://proxy.enpc.fr:3128', 'https_proxy': 'https://proxy.enpc.fr:3128'}
                    )

#===============================
# STEP 5: installation with Make
#===============================
makeInstall = shell.Compile( command     = "make install",
                            description = "Installation",
                            name = "Installation",
                            descriptionDone = "Installation",
                            workdir     = "build/Linux",
		     warnOnWarnings = True,
                     haltOnFailure = True )

factory = BuildFactory()
# check out the source
factory.addStep(makeClean)
factory.addStep(update)
factory.addStep(cppcheck)
factory.addStep(cmake)
factory.addStep(make)
#factory.addStep(makeInstall)


from buildbot.config import BuilderConfig

c['builders'] = []
c['builders'].append(
    BuilderConfig(name="Ubuntu-12.04",
      slavenames=["example-slave"],
      factory=factory))

####### 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
    auth=auth.BasicAuth([("pyflakes","pyflakes")]),
    gracefulShutdown = False,
    forceBuild = 'auth', # use this to test your slave once it is set up
    forceAllBuilds = 'auth',  # ..or this
    pingBuilder = False,
    stopBuild = False,
    stopAllBuilds = False,
    cancelPendingBuild = False,
)
c['status'].append(html.WebStatus(http_port=8010, authz=authz_cfg))

####### 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'] = "Simol"
c['titleURL'] = "https://sourcesup.renater.fr/wiki/simol"

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