-
Notifications
You must be signed in to change notification settings - Fork 62
[RUM-18034] fix: tvOS build issue #1367
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
Merged
marco-saia-datadog
merged 2 commits into
develop
from
marcosaia/rum-18034/ios-tv-os-build-issue
Aug 13, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 fileExtension: 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 == fileExtension } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.