Bug 1533770 - [fuzzy] Fix query intersection when running presets with multiple queries, r=jgraham
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Tue, 12 Mar 2019 19:33:36 +0000
changeset 521594 83169352c088284bbe4fe38bd130eff2c3a01007
parent 521593 f4017be29bbd38d93d900c4854ba51c53ce4b39b
child 521595 15affcdf9d0ddb0a40c984b023dd688db2ac8911
push id10867
push userdvarga@mozilla.com
push dateThu, 14 Mar 2019 15:20:45 +0000
treeherdermozilla-beta@abad13547875 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgraham
bugs1533770
milestone67.0a1
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 1533770 - [fuzzy] Fix query intersection when running presets with multiple queries, r=jgraham Differential Revision: https://phabricator.services.mozilla.com/D22741
tools/tryselect/mach_commands.py
tools/tryselect/selectors/fuzzy.py
tools/tryselect/test/test_fuzzy.t
--- a/tools/tryselect/mach_commands.py
+++ b/tools/tryselect/mach_commands.py
@@ -236,16 +236,20 @@ 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('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()
             kwargs_copy['push'] = False
             kwargs_copy['save'] = None
             kwargs['query'] = self.run(save_query=True, **kwargs_copy)
 
--- a/tools/tryselect/selectors/fuzzy.py
+++ b/tools/tryselect/selectors/fuzzy.py
@@ -8,17 +8,16 @@ import os
 import platform
 import re
 import subprocess
 import sys
 from distutils.spawn import find_executable
 
 from mozboot.util import get_state_dir
 from mozterm import Terminal
-from six import string_types
 
 from ..cli import BaseTryParser
 from ..tasks import generate_tasks, filter_tasks_by_paths
 from ..push import check_working_directory, push_to_try, vcs
 
 terminal = Terminal()
 
 here = os.path.abspath(os.path.dirname(__file__))
@@ -206,19 +205,19 @@ def run_fzf(cmd, tasks):
         selected = out[1:]
     return query, selected
 
 
 def filter_target_task(task):
     return not any(re.search(pattern, task) for pattern in TARGET_TASK_FILTERS)
 
 
-def run(update=False, query=None, templates=None, full=False, parameters=None, save_query=False,
-        push=True, message='{msg}', test_paths=None, exact=False, closed_tree=False,
-        intersection=False):
+def run(update=False, query=None, intersect_query=None, templates=None, full=False,
+        parameters=None, save_query=False, push=True, message='{msg}',
+        test_paths=None, exact=False, closed_tree=False):
     fzf = fzf_bootstrap(update)
 
     if not fzf:
         print(FZF_NOT_FOUND)
         return 1
 
     check_working_directory(push)
     tg = generate_tasks(parameters, full, root=vcs.path)
@@ -242,50 +241,49 @@ def run(update=False, query=None, templa
         '--preview', 'python -c "print(\\"\\n\\".join(sorted([s.strip(\\"\'\\") for s in \\"{+}\\".split()])))"',  # noqa
         '--preview-window=right:20%',
         '--print-query',
     ]
 
     if exact:
         base_cmd.append('--exact')
 
-    query = query or []
-    if isinstance(query, string_types):
-        query = [query]
-
-    commands = []
-    if query:
-        for q in query:
-            commands.append(base_cmd + ['-f', q])
-    else:
-        commands.append(base_cmd)
-
+    selected = set()
     queries = []
-    selected = set()
-    for command in commands:
-        query, tasks = run_fzf(command, all_tasks)
-        if tasks:
-            tasks = set(tasks)
-            queries.append(query)
+
+    def get_tasks(query_arg=None):
+        cmd = base_cmd[:]
+        if query_arg:
+            cmd.extend(['-f', query_arg])
+
+        query_str, tasks = run_fzf(cmd, all_tasks)
+        queries.append(query_str)
+        return set(tasks)
 
-            if intersection and selected:
-                selected &= tasks
-            else:
-                selected |= tasks
+    for q in query or []:
+        selected |= get_tasks(q)
+
+    for q in intersect_query or []:
+        tasks = get_tasks(q)
+        if not selected:
+            selected |= tasks
+        else:
+            selected &= tasks
+
+    if not queries:
+        selected = get_tasks()
 
     if not selected:
         print("no tasks selected")
         return
 
     if save_query:
         return queries
 
     # build commit message
     msg = "Fuzzy"
-    args = []
+    args = ["query={}".format(q) for q in queries]
     if test_paths:
         args.append("paths={}".format(':'.join(test_paths)))
-    if query:
-        args.extend(["query={}".format(q) for q in queries])
     if args:
         msg = "{} {}".format(msg, '&'.join(args))
     return push_to_try('fuzzy', message.format(msg=msg), selected, templates, push=push,
                        closed_tree=closed_tree)
--- a/tools/tryselect/test/test_fuzzy.t
+++ b/tools/tryselect/test/test_fuzzy.t
@@ -84,16 +84,40 @@ Test query intersection
           "env": {
               "TRY_SELECTOR": "fuzzy"
           }
       },
       "version": 1
   }
   
 
+Test intersection with preset containing multiple queries
+
+  $ ./mach try fuzzy --save foo -q "'test" -q "'opt"
+  preset saved, run with: --preset=foo
+
+  $ ./mach try fuzzy $testargs --preset foo -xq "'test"
+  Commit message:
+  Fuzzy query='test&query='opt&query='test
+  
+  Pushed via `mach try fuzzy`
+  Calculated try_task_config.json:
+  {
+      "tasks": [
+          "test/foo-debug",
+          "test/foo-opt"
+      ],
+      "templates": {
+          "env": {
+              "TRY_SELECTOR": "fuzzy"
+          }
+      },
+      "version": 1
+  }
+  
 
 Test exact match
 
   $ ./mach try fuzzy $testargs --full -q "testfoo | 'testbar"
   Commit message:
   Fuzzy query=testfoo | 'testbar
   
   Pushed via `mach try fuzzy`