Galina Kistanova | 063a011 | 2016-06-21 00:08:18 +0000 | [diff] [blame] | 1 | from twisted.python import log |
| 2 | |
| 3 | from buildbot.schedulers.filter import ChangeFilter |
| 4 | from buildbot.schedulers.basic import SingleBranchScheduler |
| 5 | |
Galina Kistanova | 30fd388 | 2016-08-19 22:43:51 +0000 | [diff] [blame] | 6 | def 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 Kistanova | 063a011 | 2016-06-21 00:08:18 +0000 | [diff] [blame] | 10 | # Since we have many parametric builders, we dynamically build the minimum set |
| 11 | # of schedulers, which covers all actually used combinations of dependencies. |
| 12 | def 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 Kistanova | 343ac76 | 2019-10-11 20:39:42 +0000 | [diff] [blame^] | 29 | # 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 Kistanova | 063a011 | 2016-06-21 00:08:18 +0000 | [diff] [blame] | 33 | # 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 Kistanova | 309e64b | 2018-11-14 05:30:37 +0000 | [diff] [blame] | 55 | automatic_scheduler_name = ",".join(sorted(projects)) |
Galina Kistanova | 30fd388 | 2016-08-19 22:43:51 +0000 | [diff] [blame] | 56 | projects_to_filter = getProjectsToFilter(projects) |
| 57 | |
Galina Kistanova | 063a011 | 2016-06-21 00:08:18 +0000 | [diff] [blame] | 58 | automatic_schedulers.append( |
| 59 | SingleBranchScheduler( |
Galina Kistanova | 309e64b | 2018-11-14 05:30:37 +0000 | [diff] [blame] | 60 | name=automatic_scheduler_name, |
Galina Kistanova | 063a011 | 2016-06-21 00:08:18 +0000 | [diff] [blame] | 61 | treeStableTimer=treeStableTimer, |
| 62 | builderNames=sch_builders, |
Galina Kistanova | 30fd388 | 2016-08-19 22:43:51 +0000 | [diff] [blame] | 63 | change_filter=ChangeFilter(project=projects_to_filter) |
Galina Kistanova | 063a011 | 2016-06-21 00:08:18 +0000 | [diff] [blame] | 64 | ) |
| 65 | ) |
| 66 | |
| 67 | log.msg( |
Galina Kistanova | 309e64b | 2018-11-14 05:30:37 +0000 | [diff] [blame] | 68 | "Generated SingleBranchScheduler: { name='%s'" % automatic_scheduler_name, |
Galina Kistanova | 063a011 | 2016-06-21 00:08:18 +0000 | [diff] [blame] | 69 | ", builderNames=", sch_builders, |
Galina Kistanova | 30fd388 | 2016-08-19 22:43:51 +0000 | [diff] [blame] | 70 | ", change_filter=", projects_to_filter, |
Galina Kistanova | 063a011 | 2016-06-21 00:08:18 +0000 | [diff] [blame] | 71 | "}") |
| 72 | return automatic_schedulers |