Repository: conan-io/conan
Pull request #13070 (2023-02-07 21:55:16)

server revisions fix search
Changelog: Bugfix: Solve 500 error in ``conan search`` to conan_server with revisions enabled of a missing package
Docs: Omit

Close https://github.com/conan-io/conan/issues/13067


Patch:
diff --git a/conan/tools/apple/apple.py b/conan/tools/apple/apple.py
index 33f9e02bb..00d82783e 100644
--- a/conan/tools/apple/apple.py
+++ b/conan/tools/apple/apple.py
@@ -159,14 +159,18 @@ class XCRun(object):
         """path to libtool"""
         return self.find('libtool')
 
+def _get_dylib_install_name(path_to_dylib):
+    command = "otool -D {}".format(path_to_dylib)
+    output =  iter(check_output_runner(command).splitlines())
+    # Note: if otool return multiple entries for different architectures
+    # assume they are the same and pick the first one.
+    for line in output:
+        if ":" in line:
+            return next(output)
+    raise ConanException(f"Unable to extract install_name for {path_to_dylib}")
 
 def fix_apple_shared_install_name(conanfile):
 
-    def _get_install_name(path_to_dylib):
-        command = "otool -D {}".format(path_to_dylib)
-        install_name = check_output_runner(command).strip().split(":")[1].strip()
-        return install_name
-
     def _darwin_is_binary(file, binary_type):
         if binary_type not in ("DYLIB", "EXECUTE") or os.path.islink(file) or os.path.isdir(file):
             return False
@@ -212,7 +216,7 @@ def fix_apple_shared_install_name(conanfile):
             shared_libs = _darwin_collect_binaries(full_folder, "DYLIB")
             # fix LC_ID_DYLIB in first pass
             for shared_lib in shared_libs:
-                install_name = _get_install_name(shared_lib)
+                install_name = _get_dylib_install_name(shared_lib)
                 #TODO: we probably only want to fix the install the name if
                 # it starts with `/`.
                 rpath_name = f"@rpath/{os.path.basename(install_name)}"
diff --git a/conans/client/build/cmake.py b/conans/client/build/cmake.py
index 0006d8622..d9a668b37 100644
--- a/conans/client/build/cmake.py
+++ b/conans/client/build/cmake.py
@@ -47,8 +47,14 @@ class CMake(object):
         :param generator_platform: Generator platform name or none to autodetect (-A cmake option)
         """
         if getattr(conanfile, "must_use_new_helpers", None):
-            raise ConanException("Using the wrong 'CMake' helper. To use CMakeDeps, CMakeToolchain "
-                                 "you should use 'from conan.tools.cmake import CMake'")
+            wrong_helper_msg = "Using the wrong 'CMake' helper. To use CMakeDeps, CMakeToolchain "\
+                               "you should use 'from conan.tools.cmake import CMake'. "\
+                               "Set environment variable CONAN_DISABLE_STRICT_MODE=1 to override "\
+                               "this check (should only be used to build old packages)."
+            if get_env("CONAN_DISABLE_STRICT_MODE", False):
+                conanfile.output.warning(wrong_helper_msg)
+            else:
+                raise ConanException(wrong_helper_msg)
         self._append_vcvars = append_vcvars
         self._conanfile = conanfile
         self._settings = conanfile.settings
diff --git a/conans/client/build/msbuild.py b/conans/client/build/msbuild.py
index 778b81a76..df8b7bee4 100644
--- a/conans/client/build/msbuild.py
+++ b/conans/client/build/msbuild.py
@@ -23,9 +23,14 @@ class MSBuild(object):
     def __init__(self, conanfile):
         if isinstance(conanfile, ConanFile):
             if getattr(conanfile, "must_use_new_helpers", None):
-                raise ConanException(
-                    "Using the wrong 'MSBuild' helper. To use MSBuildDeps, MSBuildToolchain "
-                    "you should use 'from conan.tools.microsoft import MSBuild'")
+                wrong_helper_msg = "Using the wrong 'MSBuild' helper. To use MSBuildDeps, MSBuildToolchain "\
+                                   "you should use 'from conan.tools.microsoft import MSBuild'. "\
+                                   "Set environment variable CONAN_DISABLE_STRICT_MODE=1 to override "\
+                                   "this check (should only be used to build old packages)."
+                if get_env("CONAN_DISABLE_STRICT_MODE", False):
+                    conanfile.output.warning(wrong_helper_msg)
+                else:
+                    raise ConanException(wrong_helper_msg)
             self._conanfile = conanfile
             self._settings = self._conanfile.settings
             self._output = self._conanfile.output
diff --git a/conans/server/service/common/search.py b/conans/server/service/common/search.py
index af0c58ac3..e9c576206 100644
--- a/conans/server/service/common/search.py
+++ b/conans/server/service/common/search.py
@@ -61,7 +61,10 @@ def search_packages(server_store, ref, query, look_in_all_rrevs):
     param ref: ConanFileReference object
     """
     if not look_in_all_rrevs and ref.revision is None:
