diff --git a/conan/internal/api/detect_api.py b/conan/internal/api/detect_api.py index e90894b297f..aebad6e726c 100644 --- a/conan/internal/api/detect_api.py +++ b/conan/internal/api/detect_api.py @@ -581,3 +581,12 @@ def default_compiler_version(compiler, version): elif compiler == "intel-cc": return major return version + + +def detect_sdk_version(sdk): + if platform.system() != "Darwin": + return + cmd = f'xcrun -sdk {sdk} --show-sdk-version' + result = check_output_runner(cmd) + result = result.strip() + return result diff --git a/test/functional/test_profile_detect_api.py b/test/functional/test_profile_detect_api.py index 24f6b3f8dcf..1bac560e898 100644 --- a/test/functional/test_profile_detect_api.py +++ b/test/functional/test_profile_detect_api.py @@ -76,3 +76,17 @@ def test_profile_detect_libc(self): user.confvar:libc_version={libc_version} """) assert expected in client.out + + @pytest.mark.skipif(platform.system() != "Darwin", reason="Only OSX") + def test_profile_detect_darwin_sdk(self): + client = TestClient() + tpl1 = textwrap.dedent("""\ + [settings] + os = "Macos" + os.sdk_version = {{ detect_api.detect_sdk_version(sdk="macosx") }} + """) + + client.save({"profile1": tpl1}) + client.run("profile show -pr=profile1") + sdk_version = detect_api.detect_sdk_version(sdk="macosx") + assert f"os.sdk_version={sdk_version}" in client.out