diff --git a/conan/tools/apple/__init__.py b/conan/tools/apple/__init__.py index 22f18bb1286..2aa3f7f4dbd 100644 --- a/conan/tools/apple/__init__.py +++ b/conan/tools/apple/__init__.py @@ -1,9 +1,8 @@ # Keep everything private until we review what is really needed and refactor passing "conanfile" -# from conan.tools.apple.apple import XCRun # from conan.tools.apple.apple import apple_dot_clean # from conan.tools.apple.apple import apple_sdk_name # from conan.tools.apple.apple import apple_deployment_target_flag -from conan.tools.apple.apple import fix_apple_shared_install_name, is_apple_os, to_apple_arch +from conan.tools.apple.apple import fix_apple_shared_install_name, is_apple_os, to_apple_arch, XCRun from conan.tools.apple.xcodedeps import XcodeDeps from conan.tools.apple.xcodebuild import XcodeBuild from conan.tools.apple.xcodetoolchain import XcodeToolchain diff --git a/conan/tools/apple/apple.py b/conan/tools/apple/apple.py index b796de342dc..a68b5d355d7 100644 --- a/conan/tools/apple/apple.py +++ b/conan/tools/apple/apple.py @@ -73,17 +73,17 @@ def apple_min_version_flag(conanfile): def apple_sdk_path(conanfile): sdk_path = conanfile.conf.get("tools.apple:sdk_path") if not sdk_path: - sdk_path = XCRun(conanfile.settings).sdk_path + sdk_path = XCRun(conanfile).sdk_path return sdk_path class XCRun(object): - def __init__(self, settings, sdk=None): + def __init__(self, conanfile, sdk=None): """sdk=False will skip the flag sdk=None will try to adjust it automatically""" - if sdk is None and settings: - sdk = apple_sdk_name(settings) + if sdk is None and conanfile.settings: + sdk = apple_sdk_name(conanfile.settings) self.sdk = sdk def _invoke(self, args): diff --git a/conans/test/functional/tools/test_apple_tools.py b/conans/test/functional/tools/test_apple_tools.py new file mode 100644 index 00000000000..15fba0bcf34 --- /dev/null +++ b/conans/test/functional/tools/test_apple_tools.py @@ -0,0 +1,26 @@ +import platform +import textwrap + +import pytest + +from conans.test.utils.tools import TestClient + + +@pytest.mark.skipif(platform.system() != "Darwin", reason="Requires Xcode") +def test_xcrun(): + conanfile = textwrap.dedent(""" + from conan import ConanFile + from conan.tools.apple import XCRun + + class HelloConan(ConanFile): + name = "hello" + version = "0.1" + settings = "os", "compiler", "build_type", "arch" + def build(self): + sdk_path = XCRun(self).sdk_path + self.output.info(sdk_path) + """) + client = TestClient(path_with_spaces=False) + client.save({"conanfile.py": conanfile}, clean_first=True) + client.run("create .") + assert "Xcode.app/Contents/Developer/Platforms/MacOSX.platform" in client.out