Bug 1546718 - [tryselect] Add ability to post-filter fuzzy presets interactively, r=jgraham
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Wed, 24 Apr 2019 19:36:03 +0000
changeset 530018 d27fb891cdbf69dcd8b7742e7a93dbaee6b093b8
parent 530017 83021d773da65cf00f6021d17b59eaf7cf622e36
child 530019 87d5204978fa6d1dc282ca53d9425336e5f747db
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1546718 - [tryselect] Add ability to post-filter fuzzy presets interactively, r=jgraham Differential Revision: https://phabricator.services.mozilla.com/D28713
--- a/tools/tryselect/docs/selectors/fuzzy.rst
+++ b/tools/tryselect/docs/selectors/fuzzy.rst
@@ -91,23 +91,46 @@ You can pass in multiple queries at once
 If instead you want the intersection of queries, you can pass in ``-x/--and``:
 .. code-block:: shell
     # selects all windows mochitest tasks
     $ mach try fuzzy --and -q "mochitest" -q "windows"
-Using query intersections is especially useful with presets:
+Modifying Presets
+:doc:`Presets <../presets>` make it easy to run a pre-determined set of tasks. But sometimes you
+might not want to run that set exactly as is, you may only want to use the preset as a starting
+point then add or remove tasks as needed. This can be accomplished with ``-q/--query`` or
+Here are some examples of adding tasks to a preset:
 .. code-block:: shell
-    # selects all windows perf tasks
+    # selects all perf tasks plus all mochitest-chrome tasks
+    $ mach try fuzzy --preset perf -q "mochitest-chrome"
+    # adds tasks to the perf preset interactively
+    $ mach try fuzzy --preset perf -i
+Similarly, ``-x/--and`` can be used to filter down a preset by taking the intersection of the two
+.. code-block:: shell
+    # limits perf tasks to windows only
     $ mach try fuzzy --preset perf -xq "windows"
+    # limits perf tasks interactively
+    $ mach try fuzzy --preset perf -xi
 Shell Conflicts
 Unfortunately ``fzf``'s query language uses some characters (namely ``'``, ``!`` and ``$``) that can
 interfere with your shell when using ``-q/--query``. Below are some tips for how to type out a query
 on the command line.
--- a/tools/tryselect/mach_commands.py
+++ b/tools/tryselect/mach_commands.py
@@ -250,16 +250,19 @@ class TrySelect(MachCommandBase):
           word$: exact suffix match (line must end with literal "word")
           !word: exact negation match (line must not contain literal "word")
           'a | 'b: OR operator (joins two exact match operators together)
         For example:
           ^start 'exact | !ignore fuzzy end$
+        if kwargs.pop('interactive'):
+            kwargs['query'].append('INTERACTIVE')
         if kwargs.pop('intersection'):
             kwargs['intersect_query'] = kwargs['query']
             del kwargs['query']
         if kwargs.get('save') and not kwargs.get('query'):
             # If saving preset without -q/--query, allow user to use the
             # interface to build the query.
             kwargs_copy = kwargs.copy()
--- a/tools/tryselect/selectors/fuzzy.py
+++ b/tools/tryselect/selectors/fuzzy.py
@@ -82,21 +82,28 @@ fzf_header_shortcuts = {
 class FuzzyParser(BaseTryParser):
     name = 'fuzzy'
     arguments = [
         [['-q', '--query'],
          {'metavar': 'STR',
           'action': 'append',
+          'default': [],
           'help': "Use the given query instead of entering the selection "
                   "interface. Equivalent to typing <query><ctrl-a><enter> "
                   "from the interface. Specifying multiple times schedules "
                   "the union of computed tasks.",
+        [['-i', '--interactive'],
+         {'action': 'store_true',
+          'default': False,
+          'help': "Force running fzf interactively even when using presets or "
+                  "queries with -q/--query."
+          }],
         [['-x', '--and'],
          {'dest': 'intersection',
           'action': 'store_true',
           'default': False,
           'help': "When specifying queries on the command line with -q/--query, "
                   "use the intersection of tasks rather than the union. This is "
                   "especially useful for post filtering presets.",
@@ -245,33 +252,34 @@ def run(update=False, query=None, inters
     if exact:
     selected = set()
     queries = []
-    def get_tasks(query_arg=None):
+    def get_tasks(query_arg=None, candidate_tasks=all_tasks):
         cmd = base_cmd[:]
-        if query_arg:
+        if query_arg and query_arg != 'INTERACTIVE':
             cmd.extend(['-f', query_arg])
-        query_str, tasks = run_fzf(cmd, all_tasks)
+        query_str, tasks = run_fzf(cmd, sorted(candidate_tasks))
         return set(tasks)
     for q in query or []:
         selected |= get_tasks(q)
     for q in intersect_query or []:
-        tasks = get_tasks(q)
         if not selected:
+            tasks = get_tasks(q)
             selected |= tasks
+            tasks = get_tasks(q, selected)
             selected &= tasks
     if not queries:
         selected = get_tasks()
     if not selected:
         print("no tasks selected")