From adbef6cb2ddbb1f8986a40a7fb6d07b866b6c856 Mon Sep 17 00:00:00 2001 From: Marco Saia Date: Wed, 12 Aug 2026 11:52:37 +0200 Subject: [PATCH 1/2] fix: tvOS build issue --- packages/core/ios/Sources/DdSdk.mm | 2 + .../ios/Sources/DdSdkImplementation.swift | 1 - .../ios/Tests/TvOSCompatibilityTests.swift | 111 ++++++++++++++++++ 3 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 packages/core/ios/Tests/TvOSCompatibilityTests.swift diff --git a/packages/core/ios/Sources/DdSdk.mm b/packages/core/ios/Sources/DdSdk.mm index c05ac6a7c..fabbfffa9 100644 --- a/packages/core/ios/Sources/DdSdk.mm +++ b/packages/core/ios/Sources/DdSdk.mm @@ -122,12 +122,14 @@ + (void)initFromNative { [self telemetryError:message stack:stack kind:kind resolve:resolve reject:reject]; } +#if TARGET_OS_IOS RCT_REMAP_METHOD(consumeWebviewEvent, withWebviewMessage:(NSString*)message withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject) { [self consumeWebviewEvent:message resolve:resolve reject:reject]; } +#endif RCT_EXPORT_METHOD(clearAllData:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject) diff --git a/packages/core/ios/Sources/DdSdkImplementation.swift b/packages/core/ios/Sources/DdSdkImplementation.swift index 8a2a455d8..7a838055a 100644 --- a/packages/core/ios/Sources/DdSdkImplementation.swift +++ b/packages/core/ios/Sources/DdSdkImplementation.swift @@ -10,7 +10,6 @@ import DatadogInternal import DatadogLogs import DatadogRUM import DatadogTrace -import DatadogWebViewTracking import Foundation import React diff --git a/packages/core/ios/Tests/TvOSCompatibilityTests.swift b/packages/core/ios/Tests/TvOSCompatibilityTests.swift new file mode 100644 index 000000000..a7926ccae --- /dev/null +++ b/packages/core/ios/Tests/TvOSCompatibilityTests.swift @@ -0,0 +1,111 @@ +/* + * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. + * This product includes software developed at Datadog (https://www.datadoghq.com/). + * Copyright 2016-Present Datadog, Inc. + */ + +import Foundation +import XCTest + +/// `DatadogWebViewTracking` and the `consumeWebviewEvent` bridge method are iOS-only (the +/// framework isn't published for tvOS, see the podspec's `s.ios.dependency 'DatadogWebViewTracking'`). +/// +/// This test statically enforces that every reference to these symbols in `Sources` is wrapped in +/// a platform guard (`#if os(iOS)` for Swift, `#if TARGET_OS_IOS` for Objective-C++), as a +/// lightweight substitute for an actual tvOS build. +final class TvOSCompatibilityTests: XCTestCase { + private static let iOSOnlySymbols = ["DatadogWebViewTracking", "WebViewTracking", "consumeWebviewEvent"] + + private static let swiftGuardPattern = "os(iOS)" + private static let objcGuardPattern = "TARGET_OS_IOS" + + func testIOSOnlySymbolsAreGuardedInSwiftSources() throws { + for url in try swiftSourceFiles() { + try assertSymbolsAreGuarded( + in: url, + guardPattern: Self.swiftGuardPattern + ) + } + } + + func testIOSOnlySymbolsAreGuardedInObjectiveCSources() throws { + for url in try objectiveCSourceFiles() { + try assertSymbolsAreGuarded( + in: url, + guardPattern: Self.objcGuardPattern + ) + } + } + + // MARK: - Helpers + + private func assertSymbolsAreGuarded(in url: URL, guardPattern: String) throws { + let contents = try String(contentsOf: url, encoding: .utf8) + // Each stack entry is (conditionMatchesGuard, parentIsGuarded); the level is + // guarded if either its own condition matches, or an enclosing level is guarded. + var stack: [(matches: Bool, parentGuarded: Bool)] = [] + + for (index, rawLine) in contents.components(separatedBy: .newlines).enumerated() { + let line = rawLine.trimmingCharacters(in: .whitespaces) + let lineNumber = index + 1 + + if line.hasPrefix("#if") { + let parentGuarded = stack.last.map { $0.matches || $0.parentGuarded } ?? false + stack.append((matches: line.contains(guardPattern), parentGuarded: parentGuarded)) + continue + } + if line.hasPrefix("#else") { + if let top = stack.last { + stack[stack.count - 1] = (matches: !top.matches, parentGuarded: top.parentGuarded) + } + continue + } + if line.hasPrefix("#endif") { + if !stack.isEmpty { + stack.removeLast() + } + continue + } + + let isGuarded = stack.last.map { $0.matches || $0.parentGuarded } ?? false + if isGuarded { + continue + } + + for symbol in Self.iOSOnlySymbols where line.contains(symbol) { + XCTFail( + "\(url.lastPathComponent):\(lineNumber) references iOS-only symbol " + + "'\(symbol)' without a '\(guardPattern)' guard. This will break the tvOS " + + "build: wrap this reference in the appropriate platform guard.", + file: #filePath, + line: UInt(lineNumber) + ) + } + } + } + + private func swiftSourceFiles() throws -> [URL] { + try sourceFiles(withExtension: "swift") + } + + private func objectiveCSourceFiles() throws -> [URL] { + try sourceFiles(withExtension: "mm") + sourceFiles(withExtension: "m") + } + + private func sourceFiles(withExtension extension: String) throws -> [URL] { + let sourcesDirectory = URL(fileURLWithPath: #filePath) + .deletingLastPathComponent() + .deletingLastPathComponent() + .appendingPathComponent("Sources") + + guard let enumerator = FileManager.default.enumerator( + at: sourcesDirectory, + includingPropertiesForKeys: nil + ) else { + XCTFail("Could not enumerate \(sourcesDirectory.path)") + return [] + } + + return enumerator.compactMap { $0 as? URL }.filter { $0.pathExtension == `extension` } + } +} From a30a6207fadcbf15f3307e0a529a111fccc4ffd2 Mon Sep 17 00:00:00 2001 From: Marco Saia <164892343+marco-saia-datadog@users.noreply.github.com> Date: Wed, 12 Aug 2026 12:01:46 +0200 Subject: [PATCH 2/2] fix(pr): rename protected keyword parameter Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- packages/core/ios/Tests/TvOSCompatibilityTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/ios/Tests/TvOSCompatibilityTests.swift b/packages/core/ios/Tests/TvOSCompatibilityTests.swift index a7926ccae..19434248d 100644 --- a/packages/core/ios/Tests/TvOSCompatibilityTests.swift +++ b/packages/core/ios/Tests/TvOSCompatibilityTests.swift @@ -92,7 +92,7 @@ final class TvOSCompatibilityTests: XCTestCase { try sourceFiles(withExtension: "mm") + sourceFiles(withExtension: "m") } - private func sourceFiles(withExtension extension: String) throws -> [URL] { + private func sourceFiles(withExtension fileExtension: String) throws -> [URL] { let sourcesDirectory = URL(fileURLWithPath: #filePath) .deletingLastPathComponent() .deletingLastPathComponent() @@ -106,6 +106,6 @@ final class TvOSCompatibilityTests: XCTestCase { return [] } - return enumerator.compactMap { $0 as? URL }.filter { $0.pathExtension == `extension` } + return enumerator.compactMap { $0 as? URL }.filter { $0.pathExtension == fileExtension } } }