blob: 0bcae8b37a331b2108f523bb3f5bc5d6df17e410 [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 = []
Galina Kistanova4f59d772019-10-18 05:51:12 +000026 legacy_builders_with_automatic_schedulers = []
Galina Kistanova063a0112016-06-21 00:08:18 +000027 for builder in builders:
28 # Only for the builders created with LLVMBuildFactory or similar.
29 if getattr(builder['factory'], 'depends_on_projects', None):
Galina Kistanova4f59d772019-10-18 05:51:12 +000030 if getattr(builder['factory'], 'is_legacy_mode', True):
31 # Only if this builder is in the legacy mode and
32 # does not yet have an assigned scheduler.
33 if builder['name'] not in builders_with_schedulers:
34 legacy_builders_with_automatic_schedulers.append(builder)
35 else:
36 # There are no manually assigned schedulers in this case.
Galina Kistanova063a0112016-06-21 00:08:18 +000037 builders_with_automatic_schedulers.append(builder)
38
39 automatic_schedulers = []
Galina Kistanova4f59d772019-10-18 05:51:12 +000040 automatic_schedulers.extend(
41 _getSingleBranchAutomaticSchedulers(
42 builders_with_automatic_schedulers,
43 filter_branch='master', # git monorepo branch.
44 treeStableTimer=kwargs.get('treeStableTimer', 2*60)))
45 automatic_schedulers.extend(
46 _getSingleBranchAutomaticSchedulers(
47 legacy_builders_with_automatic_schedulers,
48 filter_branch='trunk', # svn repo branch.
49 treeStableTimer=kwargs.get('treeStableTimer', 2*60)))
50
51 return automatic_schedulers
52
53def _getSingleBranchAutomaticSchedulers(
54 builders_with_automatic_schedulers,
55 filter_branch,
56 treeStableTimer):
57
58 automatic_schedulers = []
59
Galina Kistanova063a0112016-06-21 00:08:18 +000060 # Do we have any to take care of?
61 if builders_with_automatic_schedulers:
62 # Let's reconsile first to get a unique set of dependencies.
63 # We need a set of unique sets of dependent projects.
64 set_of_dependencies = set([
65 frozenset(getattr(b['factory'], 'depends_on_projects'))
66 for b in builders_with_automatic_schedulers
67 ])
68
Galina Kistanova063a0112016-06-21 00:08:18 +000069 for projects in set_of_dependencies:
70 sch_builders = [
71 b['name']
72 for b in builders_with_automatic_schedulers
73 if frozenset(getattr(b['factory'], 'depends_on_projects')) == projects
74 ]
75
Galina Kistanova4f59d772019-10-18 05:51:12 +000076 automatic_scheduler_name = filter_branch + ":" + ",".join(sorted(projects))
Galina Kistanova30fd3882016-08-19 22:43:51 +000077 projects_to_filter = getProjectsToFilter(projects)
78
Galina Kistanova063a0112016-06-21 00:08:18 +000079 automatic_schedulers.append(
80 SingleBranchScheduler(
Galina Kistanova309e64b2018-11-14 05:30:37 +000081 name=automatic_scheduler_name,
Galina Kistanova063a0112016-06-21 00:08:18 +000082 treeStableTimer=treeStableTimer,
83 builderNames=sch_builders,
Galina Kistanova4f59d772019-10-18 05:51:12 +000084 change_filter=ChangeFilter(project=projects_to_filter, branch=filter_branch)
Galina Kistanova063a0112016-06-21 00:08:18 +000085 )
86 )
87
88 log.msg(
Galina Kistanova309e64b2018-11-14 05:30:37 +000089 "Generated SingleBranchScheduler: { name='%s'" % automatic_scheduler_name,
Galina Kistanova063a0112016-06-21 00:08:18 +000090 ", builderNames=", sch_builders,
Galina Kistanova4f59d772019-10-18 05:51:12 +000091 ", change_filter=", projects_to_filter, " (branch: %s)" % filter_branch,
Galina Kistanova063a0112016-06-21 00:08:18 +000092 "}")
93 return automatic_schedulers