Changeset 52132 in webkit


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

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

Reviewed by Eric Seidel.

[bzt] Add AbstractPatchSequencingCommand to remove redundant code
https://bugs.webkit.org/show_bug.cgi?id=32468

Redundant code is bad. This patch moves us towards more declarative
commands.

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

Legend:

Unmodified
Added
Removed
  • trunk/WebKitTools/ChangeLog

    r52131 r52132  
     12009-12-14  Adam Barth  <abarth@webkit.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        [bzt] Add AbstractPatchSequencingCommand to remove redundant code
     6        https://bugs.webkit.org/show_bug.cgi?id=32468
     7
     8        Redundant code is bad.  This patch moves us towards more declarative
     9        commands.
     10
     11        * Scripts/modules/commands/download.py:
     12
    1132009-12-14  Adam Barth  <abarth@webkit.org>
    214
  • trunk/WebKitTools/Scripts/modules/commands/download.py

    r52131 r52132  
    115115
    116116
    117 class CheckStyle(AbstractPatchProcessingCommand):
     117class AbstractPatchSequencingCommand(AbstractPatchProcessingCommand):
     118    prepare_steps = None
     119    main_steps = None
     120
     121    @staticmethod
     122    def _create_step_sequence(steps):
     123        if not steps:
     124            return None, []
     125        step_sequence = StepSequence(steps)
     126        return step_sequence, step_sequence.options()
     127
     128    def __init__(self, help_text, args_description):
     129        options = []
     130        self._prepare_sequence, prepare_options = self._create_step_sequence(self.prepare_steps)
     131        self._main_sequence, main_options = self._create_step_sequence(self.main_steps)
     132        options = sorted(set(prepare_options + main_options))
     133        AbstractPatchProcessingCommand.__init__(self, help_text, args_description, options)
     134
     135    def _prepare_to_process(self, options, args, tool):
     136        if self._prepare_sequence:
     137            self._prepare_sequence.run_and_handle_errors(tool, options)
     138
     139    def _process_patch(self, patch, options, args, tool):
     140        if self._main_sequence:
     141            state = {"patch": patch}
     142            self._main_sequence.run_and_handle_errors(tool, options, state)
     143
     144
     145class CheckStyle(AbstractPatchSequencingCommand):
    118146    name = "check-style"
    119147    show_in_main_help = False
    120     def __init__(self):
    121         self._sequence = StepSequence([
    122             CleanWorkingDirectoryStep,
    123             UpdateStep,
    124             ApplyPatchStep,
    125             CheckStyleStep,
    126         ])
    127         AbstractPatchProcessingCommand.__init__(self, "Run check-webkit-style on the specified attachments", "ATTACHMENT_ID [ATTACHMENT_IDS]", self._sequence.options())
    128 
    129     def _fetch_list_of_patches_to_process(self, options, args, tool):
    130         return map(lambda patch_id: tool.bugs.fetch_attachment(patch_id), args)
    131 
    132     def _prepare_to_process(self, options, args, tool):
    133         pass
    134 
    135     # FIXME: Add a base class to share this code.
    136     def _process_patch(self, patch, options, args, tool):
    137         state = {"patch": patch}
    138         self._sequence.run_and_handle_errors(tool, options, state)
    139 
    140 
    141 class BuildAttachment(AbstractPatchProcessingCommand):
     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
     157    def _fetch_list_of_patches_to_process(self, options, args, tool):
     158        return map(lambda patch_id: tool.bugs.fetch_attachment(patch_id), args)
     159
     160
     161class BuildAttachment(AbstractPatchSequencingCommand):
    142162    name = "build-attachment"
    143163    show_in_main_help = False
    144     def __init__(self):
    145         self._sequence = StepSequence([
    146             CleanWorkingDirectoryStep,
    147             UpdateStep,
    148             ApplyPatchStep,
    149             BuildStep,
    150         ])
    151         AbstractPatchProcessingCommand.__init__(self, "Apply and build patches from bugzilla", "ATTACHMENT_ID [ATTACHMENT_IDS]", self._sequence.options())
    152 
    153     def _fetch_list_of_patches_to_process(self, options, args, tool):
    154         return map(lambda patch_id: tool.bugs.fetch_attachment(patch_id), args)
    155 
    156     def _prepare_to_process(self, options, args, tool):
    157         pass
    158 
    159     # FIXME: Add a base class to share this code.
    160     def _process_patch(self, patch, options, args, tool):
    161         state = {"patch": patch}
    162         self._sequence.run_and_handle_errors(tool, options, state)
    163 
    164 
    165 class AbstractPatchApplyingCommand(AbstractPatchProcessingCommand):
    166     def __init__(self, help_text, args_description):
    167         self._prepare_sequence = StepSequence([
    168             CleanWorkingDirectoryWithLocalCommitsStep,
    169             UpdateStep,
    170         ])
    171         self._main_sequence  = StepSequence([
    172             ApplyPatchWithLocalCommitStep,
    173         ])
    174         options = sorted(set(self._prepare_sequence.options() + self._main_sequence.options()))
    175         AbstractPatchProcessingCommand.__init__(self, help_text, args_description, options)
     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
     177class AbstractPatchApplyingCommand(AbstractPatchSequencingCommand):
     178    prepare_steps = [
     179        CleanWorkingDirectoryWithLocalCommitsStep,
     180        UpdateStep,
     181    ]
     182    main_steps = [
     183        ApplyPatchWithLocalCommitStep,
     184    ]
    176185
    177186    def _prepare_to_process(self, options, args, tool):
    178187        if options.local_commit and not tool.scm().supports_local_commits():
    179188            error("--local-commit passed, but %s does not support local commits" % scm.display_name())
    180         self._prepare_sequence.run_and_handle_errors(tool, options)
    181 
    182     # FIXME: Add a base class to share this code.
    183     def _process_patch(self, patch, options, args, tool):
    184         state = {"patch": patch}
    185         self._main_sequence.run_and_handle_errors(tool, options, state)
     189        AbstractPatchSequencingCommand._prepare_to_process(self, options, args, tool)
    186190
    187191
     
    211215
    212216
    213 class AbstractPatchLandingCommand(AbstractPatchProcessingCommand):
    214     def __init__(self, help_text, args_description):
    215         self._sequence = StepSequence([
    216             CleanWorkingDirectoryStep,
    217             UpdateStep,
    218             ApplyPatchStep,
    219             EnsureBuildersAreGreenStep,
    220             BuildStep,
    221             RunTestsStep,
    222             CommitStep,
    223             ClosePatchStep,
    224             CloseBugStep,
    225         ])
    226         AbstractPatchProcessingCommand.__init__(self, help_text, args_description, self._sequence.options())
    227 
    228     def _prepare_to_process(self, options, args, tool):
    229         # Check the tree status first so we can fail early.
    230         EnsureBuildersAreGreenStep(tool, options).run({})
    231 
    232     # FIXME: Add a base class to share this code.
    233     def _process_patch(self, patch, options, args, tool):
    234         state = {"patch": patch}
    235         self._sequence.run_and_handle_errors(tool, options, state)
     217class AbstractPatchLandingCommand(AbstractPatchSequencingCommand):
     218    prepare_steps = [
     219        EnsureBuildersAreGreenStep,
     220    ]
     221    main_steps = [
     222        CleanWorkingDirectoryStep,
     223        UpdateStep,
     224        ApplyPatchStep,
     225        EnsureBuildersAreGreenStep,
     226        BuildStep,
     227        RunTestsStep,
     228        CommitStep,
     229        ClosePatchStep,
     230        CloseBugStep,
     231    ]
    236232
    237233
Note: See TracChangeset for help on using the changeset viewer.