Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make conan.tools.apple.XCRun public #12172

Merged
merged 3 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions conan/tools/apple/__init__.py
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions conan/tools/apple/apple.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
26 changes: 26 additions & 0 deletions conans/test/functional/tools/test_apple_tools.py
Original file line number Diff line number Diff line change
@@ -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