diff --git a/ReactCommon/React-Fabric.podspec b/ReactCommon/React-Fabric.podspec index ee46e5f291b..e439a5d7e63 100644 --- a/ReactCommon/React-Fabric.podspec +++ b/ReactCommon/React-Fabric.podspec @@ -235,8 +235,7 @@ Pod::Spec.new do |s| s.subspec "debug_core" do |ss| ss.dependency folly_dep_name, folly_version ss.compiler_flags = folly_compiler_flags - ss.source_files = "react/debug/*.h", - "react/debug/ios/**/*.{m,mm,cpp,h}" + ss.source_files = "react/debug/**/*.{m,mm,cpp,h}" ss.exclude_files = "react/debug/tests" ss.header_dir = "react/debug" end diff --git a/ReactCommon/react/debug/BUCK b/ReactCommon/react/debug/BUCK index ef141d97dd0..20c7a930f8c 100644 --- a/ReactCommon/react/debug/BUCK +++ b/ReactCommon/react/debug/BUCK @@ -14,6 +14,10 @@ APPLE_COMPILER_FLAGS = get_apple_compiler_flags() rn_xplat_cxx_library( name = "debug", + srcs = glob( + ["**/*.cpp"], + exclude = glob(["tests/**/*.cpp"]), + ), headers = glob( ["**/*.h"], exclude = glob(["tests/**/*.h"]), @@ -36,10 +40,8 @@ rn_xplat_cxx_library( # for android react_native_assert "-llog", ], - fbandroid_srcs = glob(["android/**/*.cpp"]), fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), - fbobjc_srcs = glob(["ios/**/*.mm"]), force_static = True, labels = [ "pfh:ReactNative_CommonInfrastructurePlaceholder", diff --git a/ReactCommon/react/debug/CMakeLists.txt b/ReactCommon/react/debug/CMakeLists.txt index a985ac20a1c..ccfc69872e7 100644 --- a/ReactCommon/react/debug/CMakeLists.txt +++ b/ReactCommon/react/debug/CMakeLists.txt @@ -16,7 +16,7 @@ add_compile_options( -DLOG_TAG=\"Fabric\") -file(GLOB react_debug_SRC CONFIGURE_DEPENDS android/*.cpp) +file(GLOB react_debug_SRC CONFIGURE_DEPENDS *.cpp) add_library(react_debug SHARED ${react_debug_SRC}) target_include_directories(react_debug PUBLIC ${REACT_COMMON_DIR}) diff --git a/ReactCommon/react/debug/ios/react_native_assert.mm b/ReactCommon/react/debug/ios/react_native_assert.mm deleted file mode 100644 index ad9397e37e2..00000000000 --- a/ReactCommon/react/debug/ios/react_native_assert.mm +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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 -#import -#import - -#ifdef REACT_NATIVE_DEBUG - -extern "C" void react_native_assert_fail(const char *func, const char *file, int line, const char *expr) -{ - // flush logs because some might be lost on iOS if an assert is hit right after - // this. If you are trying to debug something actively and have added lots of - // LOG statements to track down an issue, there is race between flushing the - // final logs and stopping execution when the assert hits. Thus, if we know an - // assert will fail, we force flushing to happen right before the assert. - LOG(ERROR) << "react_native_assert failure: " << expr; - google::FlushLogFiles(google::GLOG_INFO /*min_severity*/); - - NSCAssert(false, @"%s:%d: function %s: assertion failed (%s)", file, line, func, expr); -} - -#endif diff --git a/ReactCommon/react/debug/android/react_native_assert.cpp b/ReactCommon/react/debug/react_native_assert.cpp similarity index 76% rename from ReactCommon/react/debug/android/react_native_assert.cpp rename to ReactCommon/react/debug/react_native_assert.cpp index 0c7c558ecc7..abcdc5e8fbc 100644 --- a/ReactCommon/react/debug/android/react_native_assert.cpp +++ b/ReactCommon/react/debug/react_native_assert.cpp @@ -5,10 +5,17 @@ * LICENSE file in the root directory of this source tree. */ -#include -#include +#ifdef __ANDROID__ -#ifdef REACT_NATIVE_DEBUG +#include + +// Provide a prototype to silence missing prototype warning in release +// mode. +extern "C" void react_native_assert_fail( + const char *func, + const char *file, + int line, + const char *expr); extern "C" void react_native_assert_fail( const char *func, @@ -35,4 +42,4 @@ extern "C" void react_native_assert_fail( expr); } -#endif +#endif // __ANDROID__ diff --git a/ReactCommon/react/debug/react_native_assert.h b/ReactCommon/react/debug/react_native_assert.h index 57eda382cb9..9ee5ce631c3 100644 --- a/ReactCommon/react/debug/react_native_assert.h +++ b/ReactCommon/react/debug/react_native_assert.h @@ -28,8 +28,9 @@ #else // REACT_NATIVE_DEBUG -#define react_native_assert(e) \ - ((e) ? (void)0 : react_native_assert_fail(__func__, __FILE__, __LINE__, #e)) +#ifdef __ANDROID__ + +#include #ifdef __cplusplus extern "C" { @@ -43,4 +44,27 @@ void react_native_assert_fail( } #endif // __cpusplus +#define react_native_assert(e) \ + ((e) ? (void)0 : react_native_assert_fail(__func__, __FILE__, __LINE__, #e)) + +#else // __ANDROID__ + +#include +#include + +// For all platforms, but iOS+Xcode especially: flush logs because some might be +// lost on iOS if an assert is hit right after this. If you are trying to debug +// something actively and have added lots of LOG statements to track down an +// issue, there is race between flushing the final logs and stopping execution +// when the assert hits. Thus, if we know an assert will fail, we force flushing +// to happen right before the assert. +#define react_native_assert(cond) \ + if (!(cond)) { \ + LOG(ERROR) << "react_native_assert failure: " << #cond; \ + google::FlushLogFiles(google::GLOG_INFO); \ + assert(cond); \ + } + +#endif // platforms besides __ANDROID__ + #endif // REACT_NATIVE_DEBUG