diff --git a/scripts/gha/integration_testing/xcodebuild.py b/scripts/gha/integration_testing/xcodebuild.py index 1faa1e9c..27a97076 100644 --- a/scripts/gha/integration_testing/xcodebuild.py +++ b/scripts/gha/integration_testing/xcodebuild.py @@ -29,7 +29,25 @@ """ import os +import re import shutil +import subprocess + + +def _get_xcode_version(): + """Helper to determine major Xcode version.""" + try: + result = subprocess.run( + ["xcodebuild", "-version"], + capture_output=True, + text=True, + check=True) + match = re.search(r"Xcode\s+(\d+)", result.stdout) + if match: + return int(match.group(1)) + except Exception: + pass + return None def get_args_for_build(path, scheme, output_dir, ios_sdk, target_os, configuration): @@ -55,6 +73,68 @@ def get_args_for_build(path, scheme, output_dir, ios_sdk, target_os, configurati "BUILD_DIR=" + output_dir ] + xcode_version = _get_xcode_version() + if xcode_version and xcode_version >= 16: + try: + import pwd + # Retrieve genuine home directory independent of temporary GHA shell overrides. + try: + real_home = pwd.getpwuid(os.getuid()).pw_dir + except Exception: + real_home = os.path.expanduser("~") + + # Gather all preference directories to populate plists in. + pref_dirs = [] + if real_home: + pref_dirs.append(os.path.join(real_home, "Library", "Preferences")) + env_home = os.environ.get("HOME") + if env_home: + pref_dirs.append(os.path.join(env_home, "Library", "Preferences")) + + # Write directly to preference plist files. + for pref_dir in set(pref_dirs): + os.makedirs(pref_dir, exist_ok=True) + for filename in ["com.apple.dt.Xcode.plist", "com.apple.dt.xcodebuild.plist", ".GlobalPreferences.plist"]: + plist_path = os.path.join(pref_dir, filename) + subprocess.run( + ["defaults", "write", plist_path, "DisablePackageRepositorySandboxing", "-bool", "YES"], + check=True, + capture_output=True) + subprocess.run( + ["defaults", "write", plist_path, "IDEPackageSupportDisableSandboxing", "-bool", "YES"], + check=True, + capture_output=True) + + # Write via standard macOS domains. + subprocess.run( + ["defaults", "write", "com.apple.dt.Xcode", "DisablePackageRepositorySandboxing", "-bool", "YES"], + check=True, + capture_output=True) + subprocess.run( + ["defaults", "write", "com.apple.dt.Xcode", "IDEPackageSupportDisableSandboxing", "-bool", "YES"], + check=True, + capture_output=True) + + subprocess.run( + ["defaults", "write", "com.apple.dt.xcodebuild", "DisablePackageRepositorySandboxing", "-bool", "YES"], + check=True, + capture_output=True) + subprocess.run( + ["defaults", "write", "com.apple.dt.xcodebuild", "IDEPackageSupportDisableSandboxing", "-bool", "YES"], + check=True, + capture_output=True) + + subprocess.run( + ["defaults", "write", "-g", "DisablePackageRepositorySandboxing", "-bool", "YES"], + check=True, + capture_output=True) + subprocess.run( + ["defaults", "write", "-g", "IDEPackageSupportDisableSandboxing", "-bool", "YES"], + check=True, + capture_output=True) + except Exception: + pass + if ios_sdk == "device": args.extend(['CODE_SIGN_IDENTITY=""', "CODE_SIGNING_REQUIRED=NO",