Skip to content
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

Update to latest idb to enable compatibility with more recent devices #7

Merged
merged 479 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
479 commits
Select commit Hold shift + click to select a range
0fd2a2e
Implement exclusive swift endpoint mode
May 5, 2022
4b0381c
Handle IDB_USE_SWIFT_AS_DEFAULT for proper logging
May 5, 2022
38636f2
Properly implement port extraction in swift endpoint
May 5, 2022
658ff4c
Add iPhone 13* devices
fejese May 6, 2022
923bd97
Implement FBTeardownContext
May 9, 2022
6b40663
Bridge FBFutureContext to swift concurrency world
May 9, 2022
db37a8d
Implement idb push
May 9, 2022
60c9b1a
Implement Atomic as a class to properly pass between concurrency context
May 9, 2022
3a142b1
Implement tail command
May 9, 2022
d10a778
Implement uninstall command
May 10, 2022
4bb8487
Implement focus command
May 10, 2022
9e414b1
Implement simulate_memory_warning
May 10, 2022
70406cb
Implement send-notification command
May 10, 2022
b235eb3
Implement set-location command
May 10, 2022
9b429cc
Implement crash list command
May 10, 2022
3e619f7
Add explicit temporary directory path
May 11, 2022
dc5c05d
formatting changes from black 22.3.0
amyreese May 12, 2022
92db991
apply import merging for fbcode (6 of 11)
amyreese May 15, 2022
d020f72
Add bsdtar -m flag to Archive Operation
jbardini May 16, 2022
f8c93e1
Add option to override m_time on Temporary Directory
jbardini May 16, 2022
dcd17cf
Add flag to app install to ignore mtime in .ipa archives
jbardini May 16, 2022
3cc2e69
Add --override-mtime to cli
jbardini May 16, 2022
5a020b2
XCTest list-bundle in Swift
jbardini May 16, 2022
b28e15b
Fix file draining pipe
May 17, 2022
dbad671
Implement crash show command
May 17, 2022
bd86b9f
Implement crash delete command
May 17, 2022
a412098
Implement contacts_update method
May 17, 2022
8ef2154
Implement get_setting command
May 17, 2022
b7930d3
Implement TaskSelect for concurrency
May 17, 2022
cf8eac6
Implement video_stream command in swift
May 17, 2022
70cc77a
Fix server startup interface
May 17, 2022
9a7b0ef
Remove unused queue parameter from archive operation
May 17, 2022
138c3b5
Change listTestDescriptorsWithError: to use NSArray
jbardini May 17, 2022
b0df679
List XCTest bundles in Swift
jbardini May 17, 2022
916294d
Use relatie paths on Bridging header
jbardini May 17, 2022
335da28
Fix futures chaining in `runTestWithLaunchConfiguration:reporter:logg…
jbardini May 19, 2022
3bacc76
Standardise on FBTestApplicationsPair to create FBApplicationLaunchCo…
jbardini May 19, 2022
d7389ad
Disambiguate appBundleId for App tests
jbardini May 19, 2022
061bbd1
Fix FBXCTestRunFileReader crash
jbardini May 20, 2022
5b12548
Fix undefined behaviour causing crash by preventing closing stdin fil…
May 23, 2022
07e25e6
Implement instruments command
May 23, 2022
54927d9
Implement xctrace command
May 23, 2022
684efe2
Implement Task.timeout
May 23, 2022
baa4e00
Implement dap command
May 23, 2022
1e91c4d
Implement debugserver method
May 23, 2022
39c8664
Implement add_media method
May 23, 2022
b8d8837
Allow not returning bundle results from running xctest
May 24, 2022
fc9f2a8
Do not download screenshots if we don't return the results
May 24, 2022
f5370c1
Move FBScubaSample to swift
May 25, 2022
7ccabe3
Move FBIDBConfiguration to swift
May 25, 2022
6af872a
Add logging interceptor to grpc-swift
May 25, 2022
f261e9c
Refactor MethodPathSetter to MethodInfoSetter interceptor
May 25, 2022
5864b2b
Add swift nativeness log into scuba sample
May 25, 2022
19b71cf
Report grpc-swift method calls to event reporter
May 25, 2022
b4da610
Expand target and dependencies paths on xctestrunfilepaths
jbardini May 26, 2022
9656039
Skip IO setup for tests driven by xctestrun files
jbardini May 26, 2022
ec36447
One less usage of appBundleId
jbardini May 26, 2022
8a540b7
Replace appBundleId with testTargetAppBundleId
jbardini May 26, 2022
8144fec
suppress errors in `fbcode/idb` - batch 1
Jun 8, 2022
6bd49da
Defined killswitch API protocols
Jun 16, 2022
6455dad
Inject IDBKillswitch for OSS and internal builds
Jun 16, 2022
276c9cc
Implement request suspension until killswitch determination
Jun 16, 2022
1d1ccb7
Implement TaskFBFuture
Jun 16, 2022
cdb5d7d
Implement IDBKillswitchBridge
Jun 16, 2022
34d24ff
Move swift endpoint determination implementation to global config from
Jun 16, 2022
0acd7a7
Increase error verbosity to the client output
Jun 16, 2022
44b0b99
Add mac aux directory info
Jun 20, 2022
c1eaafa
Hold strong reference on sim set in FBSimulator
Jun 20, 2022
eacf58f
Show mounted disk image if it's not known to xcode
Jun 20, 2022
54e85fa
Clean up unix domain socket before server start
Jun 22, 2022
26ca040
Update grpc-swift version to 1.8.0
Jun 23, 2022
5ff9d1e
Create gzip from input stream
jbardini Jun 27, 2022
765448f
Stream output of llvm-export to gzip
jbardini Jun 27, 2022
e4fe249
Fix opensource build configuration
Jun 28, 2022
a67f9d9
Do not include user info output if it is empty
Jun 29, 2022
4acdce1
Fix debugserver command
Jun 29, 2022
631f47d
Add userInfo to XCTAttachment in proto
Jun 29, 2022
1c1c5ee
Extract userInfo from test result to FBAttachment
Jun 29, 2022
4b1e582
Send XCTAttachment user info to idb client
Jun 29, 2022
31aaccd
Report attachments user info
Jun 29, 2022
7d61000
Fix tests when no user attachment present
Jul 5, 2022
cbb5848
Fix crash log list crash
Jul 13, 2022
1979d2c
Improved `shell` Command Description
Jul 14, 2022
119e4a8
Allow to load developer disk image from custom locations
Jul 15, 2022
5c64d43
Move utilities without dependencies to separate module
Jul 19, 2022
7df86a5
Add convenience wrappers that will replace wrappedValue setter
Jul 19, 2022
a59c094
Forced all code to synchronize explicitly when using atomics
Jul 19, 2022
9e3549c
Create FIFOStreamWriter to bridge sync and async writes properly
Jul 19, 2022
1bb8c7c
Move all data consumers to FIFO response writer
Jul 19, 2022
31b6ed0
Fix aperture framebuffer reference storage
Jul 19, 2022
e449376
Make settings naming broader to lay groundwork for revoking permissions
dado3212 Jul 22, 2022
f05a91e
Add in new command to revoke permissions
dado3212 Jul 22, 2022
29a74ec
Add in client changes for revoke API
dado3212 Jul 22, 2022
fecbba1
Remove proxying logic from grpc-swift server
Aug 3, 2022
9287ac3
Remove cpp usage from main
Aug 3, 2022
658169c
Remove cpp files
Aug 3, 2022
feb8ceb
Remove cpp dependency from pods
Aug 3, 2022
2b0b496
Remove grpc-swift determination code from client
Aug 3, 2022
e3fa0b2
Readable log file names
jbardini Aug 4, 2022
f638fbb
Use "standalone" mode to launch logic tests
jbardini Aug 8, 2022
facd511
Fix grpc-swift source files generation in OSS release builds
Aug 9, 2022
203ca3b
Switch to universal binary building for OSS
Aug 12, 2022
7a43463
Remove noisy log message
fgasperij Aug 15, 2022
e72bcc2
Create script to simplify OSS release
Aug 18, 2022
0e4e93b
Add MixedTests binary fixture
Aug 26, 2022
6754fd1
Reduce number of parallel SQLite command when revoking permissions
dado3212 Sep 7, 2022
afb4eb9
Add missing file to testMappedPathPushDirectory
jamescoggan Sep 9, 2022
55d7641
Add nother missing file in FBSimulatorControl:FBControlCoreTests
jamescoggan Sep 13, 2022
41d5da8
Handle non-JSON-serialisable Accessibility data
jbardini Sep 26, 2022
cd554d5
Add VOD Spec Parser
Oct 12, 2022
ff90440
Implement method extraction for `objc_reference_method`s
Oct 17, 2022
438745d
Handle test identifiers prefixed by with Swift module name
jbardini Nov 3, 2022
7d6f21a
Fixing deprecation issue
Nov 7, 2022
4695dc0
Move Connection error diagnosis one step earlier
jbardini Nov 10, 2022
2e7a571
Move crash log reporting to its own method
jbardini Nov 10, 2022
25d7d21
Look for a crash log when bundle connection fails
jbardini Nov 10, 2022
8faba53
Updated grpc version in OSS
Nov 15, 2022
a84d5f4
Upgrade yarn packages
Nov 29, 2022
13811ca
Correct regex to parse running processes
jbardini Dec 12, 2022
1b7fd62
Move stackshot to FBProcessFetcher
jbardini Dec 12, 2022
a4a5a43
Sample stack of host app process on bundle connection timeout
jbardini Dec 12, 2022
c5d0ebd
upgrade pyre version in `fbcode/idb` - batch 1
Dec 14, 2022
7835f7b
fbobjc/EndToEndTests
Dec 15, 2022
9f5728a
Conform FBTeardownContext to Sendable
Jan 3, 2023
0dffb4e
Increased timeout waiting for host process startup
Jan 4, 2023
99f8206
Increased intermediate timeouts for connecting to the resource bundle
Jan 9, 2023
a8239a0
Reporting Additional Test Failure Assertions
Jan 11, 2023
5278172
Reporting Additional Test Failure Assertions
Jan 11, 2023
91c78ab
Reporting Additional Test Failure Assertions
Jan 11, 2023
43eb43e
Fixed OSS project build
Jan 16, 2023
8d8c56c
fbobjc/EndToEndTests
Jan 18, 2023
90e761a
fix two small typos (#783)
dweekly Jan 19, 2023
041409b
Send `--install-dsym-test-bundle` warning to stderr
jbardini Feb 9, 2023
95db163
Refactored integration tests
Feb 15, 2023
ff832e0
Increased test setup timeout
Feb 28, 2023
0249c05
upgrade pyre version in `fbcode/idb` - batch 1
Mar 22, 2023
bef98c1
fbobjc/EndToEndTests
Mar 29, 2023
c798996
Ignore terminated application error while cleaning simulators
Apr 4, 2023
058d974
Removed all hardcoded simulator architectures from target description
Apr 12, 2023
a547f27
Rethrow not test related errors
Apr 12, 2023
d5bdcc4
Implemented cross-architecture support for logic tests
Apr 12, 2023
b2ca1d2
Raised minimum supported version to 11.0
Apr 12, 2023
af78398
Replace hasattr with getattr in idb/cli/commands/xctest.py
r-barnes Apr 12, 2023
0cb31d6
fbobjc/EndToEndTests
Apr 13, 2023
b228c89
Support starting idb_companion with a given architecture
Apr 13, 2023
fd02538
Better Message around supported architectures
Apr 17, 2023
da11cd4
Moved back accidentally deleted arm64e check
Apr 17, 2023
df3b085
update argument for -Wstrict-prototypes
Apr 24, 2023
f912ab1
fix -Wstrict-prototypes break
Apr 24, 2023
3a43ef7
Fix FBSimulatorConfigurationTests build
jbardini Apr 27, 2023
1c3b15f
Fix FBControlCoreTests tests
jbardini Apr 27, 2023
4de0d27
Select test process architecture based on test bundle and host processor
jbardini May 2, 2023
9550c4c
Add an option to skip signing xctest bundles
May 3, 2023
f9260ef
Add --skip-signing-bundles to cli
May 3, 2023
1695452
Added additional search path for dylibs in test load
May 11, 2023
8ec8c3f
Fix 'function declaration without a prototype'
jbardini May 18, 2023
10d67ce
Fix typo in error message
May 24, 2023
41f6ca0
Fixed IDB Crash on Empty Crash String
Jun 8, 2023
5613c2d
Implemented process adapter for test listing
Jun 12, 2023
de20617
Fixed supported bundle architectures determination for macos
Jun 12, 2023
6a2a7b9
More FBCrashLog from File Error Messaging
Jun 19, 2023
34a87a6
Update `approve` to suport iOS 17
jbardini Jun 21, 2023
2cb0fc2
Do not adapt listing process if wrapped in app
Jun 21, 2023
fac1a38
Fixing Crash Log Reporting
Jun 27, 2023
6a98c2a
Update semver version to skip vulnerable versions
fgasperij Jun 28, 2023
ac15bff
Use tmp directory to store macOS Tests
Jul 7, 2023
10fcbb5
No B-frames for idb video streams
Aug 10, 2023
70fb9cb
Allow configuring key frame rate for video streams
Aug 10, 2023
3613b17
Actually kill launched applicatio, up on test bundle disconnection
Aug 15, 2023
6defdd1
Implement FBMacLaunchedApplication
Aug 15, 2023
011e53a
Add --coverage-file-suffix option
maru Aug 15, 2023
de64c69
Use same LLVM_PROFILE_FILE format as in Xcode 14.3.1
maru Aug 15, 2023
2e1da44
Changing Error Type In Event of Crash
Aug 21, 2023
1996508
Fix OSS build
Aug 23, 2023
044f1d0
Move protocol versions constants
jbardini Aug 24, 2023
4faada5
Improve test session initialisation error logging
jbardini Aug 24, 2023
b930660
Rename option to --enable-continuous-coverage-collection
maru Aug 25, 2023
4ab2ca1
Rename option to --enable-continuous-coverage-collection
maru Aug 25, 2023
aa4bc2c
Del `(object)` from 50 inc hwcontrol/lib/rotor.py
r-barnes Aug 27, 2023
c7205d7
Document callbacks that support UI Tests target app process management
jbardini Aug 29, 2023
cf079b1
Make FBTestConfig available in FBTestManagerContext
jbardini Aug 30, 2023
959913d
Import new test execution headers
jbardini Aug 30, 2023
79cf1b7
Upgrade test execution protocols
jbardini Aug 30, 2023
a619158
Move Shim's swizzle helpers to their own file
jbardini Aug 30, 2023
dc14728
Move Shim's XCTest helpers to their own file
jbardini Aug 30, 2023
ae57892
Force swift module prefix in test identifiers
jbardini Aug 30, 2023
dc48813
Record failures from tests
Aug 30, 2023
262f5c6
Record activities from tests
Aug 30, 2023
d0e54ff
Add an additional touch down event at the end of swipes to avoid iner…
Sep 3, 2023
539b158
Increase crash wait timeout
Sep 4, 2023
84c1175
Retry openURL two times
Sep 7, 2023
bf12a98
Use existing ImageTypeKey/ImageSignatureKey in FBDeviceDeveloperDiskI…
Sep 12, 2023
fdb96ec
Add iPhone 14* and 15* devices
fejese Sep 18, 2023
0e0f56a
Log output of companion commands when command fails
fejese Sep 19, 2023
2e4b8f5
Apply idb --only option to local idb executor
Sep 26, 2023
6d3f253
Do not try to remove app that is already removed
Sep 26, 2023
b330077
Install applications to randomized directories
Sep 26, 2023
a823d32
Delete FBInternGraph.
Oct 9, 2023
4bb66c2
Fix pyre-fixmes
Joald Oct 13, 2023
f8cba4c
idb
Oct 19, 2023
d2809aa
Print an error if attempting to launch apps on iOS 17+ devices.
bwhiteley Oct 26, 2023
120ace6
Add missing arm64e to base architecture map
jbardini Oct 26, 2023
cd920cc
Print an error if attempting to debug apps on iOS 17+ devices.
bwhiteley Oct 27, 2023
2098666
fix: typos in README.md (#832)
saheem128 Nov 10, 2023
673d22e
Fixing Lost Test Case Did Start
Nov 15, 2023
6e60cce
Extract idb_companion logic into a lib
jbardini Nov 15, 2023
5340a13
Extracting Stack Trace From The IPS File
Nov 15, 2023
41cdacb
Reporting Crashed Thread on Unhosted Tests
Dec 1, 2023
fc89a00
Move BridgeFuture to Companion Lib
jbardini Dec 11, 2023
da0ff38
Declare unsafe FBSimulator initializer
jbardini Dec 12, 2023
0d44466
use devicectl to launch apps on iOS 17 devices.
bwhiteley Dec 13, 2023
eeb409d
Signal process under test termination uppon crashes
jbardini Jan 16, 2024
6855b37
Implement continuous coverage for logic tests
jbardini Jan 16, 2024
fdce027
upgrade pyre version in `fbcode/idb` - batch 1
Jan 24, 2024
f07afee
Always create temp dir for coverage data
jbardini Jan 24, 2024
4a9277d
`XCTAssertTrue(NO);` -> `XCTFail();`
Jan 25, 2024
e44d0f0
Replace "assign" annotation with "weak" for id properties
Feb 2, 2024
93d0ec9
Add annotations to AccessibilityPlatformTranslation headers
Feb 15, 2024
05ecd00
Return PID of element in ui describe output
Feb 15, 2024
29c744e
Extract FBSimulatorAccessibilitySerializer
Feb 15, 2024
93ec34d
Encapsulate fetching of AXPTranslationObject via FBSimulator_Translat…
Feb 15, 2024
9a9f803
Add -[FBSimulatorLaunchCtlCommands serviceNameForProcessIdentifier:]
Feb 15, 2024
f843669
Inline translationCallbackForToken
Feb 15, 2024
e1a503b
Remediate empty describe-all by restarting CoreSimulatorService after…
Feb 15, 2024
e85ad77
Fix crasher on describe-point
Feb 15, 2024
2dfb5c8
remove prefix_headers
rmaz Feb 16, 2024
ddfc3b9
Add support for idb-targets to iOS RM
Feb 23, 2024
f608ea3
Back out "Add support for idb-targets to iOS RM"
Joald Feb 29, 2024
10c4638
Pyre Configurationless migration for] [batch:21/112] [shard:6/N]
Mar 2, 2024
a2015dd
apply Black 2024 style in fbcode (16/17)
amyreese Mar 4, 2024
10de9e5
Fix usages of archivedDataWithRootObject: in tests (1/2)
Mar 22, 2024
fb37e20
Fix typo (#854)
dnicolson Mar 27, 2024
6ef43e6
fix: typo in readme (#833)
aike19115 Mar 27, 2024
269c025
Updating link for PIP installation (#855)
abranhe Mar 27, 2024
5842d43
Extend the timeout of test listing
sodastsai Mar 27, 2024
069f0af
Fixed file creation on RI
Apr 4, 2024
f77cff7
sed died -> exited
Apr 10, 2024
81af61d
Do not install app bundle into Application folder for macOS
Apr 18, 2024
c9a22ab
Write Test Configuration to the container of a test bundle, instead o…
sodastsai Apr 24, 2024
69a2f58
Use symlink to persistence xctest bundle instead of copying to speed …
sodastsai Apr 24, 2024
d5bb296
Convert the CircleCI workflow to a GitHub Actions workflow (#861)
jk0 Apr 26, 2024
5ff7c92
Inline single-use method
May 7, 2024
45666c7
Fix incorrect os version for simulators
May 7, 2024
9b4a7a0
Fix silently skipped async tests (idb)
May 28, 2024
b7b807a
fix unit tests
Jun 3, 2024
c0ad626
Use new mypy-protobuf for all Python GRPC builds
Jun 6, 2024
57595df
Merge remote-tracking branch 'upstream/main' into update-to-latest
juho-gavert Jul 2, 2024
3e55180
missing FBDeviceApplicationCommands?
juho-gavert Jul 11, 2024
f4845f1
Add missing InvalidateAFCHouseArrest method that was recently added t…
guillaumelevass Oct 1, 2024
91e7909
Update dylibs
guillaumelevass Oct 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ version: 2
jobs:
deploy-website:
docker:
- image: circleci/node:14.11.0
- image: cimg/node:16.14.0

steps:
- checkout
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: facebook/idb/build_and_deploy
on:
push:
branches:
- main
jobs:
deploy-website:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- uses: actions/setup-node@v4
with:
node-version: 16.14.0
- name: Deploying to GitHub Pages
run: |
git config --global user.email "[email protected]"
git config --global user.name "Website Deployment Script"
echo "machine github.com login docusaurus-bot password ${{ secrets.GITHUB_TOKEN }}" > ~/.netrc
echo "Deploying website..."
cd website && yarn install && GIT_USER=docusaurus-bot USE_SSH=false yarn deploy
205 changes: 205 additions & 0 deletions CompanionLib/BridgeFuture/BridgeFuture.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import FBControlCore
import Foundation
import IDBCompanionUtilities

enum FBFutureError: Error {

/// This indicates an error in objc code where result callback was called but no error or result provided. In case of this, debug `FBFuture` implementation.
case continuationFullfilledWithoutValues

/// This indicates an error in `BridgeFuture.values` implementation. In case of this, debug `BridgeFuture.values` implementation.
case taskGroupReceivedNilResultInternalError
}

/// Swift compiler does not allow usage of generic parameters of objc classes in extension
/// so we need to create a bridge for convenience.
public enum BridgeFuture {

/// Use this to receive results from multiple futures. The results are **ordered in the same order as passed futures**, so you can safely access them from
/// array by indexes.
/// - Note: We should *not* use @discardableResult, results should be dropped explicitly by the callee.
public static func values<T: AnyObject>(_ futures: FBFuture<T>...) async throws -> [T] {
let futuresArr: [FBFuture<T>] = futures
return try await values(futuresArr)
}

/// Use this to receive results from multiple futures. The results are **ordered in the same order as passed futures**, so you can safely access them from
/// array by indexes.
/// - Note: We should *not* use @discardableResult, results should be dropped explicitly by the callee.
public static func values<T: AnyObject>(_ futures: [FBFuture<T>]) async throws -> [T] {
return try await withThrowingTaskGroup(of: (Int, T).self, returning: [T].self) { group in
var results = [T?].init(repeating: nil, count: futures.count)

for (index, future) in futures.enumerated() {
group.addTask {
return try await (index, BridgeFuture.value(future))
}
}

for try await (index, value) in group {
results[index] = value
}

return try results.map { value -> T in
guard let shouldDefinitelyExist = value else {
assertionFailure("This should never happen. We should fullfill all values at that moment")
throw FBFutureError.taskGroupReceivedNilResultInternalError
}
return shouldDefinitelyExist
}
}
}

/// Awaitable value that waits for publishing from the wrapped future
/// - Note: We should *not* use @discardableResult, results should be dropped explicitly by the callee.
public static func value<T: AnyObject>(_ future: FBFuture<T>) async throws -> T {
try await withTaskCancellationHandler {
try await withCheckedThrowingContinuation { continuation in
future.onQueue(BridgeQueues.futureSerialFullfillmentQueue, notifyOfCompletion: { resultFuture in
if let error = resultFuture.error {
continuation.resume(throwing: error)
} else if let value = resultFuture.result {
// swiftlint:disable force_cast
continuation.resume(returning: value as! T)
} else {
continuation.resume(throwing: FBFutureError.continuationFullfilledWithoutValues)
}
})
}
} onCancel: {
future.cancel()
}
}

/// Awaitable value that waits for publishing from the wrapped future.
/// This is convenient bridgeable overload for dealing with objc `NSArray`.
/// - Warning: This operation not safe (as most of objc bridge). That means you should be sure that type bridging will succeed.
/// Consider this method as
///
/// ```
/// // ------- command_executor.m
/// - (FBFuture<NSArray<NSNumer> *> *)doTheThing;
///
/// // ------- swiftfile.swift
/// let futureFromObjc: FBFuture<NSArray> = command_executor.doTheThing() // Note: NSNumber is lost
/// let withoutBridge = BridgeFuture.value(futureFromObjc) // withoutBridge: NSArray
/// let withBridge: [NSNumer] = BridgeFuture.value(futureFromObjc) // withBridge: [NSNumber]
///
/// // But this starts to shine more when you have to pass results to methods/return results, e.g.
/// func operation() -> [Int] {
/// return BridgeFuture.value(futureFromObjc)
/// }
///
/// // Or pass value to some oter method
/// func someMethod(accepts: [NSNumber]) { ... }
///
/// self.someMethod(accepts: BridgeFuture.value(futureFromObjc)
/// ```
public static func value<T>(_ future: FBFuture<NSArray>) async throws -> [T] {
let objcValue = try await value(future)
// swiftlint:disable force_cast
return objcValue as! [T]
}

