Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure dynamic Buildbot steps have unique names #525

Merged
merged 1 commit into from Oct 28, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -1,3 +1,4 @@
import collections
import copy
import re

@@ -85,17 +86,47 @@ def run(self):
))

pkill_step = [self.make_pkill_step("servo")]

for step in pkill_step + dynamic_steps:
self.add_step(step)
self.add_steps(pkill_step + dynamic_steps)

defer.returnValue(result)

def add_step(self, step):
def add_steps(self, steps):
"""\
Adds new steps to this build, making sure to avoid name collisions
by adding counts to disambiguate multiple steps of the same type,
and respecting internal Buildbot invariants.
Semi-polyfill for addStepsAfterLastStep from Buildbot 9.
"""

def step_type(step):
return step.name.split('__')[0]

name_counts = collections.Counter()

# Check for existing max step counts for each type of step
# in the existing steps on the build.
# Adding multiple steps at the same time makes it more efficient
# to check for collisions since this is amortized over all
# steps added together.
for step in self.build.steps:
name_counts[step_type(step)] += 1

# Add new steps, updating `name_counts` along the way
for step in steps:
existing_count = name_counts[step_type(step)]
if existing_count > 0:
# First step has count = 0 but no suffix,
# so second step will have `__1` as suffix, etc.
step.name += '__{}'.format(existing_count)
name_counts[step_type(step)] += 1
self._add_step(self, step)

def _add_step(self, step):
"""\
Adds a new step to this build, making sure to maintain internal
Buildbot invariants.
Semi-polyfill for addStepsAfterLastStep from Buildbot 9.
Do not call this method directly, but go through add_steps
to prevent `name` collisions.
"""
step.setBuild(self.build)
step.setBuildSlave(self.build.slavebuilder.slave)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.