Changeset 52133 in webkit


Ignore:
Timestamp:
Dec 14, 2009 9:38:44 PM (14 years ago)
Author:
abarth@webkit.org
Message:

2009-12-14 Adam Barth <abarth@webkit.org>

Reviewed by Eric Seidel.

[bzt] Make download commands declarative
https://bugs.webkit.org/show_bug.cgi?id=32469

This patch "properly" factors most of the download commands. These
commands are now largely declarative, which is the final step of this
grand refactoring.

  • Scripts/modules/buildsteps.py:
  • Scripts/modules/commands/download.py:
Location:
trunk/WebKitTools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKitTools/ChangeLog

    r52132 r52133  
     12009-12-14  Adam Barth  <abarth@webkit.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        [bzt] Make download commands declarative
     6        https://bugs.webkit.org/show_bug.cgi?id=32469
     7
     8        This patch "properly" factors most of the download commands.  These
     9        commands are now largely declarative, which is the final step of this
     10        grand refactoring.
     11
     12        * Scripts/modules/buildsteps.py:
     13        * Scripts/modules/commands/download.py:
     14
    1152009-12-14  Adam Barth  <abarth@webkit.org>
    216
  • trunk/WebKitTools/Scripts/modules/buildsteps.py

    r52131 r52133  
    212212
    213213
     214class EnsureLocalCommitIfNeeded(AbstractStep):
     215    @classmethod
     216    def options(cls):
     217        return [
     218            CommandOptions.local_commit,
     219        ]
     220
     221    def run(self, state):
     222        if self._options.local_commit and not self._tool.scm().supports_local_commits():
     223            error("--local-commit passed, but %s does not support local commits" % self._tool.scm.display_name())
     224
     225
    214226class UpdateChangelogsWithReviewerStep(AbstractStep):
    215227    @classmethod
  • trunk/WebKitTools/Scripts/modules/commands/download.py

    r52132 r52133  
    3535from modules.bugzilla import parse_bug_id
    3636# FIXME: This list is rediculous.  We need to learn the ways of __all__.
    37 from modules.buildsteps import CommandOptions, EnsureBuildersAreGreenStep, UpdateChangelogsWithReviewerStep, CleanWorkingDirectoryStep, CleanWorkingDirectoryWithLocalCommitsStep, UpdateStep, ApplyPatchStep, ApplyPatchWithLocalCommitStep, BuildStep, CheckStyleStep, RunTestsStep, CommitStep, ClosePatchStep, CloseBugStep, CloseBugForLandDiffStep, PrepareChangelogStep, PrepareChangelogForRevertStep, RevertRevisionStep, CompleteRollout
     37from modules.buildsteps import CommandOptions, EnsureBuildersAreGreenStep, EnsureLocalCommitIfNeeded, UpdateChangelogsWithReviewerStep, CleanWorkingDirectoryStep, CleanWorkingDirectoryWithLocalCommitsStep, UpdateStep, ApplyPatchStep, ApplyPatchWithLocalCommitStep, BuildStep, CheckStyleStep, RunTestsStep, CommitStep, ClosePatchStep, CloseBugStep, CloseBugForLandDiffStep, PrepareChangelogStep, PrepareChangelogForRevertStep, RevertRevisionStep, CompleteRollout
    3838from modules.changelogs import ChangeLog
    3939from modules.comments import bug_comment_from_commit_text
     
    4545
    4646
    47 class Build(Command):
     47# FIXME: Move this to a more general location.
     48class AbstractDeclarativeCommmand(Command):
     49    help_text = None
     50    argument_names = None
     51    def __init__(self, options):
     52        Command.__init__(self, self.help_text, self.argument_names, options)
     53
     54
     55class AbstractSequencedCommmand(AbstractDeclarativeCommmand):
     56    steps = None
     57    def __init__(self):
     58        self._sequence = StepSequence(self.steps)
     59        AbstractDeclarativeCommmand.__init__(self, self._sequence.options())
     60
     61    def _prepare_state(self, options, args, tool):
     62        return None
     63
     64    def execute(self, options, args, tool):
     65        self._sequence.run_and_handle_errors(tool, options, self._prepare_state(options, args, tool))
     66
     67
     68class Build(AbstractSequencedCommmand):
    4869    name = "build"
     70    help_text = "Update working copy and build"
     71    argument_names = ""
    4972    show_in_main_help = False
    50     def __init__(self):
    51         self._sequence = StepSequence([
    52             CleanWorkingDirectoryStep,
    53             UpdateStep,
    54             BuildStep
    55         ])
    56         Command.__init__(self, "Update working copy and build", "", self._sequence.options())
    57 
    58     def execute(self, options, args, tool):
    59         self._sequence.run_and_handle_errors(tool, options)
    60 
    61 
    62 class LandDiff(Command):
     73    steps = [
     74        CleanWorkingDirectoryStep,
     75        UpdateStep,
     76        BuildStep,
     77    ]
     78
     79
     80class LandDiff(AbstractSequencedCommmand):
    6381    name = "land-diff"
    64     show_in_main_help = True
    65     def __init__(self):
    66         self._sequence = StepSequence([
    67             EnsureBuildersAreGreenStep,
    68             UpdateChangelogsWithReviewerStep,
    69             EnsureBuildersAreGreenStep,
    70             BuildStep,
    71             RunTestsStep,
    72             CommitStep,
    73             CloseBugForLandDiffStep,
    74         ])
    75         Command.__init__(self, "Land the current working directory diff and updates the associated bug if any", "[BUGID]", options=self._sequence.options())
    76 
    77     def execute(self, options, args, tool):
    78         bug_id = (args and args[0]) or parse_bug_id(tool.scm().create_patch())
    79         fake_patch = {
    80             "id": None,
    81             "bug_id": bug_id,
     82    help_text = "Land the current working directory diff and updates the associated bug if any"
     83    argument_names = "[BUGID]"
     84    show_in_main_help = True
     85    steps = [
     86        EnsureBuildersAreGreenStep,
     87        UpdateChangelogsWithReviewerStep,
     88        EnsureBuildersAreGreenStep,
     89        BuildStep,
     90        RunTestsStep,
     91        CommitStep,
     92        CloseBugForLandDiffStep,
     93    ]
     94
     95    def _prepare_state(self, options, args, tool):
     96        return {
     97            "patch": {
     98                "id": None,
     99                "bug_id": (args and args[0]) or parse_bug_id(tool.scm().create_patch()),
     100            }
    82101        }
    83         state = {"patch": fake_patch}
    84         self._sequence.run_and_handle_errors(tool, options, state)
    85 
    86 
    87 class AbstractPatchProcessingCommand(Command):
    88     def __init__(self, help_text, args_description, options):
    89         Command.__init__(self, help_text, args_description, options=options)
    90 
    91     def _fetch_list_of_patches_to_process(self, options, args, tool):
    92         raise NotImplementedError, "subclasses must implement"
    93 
    94     def _prepare_to_process(self, options, args, tool):
    95         raise NotImplementedError, "subclasses must implement"
     102
     103
     104class AbstractPatchProcessingCommand(AbstractDeclarativeCommmand):
     105    # Subclasses must implement the methods below.  We don't declare them here
     106    # because we want to be able to implement them with mix-ins.
     107    #
     108    # def _fetch_list_of_patches_to_process(self, options, args, tool):
     109    # def _prepare_to_process(self, options, args, tool):
    96110
    97111    @staticmethod
     
    126140        return step_sequence, step_sequence.options()
    127141
    128     def __init__(self, help_text, args_description):
     142    def __init__(self):
    129143        options = []
    130144        self._prepare_sequence, prepare_options = self._create_step_sequence(self.prepare_steps)
    131145        self._main_sequence, main_options = self._create_step_sequence(self.main_steps)
    132146        options = sorted(set(prepare_options + main_options))
    133         AbstractPatchProcessingCommand.__init__(self, help_text, args_description, options)
     147        AbstractPatchProcessingCommand.__init__(self, options)
    134148
    135149    def _prepare_to_process(self, options, args, tool):
     
    143157
    144158
    145 class CheckStyle(AbstractPatchSequencingCommand):
    146     name = "check-style"
    147     show_in_main_help = False
    148     main_steps = [
    149         CleanWorkingDirectoryStep,
    150         UpdateStep,
    151         ApplyPatchStep,
    152         CheckStyleStep,
    153     ]
    154     def __init__(self):
    155         AbstractPatchSequencingCommand.__init__(self, "Run check-webkit-style on the specified attachments", "ATTACHMENT_ID [ATTACHMENT_IDS]")
    156 
     159class ProcessAttachmentsMixin(object):
    157160    def _fetch_list_of_patches_to_process(self, options, args, tool):
    158161        return map(lambda patch_id: tool.bugs.fetch_attachment(patch_id), args)
    159162
    160163
    161 class BuildAttachment(AbstractPatchSequencingCommand):
    162     name = "build-attachment"
    163     show_in_main_help = False
    164     main_steps = [
    165         CleanWorkingDirectoryStep,
    166         UpdateStep,
    167         ApplyPatchStep,
    168         BuildStep,
    169     ]
    170     def __init__(self):
    171         AbstractPatchSequencingCommand.__init__(self, "Apply and build patches from bugzilla", "ATTACHMENT_ID [ATTACHMENT_IDS]")
    172 
    173     def _fetch_list_of_patches_to_process(self, options, args, tool):
    174         return map(lambda patch_id: tool.bugs.fetch_attachment(patch_id), args)
    175 
    176 
    177 class AbstractPatchApplyingCommand(AbstractPatchSequencingCommand):
    178     prepare_steps = [
    179         CleanWorkingDirectoryWithLocalCommitsStep,
    180         UpdateStep,
    181     ]
    182     main_steps = [
    183         ApplyPatchWithLocalCommitStep,
    184     ]
    185 
    186     def _prepare_to_process(self, options, args, tool):
    187         if options.local_commit and not tool.scm().supports_local_commits():
    188             error("--local-commit passed, but %s does not support local commits" % scm.display_name())
    189         AbstractPatchSequencingCommand._prepare_to_process(self, options, args, tool)
    190 
    191 
    192 class ApplyAttachment(AbstractPatchApplyingCommand):
    193     name = "apply-attachment"
    194     show_in_main_help = True
    195     def __init__(self):
    196         AbstractPatchApplyingCommand.__init__(self, "Apply an attachment to the local working directory", "ATTACHMENT_ID [ATTACHMENT_IDS]")
    197 
    198     def _fetch_list_of_patches_to_process(self, options, args, tool):
    199         return map(lambda patch_id: tool.bugs.fetch_attachment(patch_id), args)
    200 
    201 
    202 class ApplyPatches(AbstractPatchApplyingCommand):
    203     name = "apply-patches"
    204     show_in_main_help = True
    205     def __init__(self):
    206         AbstractPatchApplyingCommand.__init__(self, "Apply reviewed patches from provided bugs to the local working directory", "BUGID [BUGIDS]")
    207 
     164class ProcessBugsMixin(object):
    208165    def _fetch_list_of_patches_to_process(self, options, args, tool):
    209166        all_patches = []
     
    215172
    216173
     174class CheckStyle(AbstractPatchSequencingCommand, ProcessAttachmentsMixin):
     175    name = "check-style"
     176    help_text = "Run check-webkit-style on the specified attachments"
     177    argument_names = "ATTACHMENT_ID [ATTACHMENT_IDS]"
     178    show_in_main_help = False
     179    main_steps = [
     180        CleanWorkingDirectoryStep,
     181        UpdateStep,
     182        ApplyPatchStep,
     183        CheckStyleStep,
     184    ]
     185
     186
     187class BuildAttachment(AbstractPatchSequencingCommand, ProcessAttachmentsMixin):
     188    name = "build-attachment"
     189    help_text = "Apply and build patches from bugzilla"
     190    argument_names = "ATTACHMENT_ID [ATTACHMENT_IDS]"
     191    show_in_main_help = False
     192    main_steps = [
     193        CleanWorkingDirectoryStep,
     194        UpdateStep,
     195        ApplyPatchStep,
     196        BuildStep,
     197    ]
     198
     199
     200class AbstractPatchApplyingCommand(AbstractPatchSequencingCommand):
     201    prepare_steps = [
     202        EnsureLocalCommitIfNeeded,
     203        CleanWorkingDirectoryWithLocalCommitsStep,
     204        UpdateStep,
     205    ]
     206    main_steps = [
     207        ApplyPatchWithLocalCommitStep,
     208    ]
     209
     210
     211class ApplyAttachment(AbstractPatchApplyingCommand, ProcessAttachmentsMixin):
     212    name = "apply-attachment"
     213    help_text = "Apply an attachment to the local working directory"
     214    argument_names = "ATTACHMENT_ID [ATTACHMENT_IDS]"
     215    show_in_main_help = True
     216
     217
     218class ApplyPatches(AbstractPatchApplyingCommand, ProcessBugsMixin):
     219    name = "apply-patches"
     220    help_text = "Apply reviewed patches from provided bugs to the local working directory"
     221    argument_names = "BUGID [BUGIDS]"
     222    show_in_main_help = True
     223
     224
    217225class AbstractPatchLandingCommand(AbstractPatchSequencingCommand):
    218226    prepare_steps = [
     
    232240
    233241
    234 class LandAttachment(AbstractPatchLandingCommand):
     242class LandAttachment(AbstractPatchLandingCommand, ProcessAttachmentsMixin):
    235243    name = "land-attachment"
    236     show_in_main_help = True
    237     def __init__(self):
    238         AbstractPatchLandingCommand.__init__(self, "Land patches from bugzilla, optionally building and testing them first", "ATTACHMENT_ID [ATTACHMENT_IDS]")
    239 
    240     def _fetch_list_of_patches_to_process(self, options, args, tool):
    241         return map(lambda patch_id: tool.bugs.fetch_attachment(patch_id), args)
    242 
    243 
    244 class LandPatches(AbstractPatchLandingCommand):
     244    help_text = "Land patches from bugzilla, optionally building and testing them first"
     245    argument_names = "ATTACHMENT_ID [ATTACHMENT_IDS]"
     246    show_in_main_help = True
     247
     248
     249class LandPatches(AbstractPatchLandingCommand, ProcessBugsMixin):
    245250    name = "land-patches"
    246     show_in_main_help = True
    247     def __init__(self):
    248         AbstractPatchLandingCommand.__init__(self, "Land all patches on the given bugs, optionally building and testing them first", "BUGID [BUGIDS]")
    249 
    250     def _fetch_list_of_patches_to_process(self, options, args, tool):
    251         all_patches = []
    252         for bug_id in args:
    253             patches = tool.bugs.fetch_reviewed_patches_from_bug(bug_id)
    254             log("%s found on bug %s." % (pluralize("reviewed patch", len(patches)), bug_id))
    255             all_patches += patches
    256         return all_patches
    257 
    258 
     251    help_text = "Land all patches on the given bugs, optionally building and testing them first"
     252    argument_names = "BUGID [BUGIDS]"
     253    show_in_main_help = True
     254
     255
     256# FIXME: Make Rollout more declarative.
    259257class Rollout(Command):
    260258    name = "rollout"
Note: See TracChangeset for help on using the changeset viewer.