/// Awaitable value that waits for publishing from the wrapped future.
/// This is convenient bridgeable overload for dealing with objc `NSDictionary`.
/// - Warning: This operation not safe (as most of objc bridge). That means you should be sure that type bridging will succeed.
/// Consider this method as
///
/// ```
/// // ------- command_executor.m
/// - (FBFuture<NSDictionary<FBInstalledApplication *, id> *> *)doTheThing;
///
/// // ------- swiftfile.swift
/// let futureFromObjc: FBFuture<NSDictionary> = command_executor.doTheThing() // Note: types is lost
/// let withoutBridge = BridgeFuture.value(futureFromObjc) // withoutBridge: NSDictionary
/// let withBridge: [FBInstalledApplication: Any] = BridgeFuture.value(futureFromObjc) // withBridge: [FBInstalledApplication: Any]
///
/// // But this starts to shine more when you have to pass results to methods/return results, e.g.
/// func operation() -> [FBInstalledApplication: Any] {
/// return BridgeFuture.value(futureFromObjc)
/// }
///
/// // Or pass value to some oter method
/// func someMethod(accepts: [FBInstalledApplication: Any]) { ... }
///
/// self.someMethod(accepts: BridgeFuture.value(futureFromObjc)
/// ```
public static func value<T: Hashable, U>(_ future: FBFuture<NSDictionary>) async throws -> [T: U] {
let objcValue = try await value(future)
// swiftlint:disable force_cast
return objcValue as! [T: U]
}

