Changeset 52131 in webkit


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

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

Reviewed by Eric Seidel.

[bzt] Kill WebKitApplyingScripts
https://bugs.webkit.org/show_bug.cgi?id=32467

Ah! I've been wanting to do this for a long time. This patch brings
the applying commands into the patch processing fold.

  • Scripts/bugzilla-tool:
  • Scripts/modules/buildsteps.py:
  • Scripts/modules/commands/download.py:
  • Scripts/modules/commands/download_unittest.py:
  • Scripts/modules/mock_bugzillatool.py:
Location:
trunk/WebKitTools
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKitTools/ChangeLog

    r52130 r52131  
     12009-12-14  Adam Barth  <abarth@webkit.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        [bzt] Kill WebKitApplyingScripts
     6        https://bugs.webkit.org/show_bug.cgi?id=32467
     7
     8        Ah!  I've been wanting to do this for a long time.  This patch brings
     9        the applying commands into the patch processing fold.
     10
     11        * Scripts/bugzilla-tool:
     12        * Scripts/modules/buildsteps.py:
     13        * Scripts/modules/commands/download.py:
     14        * Scripts/modules/commands/download_unittest.py:
     15        * Scripts/modules/mock_bugzillatool.py:
     16
    1172009-12-14  Adam Barth  <abarth@webkit.org>
    218
  • trunk/WebKitTools/Scripts/bugzilla-tool

    r51889 r52131  
    3535from modules.bugzilla import Bugzilla
    3636from modules.buildbot import BuildBot
    37 from modules.buildsteps import BuildSteps
    3837from modules.commands.download import *
    3938from modules.commands.early_warning_system import *
     
    5655        self._scm = None
    5756        self._status = None
    58         self.steps = BuildSteps()
    5957
    6058    def dry_run_callback(self, option, opt, value, parser):
  • trunk/WebKitTools/Scripts/modules/buildsteps.py

    r52130 r52131  
    4545    parent_command = make_option("--parent-command", action="store", dest="parent_command", default=None, help="(Internal) The command that spawned this instance.")
    4646    update = make_option("--no-update", action="store_false", dest="update", default=True, help="Don't update the working directory.")
     47    local_commit = make_option("--local-commit", action="store_true", dest="local_commit", default=False, help="Make a local commit for each applied patch")
    4748    build = make_option("--no-build", action="store_false", dest="build", default=True, help="Commit without building first, implies --no-test.")
    4849    test = make_option("--no-test", action="store_false", dest="test", default=True, help="Commit without running run-webkit-tests.")
     
    142143
    143144
     145class CleanWorkingDirectoryWithLocalCommitsStep(CleanWorkingDirectoryStep):
     146    def __init__(self, tool, options):
     147        # FIXME: This a bit of a hack.  Consider doing this more cleanly.
     148        CleanWorkingDirectoryStep.__init__(self, tool, options, allow_local_commits=True)
     149
     150
    144151class UpdateStep(AbstractStep):
    145152    @classmethod
     
    172179    def run(self, state):
    173180        self._tool.scm().apply_reverse_diff(state["revision"])
     181
     182
     183class ApplyPatchWithLocalCommitStep(ApplyPatchStep):
     184    @classmethod
     185    def options(cls):
     186        return [
     187            CommandOptions.local_commit,
     188        ] + ApplyPatchStep.options()
     189   
     190    def run(self, state):
     191        ApplyPatchStep.run(self, state)
     192        if self._options.local_commit:
     193            commit_message = self._tool.scm().commit_message_for_this_commit()
     194            self._tool.scm().commit_locally_with_message(commit_message.message() or state["patch"]["name"])
    174195
    175196
     
    355376        # FIXME: I'm not sure state["commit_text"] is quite right here.
    356377        self._tool.bugs.reopen_bug(bug_id, state["commit_text"])
    357 
    358 
    359 # FIXME: This class is a dinosaur and should be extinct soon.
    360 class BuildSteps:
    361     # FIXME: The options should really live on each "Step" object.
    362     @staticmethod
    363     def cleaning_options():
    364         return [
    365             CommandOptions.force_clean,
    366             CommandOptions.clean,
    367         ]
    368 
    369     # FIXME: These distinctions are bogus.  We need a better model for handling options.
    370     @staticmethod
    371     def build_options():
    372         return [
    373             CommandOptions.check_builders,
    374             CommandOptions.quiet,
    375             CommandOptions.non_interactive,
    376             CommandOptions.parent_command,
    377             CommandOptions.port,
    378         ]
    379 
    380     @staticmethod
    381     def land_options():
    382         return [
    383             CommandOptions.update,
    384             CommandOptions.build,
    385             CommandOptions.test,
    386             CommandOptions.close_bug,
    387         ]
    388 
  • trunk/WebKitTools/Scripts/modules/commands/download.py

    r52130 r52131  
    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, BuildSteps, EnsureBuildersAreGreenStep, UpdateChangelogsWithReviewerStep, CleanWorkingDirectoryStep, UpdateStep, ApplyPatchStep, BuildStep, CheckStyleStep, RunTestsStep, CommitStep, ClosePatchStep, CloseBugStep, CloseBugForLandDiffStep, PrepareChangelogStep, PrepareChangelogForRevertStep, RevertRevisionStep, CompleteRollout
     37from modules.buildsteps import CommandOptions, EnsureBuildersAreGreenStep, 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
     
    6060
    6161
    62 class ApplyAttachment(Command):
    63     name = "apply-attachment"
    64     show_in_main_help = True
    65     def __init__(self):
    66         options = WebKitApplyingScripts.apply_options()
    67         options += BuildSteps.cleaning_options()
    68         Command.__init__(self, "Apply an attachment to the local working directory", "ATTACHMENT_ID", options=options)
    69 
    70     def execute(self, options, args, tool):
    71         WebKitApplyingScripts.setup_for_patch_apply(tool, options)
    72         attachment_id = args[0]
    73         attachment = tool.bugs.fetch_attachment(attachment_id)
    74         WebKitApplyingScripts.apply_patches_with_options(tool.scm(), [attachment], options)
    75 
    76 
    77 class ApplyPatches(Command):
    78     name = "apply-patches"
    79     show_in_main_help = True
    80     def __init__(self):
    81         options = WebKitApplyingScripts.apply_options()
    82         options += BuildSteps.cleaning_options()
    83         Command.__init__(self, "Apply reviewed patches from provided bugs to the local working directory", "BUGID", options=options)
    84 
    85     def execute(self, options, args, tool):
    86         WebKitApplyingScripts.setup_for_patch_apply(tool, options)
    87         bug_id = args[0]
    88         patches = tool.bugs.fetch_reviewed_patches_from_bug(bug_id)
    89         WebKitApplyingScripts.apply_patches_with_options(tool.scm(), patches, options)
    90 
    91 
    92 class WebKitApplyingScripts:
    93     @staticmethod
    94     def apply_options():
    95         return [
    96             make_option("--no-update", action="store_false", dest="update", default=True, help="Don't update the working directory before applying patches"),
    97             make_option("--local-commit", action="store_true", dest="local_commit", default=False, help="Make a local commit for each applied patch"),
    98             CommandOptions.port,
    99         ]
    100 
    101     @staticmethod
    102     def setup_for_patch_apply(tool, options):
    103         clean_step = CleanWorkingDirectoryStep(tool, options, allow_local_commits=True)
    104         clean_step.run({})
    105         update_step = UpdateStep(tool, options)
    106         update_step.run({})
    107 
    108     @staticmethod
    109     def apply_patches_with_options(scm, patches, options):
    110         if options.local_commit and not scm.supports_local_commits():
    111             error("--local-commit passed, but %s does not support local commits" % scm.display_name())
    112 
    113         for patch in patches:
    114             log("Applying attachment %s from bug %s" % (patch["id"], patch["bug_id"]))
    115             scm.apply_patch(patch)
    116             if options.local_commit:
    117                 commit_message = scm.commit_message_for_this_commit()
    118                 scm.commit_locally_with_message(commit_message.message() or patch["name"])
    119 
    120 
    12162class LandDiff(Command):
    12263    name = "land-diff"
     
    220161        state = {"patch": patch}
    221162        self._sequence.run_and_handle_errors(tool, options, state)
     163
     164
     165class 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)
     176
     177    def _prepare_to_process(self, options, args, tool):
     178        if options.local_commit and not tool.scm().supports_local_commits():
     179            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)
     186
     187
     188class ApplyAttachment(AbstractPatchApplyingCommand):
     189    name = "apply-attachment"
     190    show_in_main_help = True
     191    def __init__(self):
     192        AbstractPatchApplyingCommand.__init__(self, "Apply an attachment to the local working directory", "ATTACHMENT_ID [ATTACHMENT_IDS]")
     193
     194    def _fetch_list_of_patches_to_process(self, options, args, tool):
     195        return map(lambda patch_id: tool.bugs.fetch_attachment(patch_id), args)
     196
     197
     198class ApplyPatches(AbstractPatchApplyingCommand):
     199    name = "apply-patches"
     200    show_in_main_help = True
     201    def __init__(self):
     202        AbstractPatchApplyingCommand.__init__(self, "Apply reviewed patches from provided bugs to the local working directory", "BUGID [BUGIDS]")
     203
     204    def _fetch_list_of_patches_to_process(self, options, args, tool):
     205        all_patches = []
     206        for bug_id in args:
     207            patches = tool.bugs.fetch_reviewed_patches_from_bug(bug_id)
     208            log("%s found on bug %s." % (pluralize("reviewed patch", len(patches)), bug_id))
     209            all_patches += patches
     210        return all_patches
    222211
    223212
  • trunk/WebKitTools/Scripts/modules/commands/download_unittest.py

    r52130 r52131  
    5656        options.update = True
    5757        options.local_commit = True
    58         expected_stderr = "Updating working directory\nApplying attachment 197 from bug 42\n"
     58        expected_stderr = "Updating working directory\nProcessing 1 patch from 1 bug.\nProcessing patch 197 from bug 42.\n"
    5959        self.assert_execute_outputs(ApplyAttachment(), [197], options=options, expected_stderr=expected_stderr)
    6060
     
    6363        options.update = True
    6464        options.local_commit = True
    65         expected_stderr = "Updating working directory\nApplying attachment 197 from bug 42\nApplying attachment 128 from bug 42\n"
     65        expected_stderr = "Updating working directory\n2 reviewed patches found on bug 42.\nProcessing 2 patches from 1 bug.\nProcessing patch 197 from bug 42.\nProcessing patch 128 from bug 42.\n"
    6666        self.assert_execute_outputs(ApplyPatches(), [42], options=options, expected_stderr=expected_stderr)
    6767
Note: See TracChangeset for help on using the changeset viewer.