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 = [] |
Galina Kistanova | 4f59d77 | 2019-10-18 05:51:12 +0000 | [diff] [blame^] | 26 | legacy_builders_with_automatic_schedulers = [] |
Galina Kistanova | 063a011 | 2016-06-21 00:08:18 +0000 | [diff] [blame] | 27 | for builder in builders: |
| 28 | # Only for the builders created with LLVMBuildFactory or similar. |
| 29 | if getattr(builder['factory'], 'depends_on_projects', None): |
Galina Kistanova | 4f59d77 | 2019-10-18 05:51:12 +0000 | [diff] [blame^] | 30 | 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 Kistanova | 063a011 | 2016-06-21 00:08:18 +0000 | [diff] [blame] | 37 | builders_with_automatic_schedulers.append(builder) |
| 38 | |
| 39 | automatic_schedulers = [] |
Galina Kistanova | 4f59d77 | 2019-10-18 05:51:12 +0000 | [diff] [blame^] | 40 | 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 | |
| 53 | def _getSingleBranchAutomaticSchedulers( |
| 54 | builders_with_automatic_schedulers, |
| 55 | filter_branch, |
| 56 | treeStableTimer): |
| 57 | |
| 58 | automatic_schedulers = [] |
| 59 | |
Galina Kistanova | 063a011 | 2016-06-21 00:08:18 +0000 | [diff] [blame] | 60 | # 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 Kistanova | 063a011 | 2016-06-21 00:08:18 +0000 | [diff] [blame] | 69 | 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 Kistanova | 4f59d77 | 2019-10-18 05:51:12 +0000 | [diff] [blame^] | 76 | automatic_scheduler_name = filter_branch + ":" + ",".join(sorted(projects)) |
Galina Kistanova | 30fd388 | 2016-08-19 22:43:51 +0000 | [diff] [blame] | 77 | projects_to_filter = getProjectsToFilter(projects) |
| 78 | |
Galina Kistanova | 063a011 | 2016-06-21 00:08:18 +0000 | [diff] [blame] | 79 | automatic_schedulers.append( |
| 80 | SingleBranchScheduler( |
Galina Kistanova | 309e64b | 2018-11-14 05:30:37 +0000 | [diff] [blame] | 81 | name=automatic_scheduler_name, |
Galina Kistanova | 063a011 | 2016-06-21 00:08:18 +0000 | [diff] [blame] | 82 | treeStableTimer=treeStableTimer, |
| 83 | builderNames=sch_builders, |
Galina Kistanova | 4f59d77 | 2019-10-18 05:51:12 +0000 | [diff] [blame^] | 84 | change_filter=ChangeFilter(project=projects_to_filter, branch=filter_branch) |
Galina Kistanova | 063a011 | 2016-06-21 00:08:18 +0000 | [diff] [blame] | 85 | ) |
| 86 | ) |
| 87 | |
| 88 | log.msg( |
Galina Kistanova | 309e64b | 2018-11-14 05:30:37 +0000 | [diff] [blame] | 89 | "Generated SingleBranchScheduler: { name='%s'" % automatic_scheduler_name, |
Galina Kistanova | 063a011 | 2016-06-21 00:08:18 +0000 | [diff] [blame] | 90 | ", builderNames=", sch_builders, |
Galina Kistanova | 4f59d77 | 2019-10-18 05:51:12 +0000 | [diff] [blame^] | 91 | ", change_filter=", projects_to_filter, " (branch: %s)" % filter_branch, |
Galina Kistanova | 063a011 | 2016-06-21 00:08:18 +0000 | [diff] [blame] | 92 | "}") |
| 93 | return automatic_schedulers |