-        latest_rev = server_store.get_last_revision(ref).revision
+        found_ref = server_store.get_last_revision(ref)
+        if found_ref is None:
+            raise RecipeNotFoundException(ref)
+        latest_rev = found_ref.revision
         ref = ref.copy_with_rev(latest_rev)
 
     if not os.path.exists(server_store.conan_revisions_root(ref.copy_clear_rev())):


Test patch:
diff --git a/conans/test/integration/command/search_test.py b/conans/test/integration/command/search_test.py
index dd3ce69ab..71e276fe8 100644
--- a/conans/test/integration/command/search_test.py
+++ b/conans/test/integration/command/search_test.py
@@ -1639,3 +1639,10 @@ class TestMixConan1and2:
         c.run("search pkg/0.1@ -r=default")
         assert "Package_ID: package_id_1X" in c.out
         assert "package_id_20" not in c.out
+
+
+def test_error_revision_search():
+    c = TestClient(default_server_user=True)
+    c.run("config set general.revisions_enabled=1")
+    c.run("search mozilla/1.0.0@ -r=default", assert_error=True)
+    assert "ERROR: Recipe not found: 'mozilla/1.0.0'. [Remote: default]" in c.out
diff --git a/conans/test/unittests/tools/apple/test_apple_tools.py b/conans/test/unittests/tools/apple/test_apple_tools.py
index 78dd0e93d..18622458a 100644
--- a/conans/test/unittests/tools/apple/test_apple_tools.py
+++ b/conans/test/unittests/tools/apple/test_apple_tools.py
@@ -1,8 +1,11 @@
+import mock
 import pytest
+import textwrap
 
 from conans.test.utils.mocks import ConanFileMock, MockSettings
 from conans.test.utils.test_files import temp_folder
 from conan.tools.apple import is_apple_os, to_apple_arch, fix_apple_shared_install_name, XCRun
+from conan.tools.apple.apple import _get_dylib_install_name # testing private function
 
 def test_tools_apple_is_apple_os():
     conanfile = ConanFileMock()
@@ -48,3 +51,23 @@ def test_xcrun_public_settings():
     settings = xcrun.settings
 
     assert settings.os == "watchOS"
+
+def test_get_dylib_install_name():
+    # https://github.com/conan-io/conan/issues/13014
+    single_arch = textwrap.dedent("""
+    /path/to/libwebp.7.dylib:
+    /absolute/path/lib/libwebp.7.dylib
+    """)
+
+    universal_binary = textwrap.dedent("""
+    /.conan/data/package/lib/libwebp.7.dylib (architecture x86_64):
+    /absolute/path/lib/libwebp.7.dylib
+    /.conan/data/package/lib/libwebp.7.dylib (architecture arm64):
+    /absolute/path/lib/libwebp.7.dylib
+    """)
+
+    for mock_output in (single_arch, universal_binary):
+        with mock.patch("conan.tools.apple.apple.check_output_runner") as mock_output_runner:
+            mock_output_runner.return_value = mock_output
+            install_name = _get_dylib_install_name("/path/to/libwebp.7.dylib")
+            assert "/absolute/path/lib/libwebp.7.dylib" == install_name