blob: 07b9b2eb9bffe3adb21515b656b2de91e942dcc2 [file] [log] [blame]
Galina Kistanova063a0112016-06-21 00:08:18 +00001from twisted.python import log
2
3from buildbot.schedulers.filter import ChangeFilter
4from buildbot.schedulers.basic import SingleBranchScheduler
5
Galina Kistanova30fd3882016-08-19 22:43:51 +00006def getProjectsToFilter(projects):
7 # Here we could have "clang" project. In this case replace it by "cfe".
8 return [ p if p != "clang" else "cfe" for p in projects ]
9
Galina Kistanova063a0112016-06-21 00:08:18 +000010# Since we have many parametric builders, we dynamically build the minimum set
11# of schedulers, which covers all actually used combinations of dependencies.
12def getSingleBranchSchedulers(builders, schedulers, **kwargs):
13 """
14 I'm taking over all of not yet assigned builders with the
15 declared source code dependencies, and automatically generate
16 a minimum set of SingleBranchSchedulers to handle all the declared
17 source code dependency combinations.
18 """
19
20 # Prepare a list of builders which already have been assigned to schedulers.
21 builders_with_schedulers = {
22 b for s in schedulers for b in s.builderNames
23 }
24
25 builders_with_automatic_schedulers = []
26 for builder in builders:
27 # Only for the builders created with LLVMBuildFactory or similar.
28 if getattr(builder['factory'], 'depends_on_projects', None):
Galina Kistanova343ac762019-10-11 20:39:42 +000029 # And only if this builder is in the legacy mode and
30 # does not yet have an assigned scheduler.
31 if getattr(builder['factory'], 'is_legacy_mode', True) and \
32 builder['name'] not in builders_with_schedulers:
Galina Kistanova063a0112016-06-21 00:08:18 +000033 # This builder is a candidate for an automatic scheduler.
34 builders_with_automatic_schedulers.append(builder)
35
36 automatic_schedulers = []
37 # Do we have any to take care of?
38 if builders_with_automatic_schedulers:
39 # Let's reconsile first to get a unique set of dependencies.
40 # We need a set of unique sets of dependent projects.
41 set_of_dependencies = set([
42 frozenset(getattr(b['factory'], 'depends_on_projects'))
43 for b in builders_with_automatic_schedulers
44 ])
45
46 treeStableTimer = kwargs.get('treeStableTimer', 2*60)
47 automatic_schedulers = []
48 for projects in set_of_dependencies:
49 sch_builders = [
50 b['name']
51 for b in builders_with_automatic_schedulers
52 if frozenset(getattr(b['factory'], 'depends_on_projects')) == projects
53 ]
54
Galina Kistanova309e64b2018-11-14 05:30:37 +000055 automatic_scheduler_name = ",".join(sorted(projects))
Galina Kistanova30fd3882016-08-19 22:43:51 +000056 projects_to_filter = getProjectsToFilter(projects)
57
Galina Kistanova063a0112016-06-21 00:08:18 +000058 automatic_schedulers.append(
59 SingleBranchScheduler(
Galina Kistanova309e64b2018-11-14 05:30:37 +000060 name=automatic_scheduler_name,
Galina Kistanova063a0112016-06-21 00:08:18 +000061 treeStableTimer=treeStableTimer,
62 builderNames=sch_builders,
Galina Kistanova30fd3882016-08-19 22:43:51 +000063 change_filter=ChangeFilter(project=projects_to_filter)
Galina Kistanova063a0112016-06-21 00:08:18 +000064 )
65 )
66
67 log.msg(
Galina Kistanova309e64b2018-11-14 05:30:37 +000068 "Generated SingleBranchScheduler: { name='%s'" % automatic_scheduler_name,
Galina Kistanova063a0112016-06-21 00:08:18 +000069 ", builderNames=", sch_builders,
Galina Kistanova30fd3882016-08-19 22:43:51 +000070 ", change_filter=", projects_to_filter,
Galina Kistanova063a0112016-06-21 00:08:18 +000071 "}")
72 return automatic_schedulers