/// NSNull is Void equivalent in objc reference world. So is is safe to ignore the result.
public static func await(_ future: FBFuture<NSNull>) async throws {
_ = try await Self.value(future)
}

/// This overload exists because of `FBMutableFuture` does not convert its exact generic type automatically but it can be automatically converted to `FBFuture<AnyObject>`
/// without any problems. This decision may be revisited in future.
public static func await(_ future: FBFuture<AnyObject>) async throws {
_ = try await Self.value(future)
}

/// Interop between swift and objc generics are quite bad, so we have to write wrappers like this.
/// By default swift bridge compiler could not convert generic type of `FBMutableFuture`. But this force cast is 100% valid and works in runtime
/// so we just use this little helper.
public static func convertToFuture<T: AnyObject>(_ mutableFuture: FBMutableFuture<T>) -> FBFuture<T> {
let future: FBFuture<AnyObject> = mutableFuture
// swiftlint:disable force_cast
return future as! FBFuture<T>
}

/// Split FBFutureContext to two pieces: result and later cleanup closure
/// - Parameter futureContext: source future context
/// - Returns: Tuple of extracted result and cleanup closure that **should** be called later to perform all required cleanups
public static func value<T: AnyObject>(_ futureContext: FBFutureContext<T>) async throws -> T {
try FBTeardownContext.current.addCleanup {
let cleanupFuture = futureContext.onQueue(BridgeQueues.futureSerialFullfillmentQueue) { (result: Any, teardown: FBMutableFuture<NSNull>) -> NSNull in
teardown.resolve(withResult: NSNull())
return NSNull()
}
try await BridgeFuture.await(cleanupFuture)
}

return try await value(futureContext.future)
}

