Repository: conan-io/conan
Pull request #13124 (2023-02-14 10:56:48)

Distro latest version is 1.8.0
Changes do not appear breaking https://github.com/python-distro/distro/blob/master/CHANGELOG.md

Changelog: Feature: Update requirements.txt to use distro package version <=1.8.0.
Docs: omit

Closes: #13123

- [x] Refer to the issue that supports this Pull Request.
- [x] If the issue has missing info, explain the purpose/use case/pain/need that covers this Pull Request.
- [x] I've read the [Contributing guide](https://github.com/conan-io/conan/blob/develop/.github/CONTRIBUTING.md).
- [x] I've followed the PEP8 style guides for Python code.
- [x] I've opened another PR in the Conan docs repo to the ``develop`` branch, documenting this one. 

<sup>**Note:** By default this PR will skip the slower tests and will use a limited set of python versions. Check [here](https://github.com/conan-io/conan/blob/develop/.github/PR_INCREASE_TESTING.md) how to increase the testing level by writing some tags in the current PR body text.</sup>


CLAassistant: [![CLA assistant check](https://cla-assistant.io/pull/badge/not_signed)](https://cla-assistant.io/conan-io/conan?pullRequest=13124) <br/>Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our [Contributor License Agreement](https://cla-assistant.io/conan-io/conan?pullRequest=13124) before we can accept your contribution.<br/><hr/>**Alexander Stepchenko** seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please [add the email address used for this commit to your account](https://help.github.com/articles/why-are-my-commits-linked-to-the-wrong-user/#commits-are-not-linked-to-any-user).<br/><sub>You have signed the CLA already but the status is still pending? Let us [recheck](https://cla-assistant.io/check/conan-io/conan?pullRequest=13124) it.</sub>

Patch:
diff --git a/conan/tools/android/__init__.py b/conan/tools/android/__init__.py
new file mode 100644
index 000000000..c969bbebd
--- /dev/null
+++ b/conan/tools/android/__init__.py
@@ -0,0 +1,1 @@
+from conan.tools.android.utils import android_abi
diff --git a/conan/tools/android/utils.py b/conan/tools/android/utils.py
new file mode 100644
index 000000000..12a5e7551
--- /dev/null
+++ b/conan/tools/android/utils.py
@@ -0,0 +1,31 @@
+from conan.errors import ConanException
+
+
+def android_abi(conanfile, context="host"):
+    """
+    Returns Android-NDK ABI
+    :param conanfile: ConanFile instance
+    :param context: either "host", "build" or "target"
+    :return: Android-NDK ABI
+    """
+    if context not in ("host", "build", "target"):
+        raise ConanException(f"context argument must be either 'host', 'build' or 'target', was '{context}'")
+
+    try:
+        settings = getattr(conanfile, f"settings_{context}")
+    except AttributeError:
+        if context == "host":
+            settings = conanfile.settings
+        else:
+            raise ConanException(f"settings_{context} not declared in recipe")
+    arch = settings.get_safe("arch")
+    # https://cmake.org/cmake/help/latest/variable/CMAKE_ANDROID_ARCH_ABI.html
+    return {
+        "armv5el": "armeabi",
+        "armv5hf": "armeabi",
+        "armv5": "armeabi",
+        "armv6": "armeabi-v6",
+        "armv7": "armeabi-v7a",
+        "armv7hf": "armeabi-v7a",
+        "armv8": "arm64-v8a",
+    }.get(arch, arch)
diff --git a/conan/tools/cmake/toolchain/blocks.py b/conan/tools/cmake/toolchain/blocks.py
index 51a474a9a..baacbca8b 100644
--- a/conan/tools/cmake/toolchain/blocks.py
+++ b/conan/tools/cmake/toolchain/blocks.py
@@ -6,6 +6,7 @@ from collections import OrderedDict
 from jinja2 import Template
 
 from conan.tools._compilers import architecture_flag, libcxx_flags
+from conan.tools.android.utils import android_abi
 from conan.tools.apple.apple import is_apple_os, to_apple_arch
 from conan.tools.build import build_jobs
 from conan.tools.build.cross_building import cross_building
@@ -301,11 +302,6 @@ class AndroidSystemBlock(Block):
         if os_ != "Android":
             return
 
-        android_abi = {"x86": "x86",
-                       "x86_64": "x86_64",
-                       "armv7": "armeabi-v7a",
-                       "armv8": "arm64-v8a"}.get(str(self._conanfile.settings.arch))
-
         # TODO: only 'c++_shared' y 'c++_static' supported?
         #  https://developer.android.com/ndk/guides/cpp-support
         libcxx_str = self._conanfile.settings.get_safe("compiler.libcxx")
@@ -317,7 +313,7 @@ class AndroidSystemBlock(Block):
 
         ctxt_toolchain = {
             'android_platform': 'android-' + str(self._conanfile.settings.os.api_level),
-            'android_abi': android_abi,
+            'android_abi': android_abi(self._conanfile),
             'android_stl': libcxx_str,
             'android_ndk_path': android_ndk_path,
         }
diff --git a/conan/tools/meson/toolchain.py b/conan/tools/meson/toolchain.py
index d4e808f16..dcb7d06f9 100644
--- a/conan/tools/meson/toolchain.py
+++ b/conan/tools/meson/toolchain.py
@@ -211,9 +211,6 @@ class MesonToolchain(object):
             elements = getattr(self._conanfile.cpp.package, name)
             return elements[0] if elements else None
 
-        if not self._conanfile.package_folder:
-            return {}
-
         ret = {}
         bindir = _get_cpp_info_value("bindirs")
         datadir = _get_cpp_info_value("resdirs")
diff --git a/conan/tools/scm/git.py b/conan/tools/scm/git.py
index 1032d5b69..e6fe909a7 100644
--- a/conan/tools/scm/git.py
+++ b/conan/tools/scm/git.py
@@ -84,6 +84,19 @@ class Git(object):
         self._conanfile.output.info("Cloning git repo")
         self.run('clone "{}" {} {}'.format(url, " ".join(args), target))
 
+    def fetch_commit(self, url, commit):
+        """
+        Experimental: does a 1 commit fetch and checkout, instead of a full clone,
+        should be faster.
+        """
+        if os.path.exists(url):
+            url = url.replace("\\", "/")  # Windows local directory
+        self._conanfile.output.info("Shallow fetch of git repo")
+        self.run('init')
+        self.run(f'remote add origin "{url}"')
+        self.run(f'fetch --depth 1 origin {commit}')
+        self.run(f'checkout FETCH_HEAD')
+
     def checkout(self, commit):
         self._conanfile.output.info("Checkout: {}".format(commit))
         self.run('checkout {}'.format(commit))
diff --git a/conans/requirements.txt b/conans/requirements.txt
index 6afa64a16..a4d6d9ea0 100644
--- a/conans/requirements.txt
+++ b/conans/requirements.txt
@@ -6,7 +6,7 @@ patch-ng>=1.17.4, <1.18
 fasteners>=0.14.1
 six>=1.10.0,<=1.16.0
 node-semver==0.6.1
-distro>=1.0.2, <=1.7.0; sys_platform == 'linux' or sys_platform == 'linux2'
+distro>=1.0.2, <=1.8.0; sys_platform == 'linux' or sys_platform == 'linux2'
 pygments>=2.0, <3.0
 tqdm>=4.28.1, <5
 Jinja2>=2.9, <3.0.0;python_version<='2.7'


Test patch:
diff --git a/conans/test/functional/toolchains/meson/test_install.py b/conans/test/functional/toolchains/meson/test_install.py
index e61f75adc..c3b0d4275 100644
--- a/conans/test/functional/toolchains/meson/test_install.py
+++ b/conans/test/functional/toolchains/meson/test_install.py
@@ -106,6 +106,11 @@ class MesonInstall(TestMesonBase):
                      os.path.join("test_package", "CMakeLists.txt"): self._test_package_cmake_lists,
                      os.path.join("test_package", "test_package.cpp"): test_package_cpp})
 
-        self.t.run("create . hello/0.1@ %s" % self._settings_str)
+        # FIXME: Remove this and run a "conan create ..." instead whenever there will be tests with
+        #        export-pkg command running automatically the test_package as well.
+        self.t.run("install .")
+        self.t.run("build .")
+        self.t.run("export-pkg . hello/0.1@ %s" % self._settings_str)
+        self.t.run("test test_package/conanfile.py hello/0.1@ %s" % self._settings_str)
 
         self._check_binary()
diff --git a/conans/test/functional/tools/scm/test_git.py b/conans/test/functional/tools/scm/test_git.py
index 499319541..0b3d822a3 100644
--- a/conans/test/functional/tools/scm/test_git.py
+++ b/conans/test/functional/tools/scm/test_git.py
@@ -1,4 +1,5 @@
 import os
+import platform
 import re
 import textwrap
 
@@ -209,6 +210,52 @@ class TestGitBasicClone:
         assert c.load("source/CMakeLists.txt") == "mycmake"
 
 
+class TestGitShallowClone:
+    """ base Git cloning operations
+    """
+    conanfile = textwrap.dedent("""
+        import os
+        from conan import ConanFile
+        from conan.tools.scm import Git
+        from conan.tools.files import load
+
+        class Pkg(ConanFile):
+            name = "pkg"
+            version = "0.1"
+
+            def layout(self):
+                self.folders.source = "source"
+
+            def source(self):
+                git = Git(self)
+                git.fetch_commit(url="{url}", commit="{commit}")
+                self.output.info("MYCMAKE: {{}}".format(load(self, "CMakeLists.txt")))
+                self.output.info("MYFILE: {{}}".format(load(self, "src/myfile.h")))
+        """)
+
+    @pytest.mark.skipif(platform.system() == "Linux", reason="Git version in Linux not support it")
+    def test_clone_checkout(self):
+        folder = os.path.join(temp_folder(), "myrepo")
+        url, commit = create_local_git_repo(files={"src/myfile.h": "myheader!",
+                                                   "CMakeLists.txt": "mycmake"}, folder=folder)
+        # This second commit will NOT be used, as I will use the above commit in the conanfile
+        save_files(path=folder, files={"src/myfile.h": "my2header2!"})
+        git_add_changes_commit(folder=folder)
+
+        c = TestClient()
+        c.save({"conanfile.py": self.conanfile.format(url=url, commit=commit)})
+        c.run("create .")
+        assert "pkg/0.1: MYCMAKE: mycmake" in c.out
+        assert "pkg/0.1: MYFILE: myheader!" in c.out
+
+        # It also works in local flow
+        c.run("source .")
+        assert "conanfile.py (pkg/0.1): MYCMAKE: mycmake" in c.out
+        assert "conanfile.py (pkg/0.1): MYFILE: myheader!" in c.out
+        assert c.load("source/src/myfile.h") == "myheader!"
+        assert c.load("source/CMakeLists.txt") == "mycmake"
+
+
 class TestGitCloneWithArgs:
     """ Git cloning passing additional arguments
     """
diff --git a/conans/test/unittests/tools/android/__init__.py b/conans/test/unittests/tools/android/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/conans/test/unittests/tools/android/test_android_tools.py b/conans/test/unittests/tools/android/test_android_tools.py
new file mode 100644
index 000000000..038bd0b46
--- /dev/null
+++ b/conans/test/unittests/tools/android/test_android_tools.py
@@ -0,0 +1,79 @@
+from conans.test.utils.mocks import ConanFileMock, MockSettings
+from conans.errors import ConanException
+from conan.tools.android import android_abi
+
+from pytest import raises
+
+def test_tools_android_abi():
+    settings_linux = MockSettings({"os": "Linux", "arch": "foo"})
+
+    for (arch, expected) in [
+        ("armv5el", "armeabi"),
+        ("armv5hf", "armeabi"),
+        ("armv5", "armeabi"),
+        ("armv6", "armeabi-v6"),
+        ("armv7", "armeabi-v7a"),
+        ("armv7hf", "armeabi-v7a"),
+        ("armv8", "arm64-v8a"),
+        ("x86", "x86"),
+        ("x86_64", "x86_64"),
+        ("mips", "mips"),
+        ("mips_64", "mips_64"),
+    ]:
+        conanfile = ConanFileMock()
+        settings_android = MockSettings({"os": "Android", "arch": arch})
+
+        # 1 profile (legacy native build)
+        conanfile.settings = settings_android
+        assert android_abi(conanfile) == expected
+        assert android_abi(conanfile, context="host") == expected
+
+        with raises(ConanException):
+            assert android_abi(conanfile, context="build") == expected
+
+        with raises(ConanException):
+            assert android_abi(conanfile, context="target") == expected
+
+        # 2 profiles
+        ## native build
+        conanfile.settings = settings_android
+        conanfile.settings_host = settings_android
+        conanfile.settings_build = settings_android
+        assert android_abi(conanfile) == expected
+        assert android_abi(conanfile, context="host") == expected
+        assert android_abi(conanfile, context="build") == expected
+
+        with raises(ConanException):
+            assert android_abi(conanfile, context="target") == expected
+
+        ## cross-build from Android to Linux (quite hypothetical)
+        conanfile.settings = settings_linux
+        conanfile.settings_host = settings_linux
+        conanfile.settings_build = settings_android
+        assert android_abi(conanfile) != expected
+        assert android_abi(conanfile, context="host") != expected
+        assert android_abi(conanfile, context="build") == expected
+
+        with raises(ConanException):
+            assert android_abi(conanfile, context="target")
+
+        ## cross-build a recipe from Linux to Android:
+        ### test android_abi in recipe itself
+        conanfile.settings = settings_android
+        conanfile.settings_host = settings_android
+        conanfile.settings_build = settings_linux
+        assert android_abi(conanfile) == expected
+        assert android_abi(conanfile, context="host") == expected
+        assert android_abi(conanfile, context="build") != expected
+        with raises(ConanException):
+            android_abi(conanfile, context="target")
+
+        ### test android_abi in "compiler recipe" (ie a android-ndk recipe in tool_requires of recipe being cross-build)
+        conanfile.settings = settings_linux
+        conanfile.settings_host = settings_linux
+        conanfile.settings_build = settings_linux
+        conanfile.settings_target = settings_android
+        assert android_abi(conanfile) != expected
+        assert android_abi(conanfile, context="host") != expected
+        assert android_abi(conanfile, context="build") != expected
+        assert android_abi(conanfile, context="target") == expected
diff --git a/conans/test/unittests/tools/scm/test_git_get_commit.py b/conans/test/unittests/tools/scm/test_git_get_commit.py
index 4ee7f984f..c5f54a570 100644
--- a/conans/test/unittests/tools/scm/test_git_get_commit.py
+++ b/conans/test/unittests/tools/scm/test_git_get_commit.py
@@ -14,6 +14,7 @@ def test_change_branch_in_root_commit():
     conanfile = MockConanfile({})
     c.save({"root.txt": "", "subfolder/subfolder.txt": ""})
     c.run_command("git init .")
+    c.run_command("git checkout -B master")
     c.run_command('git config user.name myname')
     c.run_command('git config user.email myname@mycompany.com')
     c.run_command("git add .")