iOS: Introduced RCT_NEW_ARCHITECTURE build flag to separate old vs new architecture

Summary:
In order to move away from the legacy system (bridge etc), we need to decouple the new architecture assumptions from it. This flag and assertion functions will help track the runtime and report violations along the way. The goal is to have 0 violation before switching over to the pure new architecture.

Note: this is not used right now.

Changelog: [Internal]

Reviewed By: JoshuaGross

Differential Revision: D27783246

fbshipit-source-id: 61f0d77c129bddcde7f24a803432f2d359c5bff3
This commit is contained in:
Kevin Gozali
2021-04-14 19:47:31 -07:00
committed by Facebook GitHub Bot
parent 5a2693d78f
commit 0cab4469b2
3 changed files with 44 additions and 0 deletions
+8
View File
@@ -169,3 +169,11 @@ RCT_EXTERN NSString *RCTFormatStackTrace(NSArray<NSDictionary<NSString *, id> *>
} while (0)
#endif
/**
* Controls for ensuring the new architecture runtime assumption holds.
* Note: this is work in progress.
*/
__attribute__((used)) RCT_EXTERN void RCTEnableNewArchitectureViolationReporting(BOOL enabled);
__attribute__((used)) RCT_EXTERN BOOL RCTNewArchitectureViolationReportingEnabled(void);
__attribute__((used)) RCT_EXTERN void RCTAssertAndTrackNewArchitectureViolation(NSString *violation);
+26
View File
@@ -230,3 +230,29 @@ RCTFatalExceptionHandler RCTGetFatalExceptionHandler(void)
{
return RCTCurrentFatalExceptionHandler;
}
// New architecture section.
static BOOL newArchitectureViolationReporting = NO;
void RCTEnableNewArchitectureViolationReporting(BOOL enabled)
{
newArchitectureViolationReporting = enabled;
}
BOOL RCTNewArchitectureViolationReportingEnabled(void)
{
return newArchitectureViolationReporting;
}
void RCTAssertAndTrackNewArchitectureViolation(NSString *violation)
{
if (!RCTNewArchitectureViolationReportingEnabled()) {
return;
}
#if RCT_NEW_ARCHITECTURE
RCTAssert(0, @"New architecture violation assertion: %@", violation);
#endif
// TODO: Actually track violations in a global space (separate from assertion).
}
+10
View File
@@ -142,3 +142,13 @@
@throw _RCTNotImplementedException(_cmd, [self class]); \
} \
_Pragma("clang diagnostic pop")
/**
* Controls for activating the new architecture without the legacy system.
* Note: this is work in progress.
*/
#ifdef REACT_NATIVE_FORCE_NEW_ARCHITECTURE
#define RCT_NEW_ARCHITECTURE 1
#else
#define RCT_NEW_ARCHITECTURE 0
#endif