/// Awaitable value that waits for publishing from the wrapped futureContext.
/// This is convenient bridgeable overload for dealing with objc `NSArray`.
/// - Warning: This operation not safe (as most of objc bridge). That means you should be sure that type bridging will succeed.
/// Consider this method as
///
/// ```
/// // ------- command_executor.m
/// - (FBFuture<NSArray<NSNumer> *> *)doTheThing;
///
/// // ------- swiftfile.swift
/// let futureFromObjc: FBFuture<NSArray> = command_executor.doTheThing() // Note: NSNumber is lost
/// let withoutBridge = BridgeFuture.value(futureFromObjc) // withoutBridge: NSArray
/// let withBridge: [NSNumer] = BridgeFuture.value(futureFromObjc) // withBridge: [NSNumber]
///
/// // But this starts to shine more when you have to pass results to methods/return results, e.g.
/// func operation() -> [Int] {
/// return BridgeFuture.value(futureFromObjc)
/// }
///
/// // Or pass value to some oter method
/// func someMethod(accepts: [NSNumber]) { ... }
///
/// self.someMethod(accepts: BridgeFuture.value(futureFromObjc)
/// ```
public static func values<T: AnyObject, U>(_ futureContext: FBFutureContext<T>) async throws -> [U] {
let objcValue = try await value(futureContext)
// swiftlint:disable force_cast
return objcValue as! [U]
}
}
27 changes: 27 additions & 0 deletions CompanionLib/BridgeFuture/BridgeQueues.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import Foundation

