Skip to content

Commit 6e28e2d

Browse files
Jeffrey Beauchampfacebook-github-bot
authored andcommitted
Back out "Use NSCAssert() in react_native_assert instead of C assert()"
Summary: Original commit changeset: 43c4e4f1ae6b Original Phabricator Diff: D43275024 (c5bc3f1) D43587488 reverted D43275024 (c5bc3f1), but it was only committed to the fbobjc/releases/release-fbios-2023.03.01 branch (v404). We still aren't seeing successful fbios-pika-iphoneos-release builds for v405 (https://fburl.com/mobile/7zac3b5w). This is preventing QA and employee dogfooding of v405 (S325502). (Note: this ignores all push blocking failures!) Reviewed By: abashyam Differential Revision: D43609260 fbshipit-source-id: d411294ad8cdb22ff9e812bf0689d9b7bdff8d2e
1 parent e57b6d1 commit 6e28e2d

File tree

6 files changed

+42
-37
lines changed

6 files changed

+42
-37
lines changed

ReactCommon/React-Fabric.podspec

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,7 @@ Pod::Spec.new do |s|
235235
s.subspec "debug_core" do |ss|
236236
ss.dependency folly_dep_name, folly_version
237237
ss.compiler_flags = folly_compiler_flags
238-
ss.source_files = "react/debug/*.h",
239-
"react/debug/ios/**/*.{m,mm,cpp,h}"
238+
ss.source_files = "react/debug/**/*.{m,mm,cpp,h}"
240239
ss.exclude_files = "react/debug/tests"
241240
ss.header_dir = "react/debug"
242241
end

ReactCommon/react/debug/BUCK

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ APPLE_COMPILER_FLAGS = get_apple_compiler_flags()
1414

1515
rn_xplat_cxx_library(
1616
name = "debug",
17+
srcs = glob(
18+
["**/*.cpp"],
19+
exclude = glob(["tests/**/*.cpp"]),
20+
),
1721
headers = glob(
1822
["**/*.h"],
1923
exclude = glob(["tests/**/*.h"]),
@@ -36,10 +40,8 @@ rn_xplat_cxx_library(
3640
# for android react_native_assert
3741
"-llog",
3842
],
39-
fbandroid_srcs = glob(["android/**/*.cpp"]),
4043
fbobjc_compiler_flags = APPLE_COMPILER_FLAGS,
4144
fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(),
42-
fbobjc_srcs = glob(["ios/**/*.mm"]),
4345
force_static = True,
4446
labels = [
4547
"pfh:ReactNative_CommonInfrastructurePlaceholder",

ReactCommon/react/debug/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ add_compile_options(
1616
-DLOG_TAG=\"Fabric\")
1717

1818

19-
file(GLOB react_debug_SRC CONFIGURE_DEPENDS android/*.cpp)
19+
file(GLOB react_debug_SRC CONFIGURE_DEPENDS *.cpp)
2020
add_library(react_debug SHARED ${react_debug_SRC})
2121

2222
target_include_directories(react_debug PUBLIC ${REACT_COMMON_DIR})

ReactCommon/react/debug/ios/react_native_assert.mm

Lines changed: 0 additions & 27 deletions
This file was deleted.

ReactCommon/react/debug/android/react_native_assert.cpp renamed to ReactCommon/react/debug/react_native_assert.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
#ifdef __ANDROID__
9+
810
#include <android/log.h>
9-
#include <react/debug/react_native_assert.h>
1011

11-
#ifdef REACT_NATIVE_DEBUG
12+
// Provide a prototype to silence missing prototype warning in release
13+
// mode.
14+
extern "C" void react_native_assert_fail(
15+
const char *func,
16+
const char *file,
17+
int line,
18+
const char *expr);
1219

1320
extern "C" void react_native_assert_fail(
1421
const char *func,
@@ -35,4 +42,4 @@ extern "C" void react_native_assert_fail(
3542
expr);
3643
}
3744

38-
#endif
45+
#endif // __ANDROID__

ReactCommon/react/debug/react_native_assert.h

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828

2929
#else // REACT_NATIVE_DEBUG
3030

31-
#define react_native_assert(e) \
32-
((e) ? (void)0 : react_native_assert_fail(__func__, __FILE__, __LINE__, #e))
31+
#ifdef __ANDROID__
32+
33+
#include <android/log.h>
3334

3435
#ifdef __cplusplus
3536
extern "C" {
@@ -43,4 +44,27 @@ void react_native_assert_fail(
4344
}
4445
#endif // __cpusplus
4546

47+
#define react_native_assert(e) \
48+
((e) ? (void)0 : react_native_assert_fail(__func__, __FILE__, __LINE__, #e))
49+
50+
#else // __ANDROID__
51+
52+
#include <glog/logging.h>
53+
#include <cassert>
54+
55+
// For all platforms, but iOS+Xcode especially: flush logs because some might be
56+
// lost on iOS if an assert is hit right after this. If you are trying to debug
57+
// something actively and have added lots of LOG statements to track down an
58+
// issue, there is race between flushing the final logs and stopping execution
59+
// when the assert hits. Thus, if we know an assert will fail, we force flushing
60+
// to happen right before the assert.
61+
#define react_native_assert(cond) \
62+
if (!(cond)) { \
63+
LOG(ERROR) << "react_native_assert failure: " << #cond; \
64+
google::FlushLogFiles(google::GLOG_INFO); \
65+
assert(cond); \
66+
}
67+
68+
#endif // platforms besides __ANDROID__
69+
4670
#endif // REACT_NATIVE_DEBUG

0 commit comments

Comments
 (0)