Repository: conan-io/conan

Issue:
Search query handles os_build and arch_build as options
When searching for the packages of a receipe os_build and arch_build are not take into account correctly. Even if a package matches, it is not included in the resulting list. From what I can see, only specific strings in the query are treated as settings, all others as options.


Discussion:

Resolving patch:
diff --git a/conans/search/search.py b/conans/search/search.py
--- a/conans/search/search.py
+++ b/conans/search/search.py
@@ -66,7 +66,7 @@ def compatible_prop(setting_value, prop_value):
     info_settings = conan_vars_info.get("settings", [])
     info_options = conan_vars_info.get("options", [])
 
-    if prop_name in ["os", "compiler", "arch", "build_type"] or prop_name.startswith("compiler."):
+    if prop_name in ["os", "os_build", "compiler", "arch", "arch_build", "build_type"] or prop_name.startswith("compiler."):
         return compatible_prop(info_settings.get(prop_name, None), prop_value)
     else:
         return compatible_prop(info_options.get(prop_name, None), prop_value)


Test patch:
diff --git a/conans/test/command/search_test.py b/conans/test/command/search_test.py
--- a/conans/test/command/search_test.py
+++ b/conans/test/command/search_test.py
@@ -82,6 +82,25 @@
   HelloInfo1/0.45@myuser/testing:33333
 """
 
+conan_vars_tool_winx86 = """[settings]
+  os_build=Windows
+  arch_build=x86
+"""
+
+conan_vars_tool_winx64 = """[settings]
+  os_build=Windows
+  arch_build=x86_64
+"""
+
+conan_vars_tool_linx86 = """[settings]
+  os_build=Linux
+  arch_build=x86
+"""
+
+conan_vars_tool_linx64 = """[settings]
+  os_build=Linux
+  arch_build=x86_64
+"""
 
 class SearchTest(unittest.TestCase):
 
@@ -105,6 +124,7 @@ def setUp(self):
         root_folder5 = 'MissFile/1.0.2/myuser/stable'
         root_folder11 = 'Hello/1.4.11/myuser/testing'
         root_folder12 = 'Hello/1.4.12/myuser/testing'
+        root_folder_tool = 'Tool/1.0.0/myuser/testing'
 
         self.client.save({"Empty/1.10/fake/test/export/fake.txt": "//",
                           "%s/%s/WindowsPackageSHA/%s" % (root_folder1,
@@ -133,7 +153,19 @@ def setUp(self):
                                                        CONANINFO): conan_vars4,
                           "%s/%s/e4f7vdwcv4w55d/%s" % (root_folder5,
                                                        PACKAGES_FOLDER,
-                                                       "hello.txt"): "Hello"},
+                                                       "hello.txt"): "Hello",
+                          "%s/%s/winx86/%s" % (root_folder_tool,
+                                               PACKAGES_FOLDER,
+                                               CONANINFO): conan_vars_tool_winx86,
+                          "%s/%s/winx64/%s" % (root_folder_tool,
+                                               PACKAGES_FOLDER,
+                                               CONANINFO): conan_vars_tool_winx64,
+                          "%s/%s/linx86/%s" % (root_folder_tool,
+                                               PACKAGES_FOLDER,
+                                               CONANINFO): conan_vars_tool_linx86,
+                          "%s/%s/linx64/%s" % (root_folder_tool,
+                                               PACKAGES_FOLDER,
+                                               CONANINFO): conan_vars_tool_linx64},
                          self.client.paths.store)
 
         # Fake some manifests to be able to calculate recipe hash
@@ -145,6 +177,7 @@ def setUp(self):
         fake_manifest.save(os.path.join(self.client.paths.store, root_folder5, EXPORT_FOLDER))
         fake_manifest.save(os.path.join(self.client.paths.store, root_folder11, EXPORT_FOLDER))
         fake_manifest.save(os.path.join(self.client.paths.store, root_folder12, EXPORT_FOLDER))
+        fake_manifest.save(os.path.join(self.client.paths.store, root_folder_tool, EXPORT_FOLDER))
 
     def recipe_search_all_test(self):
         os.rmdir(self.servers["local"].paths.store)
@@ -179,8 +212,7 @@ def recipe_search_test(self):
         self.assertEquals("Existing package recipes:\n\n"
                           "Hello/1.4.10@myuser/testing\n"
                           "Hello/1.4.11@myuser/testing\n"
-                          "Hello/1.4.12@myuser/testing\n",
-                          self.client.out)
+                          "Hello/1.4.12@myuser/testing\n", self.client.out)
 
         self.client.run("search *myuser* --case-sensitive")
         self.assertEquals("Existing package recipes:\n\n"
@@ -190,6 +222,7 @@ def recipe_search_test(self):
                           "Hello/1.4.12@myuser/testing\n"
                           "MissFile/1.0.2@myuser/stable\n"
                           "NodeInfo/1.0.2@myuser/stable\n"
+                          "Tool/1.0.0@myuser/testing\n"
                           "helloTest/1.4.10@myuser/stable\n", self.client.out)
 
         self.client.run("search Hello/*@myuser/testing")
@@ -288,30 +321,6 @@ def search_html_table_with_no_reference_test(self):
         self.assertIn("ERROR: '--table' argument can only be used with a reference",
                       self.client.out)
 
-    def recipe_pattern_search_test(self):
-        self.client.run("search Hello*")
-        self.assertEquals("Existing package recipes:\n\n"
-                          "Hello/1.4.10@myuser/testing\n"
-                          "Hello/1.4.11@myuser/testing\n"
-                          "Hello/1.4.12@myuser/testing\n"
-                          "helloTest/1.4.10@myuser/stable\n", self.client.out)
-
-        self.client.run("search Hello* --case-sensitive")
-        self.assertEquals("Existing package recipes:\n\n"
-                          "Hello/1.4.10@myuser/testing\n"
-                          "Hello/1.4.11@myuser/testing\n"
-                          "Hello/1.4.12@myuser/testing\n", self.client.out)
-
-        self.client.run("search *myuser* --case-sensitive")
-        self.assertEquals("Existing package recipes:\n\n"
-                          "Bye/0.14@myuser/testing\n"
-                          "Hello/1.4.10@myuser/testing\n"
-                          "Hello/1.4.11@myuser/testing\n"
-                          "Hello/1.4.12@myuser/testing\n"
-                          "MissFile/1.0.2@myuser/stable\n"
-                          "NodeInfo/1.0.2@myuser/stable\n"
-                          "helloTest/1.4.10@myuser/stable\n", self.client.out)
-
     def package_search_with_invalid_reference_test(self):
         self.client.run("search Hello -q 'a=1'", ignore_error=True)
         self.assertIn("-q parameter only allowed with a valid recipe", str(self.client.out))
@@ -380,6 +389,16 @@ def _assert_pkg_q(self, query, packages_found, remote):
             self.assertEquals(pack_name in self.client.out,
                               pack_name in packages_found, "%s fail" % pack_name)
 
+    def _assert_pkg_query_tool(self, query, packages_found, remote):
+        command = 'search Tool/1.0.0@myuser/testing -q \'%s\'' % query
+        if remote:
+            command += " -r %s" % remote
+        self.client.run(command)
+
+        for pack_name in ["winx86", "winx64", "linx86", "linx64"]:
+            self.assertEquals(pack_name in self.client.out,
+                              pack_name in packages_found, "%s fail" % pack_name)
+
     def package_search_complex_queries_test(self):
 
         def test_cases(remote=None):
@@ -438,6 +457,24 @@ def test_cases(remote=None):
             q = '(os="Linux" OR os=Windows) AND use_Qt=True OR nonexistant_option=3'
             self._assert_pkg_q(q, ["WindowsPackageSHA", "LinuxPackageSHA"], remote)
 
+            q = 'os_build="Windows"'
+            self._assert_pkg_query_tool(q, ["winx86", "winx64"], remote)
+
+            q = 'os_build="Linux"'
+            self._assert_pkg_query_tool(q, ["linx86", "linx64"], remote)
+
+            q = 'arch_build="x86"'
+            self._assert_pkg_query_tool(q, ["winx86", "linx86"], remote)
+
+            q = 'arch_build="x86_64"'
+            self._assert_pkg_query_tool(q, ["winx64", "linx64"], remote)
+
+            q = 'os_build="Windows" AND arch_build="x86_64"'
+            self._assert_pkg_query_tool(q, ["winx64"], remote)
+
+            q = 'os_build="Windoooows"'
+            self._assert_pkg_query_tool(q, [], remote)
+
         # test in local
         test_cases()