From 0cab4469b2d9c2ec6012ddf94294120fe773c229 Mon Sep 17 00:00:00 2001 From: Kevin Gozali Date: Wed, 14 Apr 2021 19:46:00 -0700 Subject: [PATCH] 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 --- React/Base/RCTAssert.h | 8 ++++++++ React/Base/RCTAssert.m | 26 ++++++++++++++++++++++++++ React/Base/RCTDefines.h | 10 ++++++++++ 3 files changed, 44 insertions(+) diff --git a/React/Base/RCTAssert.h b/React/Base/RCTAssert.h index 95b37cc785d..d4ec7fc40c2 100644 --- a/React/Base/RCTAssert.h +++ b/React/Base/RCTAssert.h @@ -169,3 +169,11 @@ RCT_EXTERN NSString *RCTFormatStackTrace(NSArray *> } 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); diff --git a/React/Base/RCTAssert.m b/React/Base/RCTAssert.m index 087900d1979..4f40bbfa01a 100644 --- a/React/Base/RCTAssert.m +++ b/React/Base/RCTAssert.m @@ -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). +} diff --git a/React/Base/RCTDefines.h b/React/Base/RCTDefines.h index 23be65eb5c6..b416f71a635 100644 --- a/React/Base/RCTDefines.h +++ b/React/Base/RCTDefines.h @@ -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