| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
import re |
| 4 |
|
| 5 |
MACOS_LOG_PREFIX_REGEX = re.compile( |
| 6 |
r"\d{4}-\d{2}-\d{2} (?P<timestamp>\d{2}:\d{2}:\d{2}.\d{3}) Df (.*?)\[.*?:.*?\]" |
| 7 |
r"(?P<subsystem>( \(libffi\.dylib\))|(" |
| 8 |
r" \(_ctypes(\.cpython-3\d{1,2}-.*?\.(so|dylib))?\)))? (?P<content>.*)" |
| 9 |
) |
| 10 |
|
| 11 |
|
| 12 |
def macOS_log_clean_filter(line): |
| 13 |
"""Filter a macOS system log to extract the Python-generated message content. |
| 14 |
|
| 15 |
Any system or stub messages are ignored; all logging prefixes are stripped. |
| 16 |
|
| 17 |
:param line: The raw line from the system log |
| 18 |
:returns: A tuple, containing (a) the log line, stripped of any system |
| 19 |
logging context, and (b) a boolean indicating if the message should be |
| 20 |
included for analysis purposes (i.e., it's Python content, not a system |
| 21 |
message). Returns a single ``None`` if the line should be dumped. |
| 22 |
""" |
| 23 |
if line.startswith( |
| 24 |
( |
| 25 |
# Log stream outputs the filter when it starts |
| 26 |
"Filtering the log data using ", |
| 27 |
# Log stream outputs barely useful column headers on startup |
| 28 |
"Timestamp ", |
| 29 |
# iOS reports ignorable errors on startup |
| 30 |
"Error from getpwuid_r:", |
| 31 |
"getpwuid_r did not find a match ", |
| 32 |
) |
| 33 |
): |
| 34 |
return None |
| 35 |
|
| 36 |
match = MACOS_LOG_PREFIX_REGEX.match(line) |
| 37 |
if match: |
| 38 |
groups = match.groupdict() |
| 39 |
return groups["content"], bool(groups["subsystem"]) |
| 40 |
|
| 41 |
return line, False |
| 42 |
|
| 43 |
|
| 44 |
class XcodeBuildFilter: |
| 45 |
# The prefix for all xcodebuild messages. |
| 46 |
XCODEBUILD_PREFIX = ( |
| 47 |
r"\d{4}-\d{2}-\d{2} +\d+:\d{2}:\d{2}\.\d{3} xcodebuild\[\d+:\d+\] +" |
| 48 |
) |
| 49 |
|
| 50 |
# Xcode 14 generates the following warning on x86_64 hardware |
| 51 |
# 2023-10-04 08:05:21.757 xcodebuild[46899:11335453] DVTCoreDeviceEnabledState: |
| 52 |
# DVTCoreDeviceEnabledState_Disabled set via user default |
| 53 |
# (DVTEnableCoreDevice=disabled) |
| 54 |
DEVICE_ENABLED_STATE_RE = re.compile( |
| 55 |
XCODEBUILD_PREFIX |
| 56 |
+ r"DVTCoreDeviceEnabledState: DVTCoreDeviceEnabledState_Disabled " |
| 57 |
r"set via user default \(DVTEnableCoreDevice=disabled\)" |
| 58 |
) |
| 59 |
|
| 60 |
# Xcode 14 generates the following warning when there is a passcode-protected device |
| 61 |
# attached to your computer, even if you're not doing anything to target it: |
| 62 |
# --------------------------------------------------------------------- |
| 63 |
# 2023-09-27 08:38:11.865 xcodebuild[41087:25901835] DTDKRemoteDeviceConnection: |
| 64 |
# Failed to start remote service "com.apple.mobile.notification_proxy" on device. |
| 65 |
# Error: Error Domain=com.apple.dtdevicekit Code=811 "Failed to start remote |
| 66 |
# service "com.apple.mobile.notification_proxy" on device." |
| 67 |
# UserInfo={NSUnderlyingError=0x10b8ec780 {Error Domain= |
| 68 |
# com.apple.dt.MobileDeviceErrorDomain Code=-402653158 "The device is passcode |
| 69 |
# protected." UserInfo={MobileDeviceErrorCode=(0xE800001A), |
| 70 |
# com.apple.dtdevicekit.stacktrace=( |
| 71 |
# 0 DTDeviceKitBase ... |
| 72 |
# ... |
| 73 |
# 21 libsystem_pthread.dylib ... |
| 74 |
# ), DVTRadarComponentKey=261622, NSLocalizedDescription=The device is |
| 75 |
# passcode protected.}}, NSLocalizedRecoverySuggestion=Please check your |
| 76 |
# connection to your device., DVTRadarComponentKey=261622, |
| 77 |
# NSLocalizedDescription=Failed to start remote service |
| 78 |
# "com.apple.mobile.notification_proxy" on device.} |
| 79 |
# 2023-09-27 08:38:11.903 xcodebuild[41087:25901835] Failed to start service |
| 80 |
# (com.apple.amfi.lockdown): 0xe800001a |
| 81 |
# --------------------------------------------------------------------- |
| 82 |
# These warnings can be ignored. |
| 83 |
LOCKED_DEVICE_START_RE = re.compile( |
| 84 |
XCODEBUILD_PREFIX |
| 85 |
+ r"DTDKRemoteDeviceConnection: Failed to start remote service " |
| 86 |
r"\"com\.apple\.mobile\.notification_proxy\" on device. Error: " |
| 87 |
r"Error Domain=com\.apple\.dtdevicekit Code=811 \"Failed to start " |
| 88 |
r"remote service \"com.apple.mobile.notification_proxy\" on device.\"" |
| 89 |
) |
| 90 |
LOCKED_DEVICE_END_RE = re.compile( |
| 91 |
r"\), DVTRadarComponentKey=\d+, NSLocalizedDescription=The device is " |
| 92 |
# r"passcode protected\.}}, NSLocalizedRecoverySuggestion=Please check " |
| 93 |
# r"your connection to your device\." |
| 94 |
) |
| 95 |
LOCKED_DEVICE_ADDITIONAL_RE = re.compile( |
| 96 |
XCODEBUILD_PREFIX + r"Failed to start service \(com\.apple\.amfi\.lockdown\): " |
| 97 |
) |
| 98 |
|
| 99 |
# Xcode 15 generates dozens of copies of the following message: |
| 100 |
# --------------------------------------------------------------------- |
| 101 |
# 2023-09-26 14:35:45.775 xcodebuild[75877:23947967] [MT] DVTAssertions: |
| 102 |
# Warning in /System/Volumes/Data/SWE/Apps/DT/BuildRoots/BuildRoot11 |
| 103 |
# /ActiveBuildRoot/Library/Caches/com.apple.xbs/Sources/IDEFrameworks |
| 104 |
# /IDEFrameworks-22267/IDEFoundation/Provisioning/Capabilities Infrastructure |
| 105 |
# /IDECapabilityQuerySelection.swift:103 |
| 106 |
# Details: createItemModels creation requirements should not create capability |
| 107 |
# item model for a capability item model that already exists. |
| 108 |
# Function: createItemModels(for:itemModelSource:) |
| 109 |
# Thread: <_NSMainThread: 0x11d60beb0>{number = 1, name = main} |
| 110 |
# Please file a bug at https://feedbackassistant.apple.com with this warning |
| 111 |
# message and any useful information you can provide. |
| 112 |
# --------------------------------------------------------------------- |
| 113 |
# As best as I can make out, this is a bug in Xcode; but it's overwhelming and |
| 114 |
# confusing, so filter it out. |
| 115 |
DVT_ASSERTIONS_RE = re.compile( |
| 116 |
XCODEBUILD_PREFIX + r"\[MT\] DVTAssertions: " |
| 117 |
r"Warning in /System/Volumes/Data/SWE/Apps/DT/BuildRoots/BuildRoot11/" |
| 118 |
r"ActiveBuildRoot/Library/Caches/com.apple.xbs/Sources/IDEFrameworks/" |
| 119 |
r"IDEFrameworks-\d+/IDEFoundation/Provisioning" |
| 120 |
r"/Capabilities Infrastructure/IDECapabilityQuerySelection.swift:\d+" |
| 121 |
) |
| 122 |
|
| 123 |
def __init__(self): |
| 124 |
self.dvt_ignore_count = 0 |
| 125 |
self.locked_device = False |
| 126 |
|
| 127 |
def __call__(self, line): |
| 128 |
"""Filter a single line of a log. |
| 129 |
|
| 130 |
:param line: A single line of raw system log content, including the newline. |
| 131 |
""" |
| 132 |
if self.dvt_ignore_count: |
| 133 |
self.dvt_ignore_count -= 1 |
| 134 |
elif self.locked_device: |
| 135 |
if self.LOCKED_DEVICE_END_RE.match(line): |
| 136 |
self.locked_device = False |
| 137 |
elif self.LOCKED_DEVICE_START_RE.match(line): |
| 138 |
# Start ignoring content until the end line is found. |
| 139 |
self.locked_device = True |
| 140 |
elif self.LOCKED_DEVICE_ADDITIONAL_RE.match(line): |
| 141 |
# Ignore the additional 1-line warning about failing to start the service. |
| 142 |
pass |
| 143 |
elif self.DEVICE_ENABLED_STATE_RE.match(line): |
| 144 |
# Ignore the DVTCoreDeviceEnabledState warning |
| 145 |
pass |
| 146 |
elif self.DVT_ASSERTIONS_RE.match(line): |
| 147 |
# Ignore the 4 lines after the DVTAssertions message |
| 148 |
self.dvt_ignore_count = 4 |
| 149 |
else: |
| 150 |
yield line |