/// Queues collection to bring objc and async-swift worlds together
public enum BridgeQueues {

/// Plain serial queue that is primarily used to convert *all* FBFuture calls to swift awaitable values
public static let futureSerialFullfillmentQueue = DispatchQueue(label: "com.facebook.fbfuture.fullfilment")

/// Some of *commandExecutor* operations requires DispatchQueue to send response.
/// The only purpose of everything handled inside this queue is to passthrough call to swift async world via calling swift `Task` api
/// ```
/// commandExecutor.doSomething(onQueue: BridgeQueues.miscEventReaderQueue) { jobResult in
/// Task {
/// try? await responseStream.send(jobResult)
/// }
/// }
/// ```
///
public static let miscEventReaderQueue = DispatchQueue(label: "com.facebook.miscellaneous.reader", qos: .userInitiated, attributes: .concurrent)
}
24 changes: 24 additions & 0 deletions CompanionLib/CompanionLib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#import <CompanionLib/FBIDBCommandExecutor.h>
#import <CompanionLib/FBXCTestDescriptor.h>
#import <CompanionLib/FBIDBLogger.h>
#import <CompanionLib/FBCodeCoverageRequest.h>
#import <CompanionLib/FBIDBLogger.h>
#import <CompanionLib/FBDsymInstallLinkToBundle.h>
#import <CompanionLib/FBXCTestRunRequest.h>
#import <CompanionLib/FBDataDownloadInput.h>
#import <CompanionLib/FBIDBLogger.h>
#import <CompanionLib/FBIDBStorageManager.h>
#import <CompanionLib/FBIDBTestOperation.h>
#import <CompanionLib/FBiOSTargetProvider.h>
#import <CompanionLib/FBTestApplicationsPair.h>
#import <CompanionLib/FBXCTestDescriptor.h>
#import <CompanionLib/FBXCTestReporterConfiguration.h>
#import <CompanionLib/FBXCTestRunFileReader.h>
#import <CompanionLib/FBIDBError.h>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
Expand Down
Loading