diff --git a/conans/test/conftest.py b/conans/test/conftest.py index c0161ca4175..080b111b59e 100644 --- a/conans/test/conftest.py +++ b/conans/test/conftest.py @@ -173,6 +173,10 @@ 'android_ndk': { "platform": "Darwin", "exe": "ndk-build", + "default": "system", + "system": { + "path": {'Darwin': f'{homebrew_root}/share/android-ndk'} + } }, # TODO: Intel oneAPI is not installed in CI yet. Uncomment this line whenever it's done. # "intel_oneapi": { @@ -238,15 +242,12 @@ def update(d, u): except ImportError as e: user_default_profiles = None -homebrew_root = "/opt/homebrew" if platform.machine() == "arm64" else "/usr/local" - tools_environments = { 'mingw32': {'Windows': {'MSYSTEM': 'MINGW32'}}, 'mingw64': {'Windows': {'MSYSTEM': 'MINGW64'}}, 'ucrt64': {'Windows': {'MSYSTEM': 'UCRT64'}}, - 'msys2_clang64': {"Windows": {"MSYSTEM": "CLANG64"}}, - 'android_ndk': {'Darwin': {'TEST_CONAN_ANDROID_NDK': f'{homebrew_root}/share/android-ndk'}} + 'msys2_clang64': {"Windows": {"MSYSTEM": "CLANG64"}} } diff --git a/conans/test/functional/toolchains/android/_utils.py b/conans/test/functional/toolchains/android/_utils.py deleted file mode 100644 index 216c46123fe..00000000000 --- a/conans/test/functional/toolchains/android/_utils.py +++ /dev/null @@ -1,38 +0,0 @@ -import textwrap - -lib_h = textwrap.dedent(""" - int some_function(int value); -""") - -lib_cpp = textwrap.dedent(""" - #include "lib.h" - #include - - int some_function(int value) { - std::cout << "some_function(value=" << value << ")" << std::endl; - return 42; - } -""") - -cmakelists = textwrap.dedent(""" - cmake_minimum_required(VERSION 2.8.12) # TODO: Define minimun required here - project(AndroidLibrary CXX) - - add_library(library lib.h lib.cpp) - set_target_properties(library PROPERTIES PUBLIC_HEADER lib.h) - - install(TARGETS library - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib - PUBLIC_HEADER DESTINATION include - ) -""") - - -def create_library(client): - client.save({ - 'lib.h': lib_h, - 'lib.cpp': lib_cpp, - 'CMakeLists.txt': cmakelists - }) diff --git a/conans/test/functional/toolchains/android/test_using_cmake.py b/conans/test/functional/toolchains/android/test_using_cmake.py index 57d7d3acb2e..dd229833f94 100644 --- a/conans/test/functional/toolchains/android/test_using_cmake.py +++ b/conans/test/functional/toolchains/android/test_using_cmake.py @@ -1,70 +1,44 @@ -import os import platform +import tempfile import textwrap import pytest -from conan.tools.cmake import CMakeToolchain -from conans.test.functional.toolchains.android._utils import create_library +from conans.test.conftest import tools_locations from conans.test.utils.tools import TestClient -@pytest.fixture -def client(): - t = TestClient() - create_library(t) - t.save({ - 'conanfile.py': textwrap.dedent(""" - from conan import ConanFile - from conan.tools.cmake import CMake, CMakeToolchain - - class Library(ConanFile): - name = 'library' - settings = 'os', 'arch', 'compiler', 'build_type' - exports_sources = "CMakeLists.txt", "lib.h", "lib.cpp" - options = {'shared': [True, False]} - default_options = {'shared': False} - - def generate(self): - tc = CMakeToolchain(self) - tc.generate() - - def build(self): - cmake = CMake(self) - cmake.configure() - cmake.build() - - def package(self): - cmake = CMake(self) - cmake.install() - """), - 'profile_host': textwrap.dedent(""" - [settings] - os=Android - os.api_level=23 - arch=x86_64 - compiler=clang - compiler.version=9 - compiler.libcxx=c++_shared - build_type=Release - [conf] - tools.android:ndk_path={ndk_path} - """.format(ndk_path=os.getenv("TEST_CONAN_ANDROID_NDK"))) - }) - return t - - -@pytest.mark.tool("cmake") +@pytest.mark.tool("cmake", "3.23") # Android complains if <3.19 +@pytest.mark.tool("ninja") # so it easily works in Windows too @pytest.mark.tool("android_ndk") @pytest.mark.skipif(platform.system() != "Darwin", reason="NDK only installed on MAC") -def test_use_cmake_toolchain(client): +def test_use_cmake_toolchain(): """ This is the naive approach, we follow instruction from CMake in its documentation https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling-for-android """ - # Build in the cache - client.run('create . --name=library --version=version --profile:host=profile_host --profile:build=default') + # Overriding the default folders, so they are in the same unit drive in Windows + # otherwise AndroidNDK FAILS to build, it needs using the same unit drive + c = TestClient(cache_folder=tempfile.mkdtemp(), + current_folder=tempfile.mkdtemp()) + c.run("new cmake_lib -d name=hello -d version=0.1") + ndk_path = tools_locations["android_ndk"]["system"]["path"][platform.system()] + android = textwrap.dedent(f""" + [settings] + os=Android + os.api_level=23 + arch=x86_64 + compiler=clang + compiler.version=12 + compiler.libcxx=c++_shared + build_type=Release + [conf] + tools.android:ndk_path={ndk_path} + tools.cmake.cmaketoolchain:generator=Ninja + """) + c.save({"android": android}) + c.run('create . --profile:host=android') + assert "hello/0.1 (test package): Running test()" in c.out # Build locally - client.run('install . --name=library --version=version --profile:host=profile_host --profile:build=default') - client.run_command('cmake . -DCMAKE_TOOLCHAIN_FILE={}'.format(CMakeToolchain.filename)) - client.run_command('cmake --build .') + c.run('build . --profile:host=android') + assert "conanfile.py (hello/0.1): Running CMake.build()" in c.out diff --git a/conans/test/functional/toolchains/meson/test_cross_compilation.py b/conans/test/functional/toolchains/meson/test_cross_compilation.py index ee6a1cc3998..9f66264036f 100644 --- a/conans/test/functional/toolchains/meson/test_cross_compilation.py +++ b/conans/test/functional/toolchains/meson/test_cross_compilation.py @@ -6,6 +6,7 @@ from conan.tools.apple.apple import _to_apple_arch, XCRun from conans.test.assets.sources import gen_function_cpp, gen_function_h +from conans.test.conftest import tools_locations from conans.test.utils.mocks import ConanFileMock from conans.test.utils.tools import TestClient from conans.util.runners import conan_run @@ -175,9 +176,10 @@ def test_android_meson_toolchain_cross_compiling(arch, expected_arch): hello_h = gen_function_h(name="hello") hello_cpp = gen_function_cpp(name="hello", preprocessor=["STRING_DEFINITION"]) app = gen_function_cpp(name="main", includes=["hello"], calls=["hello"]) + ndk_path = tools_locations["android_ndk"]["system"]["path"][platform.system()] profile_host = profile_host.format( arch=arch, - ndk_path=os.getenv("TEST_CONAN_ANDROID_NDK") + ndk_path=ndk_path ) client = TestClient()