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

Call assert in SingleInstanceChecker only in example apps #4316

Merged
merged 3 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions Common/cpp/Tools/SingleInstanceChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#include <iostream>
#include <string>

#ifdef ANDROID
#include <android/log.h>
#endif

namespace reanimated {

// This is a class that counts how many instances of a different class there
Expand All @@ -22,8 +26,16 @@ class SingleInstanceChecker {
private:
void assertWithMessage(bool condition, std::string message) {
if (!condition) {
std::cerr << message << std::endl;
assert(condition);
#ifdef ANDROID
__android_log_print(
ANDROID_LOG_WARN, "Reanimated", "%s", message.c_str());
#else
std::cerr << "[Reanimated] " << message << std::endl;
#endif

#ifdef IS_REANIMATED_EXAMPLE_APP
assert(false);
#endif
}
}

Expand Down
3 changes: 2 additions & 1 deletion RNReanimated.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ folly_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comm
folly_compiler_flags = folly_flags + ' ' + '-Wno-comma -Wno-shorten-64-to-32'
boost_compiler_flags = '-Wno-documentation'
fabric_flags = fabric_enabled ? '-DRCT_NEW_ARCH_ENABLED' : ''
example_flag = config[:is_reanimated_example_app] ? '-DIS_REANIMATED_EXAMPLE_APP' : ''
version_flag = '-DREANIMATED_VERSION=' + reanimated_package_json["version"]

Pod::Spec.new do |s|
Expand Down Expand Up @@ -48,7 +49,7 @@ Pod::Spec.new do |s|
s.compiler_flags = folly_compiler_flags + ' ' + boost_compiler_flags + ' -DHERMES_ENABLE_DEBUGGER'
s.xcconfig = {
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\" \"$(PODS_ROOT)/boost-for-react-native\" \"$(PODS_ROOT)/glog\" \"$(PODS_ROOT)/#{folly_prefix}Folly\" \"$(PODS_ROOT)/Headers/Public/React-hermes\" \"$(PODS_ROOT)/Headers/Public/hermes-engine\" \"$(PODS_ROOT)/#{config[:react_native_common_dir]}\"",
"OTHER_CFLAGS" => "$(inherited)" + " " + folly_flags + " " + fabric_flags + " " + version_flag
"OTHER_CFLAGS" => "$(inherited)" + " " + folly_flags + " " + fabric_flags + " " + example_flag + " " + version_flag
}

s.requires_arc = true
Expand Down
4 changes: 4 additions & 0 deletions android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ if(${IS_NEW_ARCHITECTURE_ENABLED})
string(APPEND CMAKE_CXX_FLAGS " -DRCT_NEW_ARCH_ENABLED")
endif()

if(${IS_REANIMATED_EXAMPLE_APP})
string(APPEND CMAKE_CXX_FLAGS " -DIS_REANIMATED_EXAMPLE_APP")
endif()

if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
string(APPEND CMAKE_CXX_FLAGS " -DDEBUG")
endif()
Expand Down
8 changes: 6 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,12 @@ def resolveClientSideBuild() {
return true
}

def isReanimatedExampleApp() {
return safeAppExtGet("isReanimatedExampleApp", false)
}

def isDeveloperMode() {
// developer mode, to run Example app
return safeAppExtGet("isReanimatedExampleApp", false) || System.getenv("REANIMATED_PACKAGE_BUILD") == "1"
return isReanimatedExampleApp() || System.getenv("REANIMATED_PACKAGE_BUILD") == "1"
}

def isNewArchitectureEnabled() {
Expand Down Expand Up @@ -454,6 +457,7 @@ android {
"-DJS_RUNTIME_DIR=${jsRuntimeDir}",
"-DCLIENT_SIDE_BUILD=${CLIENT_SIDE_BUILD}",
"-DIS_NEW_ARCHITECTURE_ENABLED=${isNewArchitectureEnabled()}",
"-DIS_REANIMATED_EXAMPLE_APP=${isReanimatedExampleApp()}",
"-DPLAYGROUND_APP_NAME=${getPlaygroundAppName()}",
"-DREANIMATED_PACKAGE_BUILD=${REANIMATED_PACKAGE_BUILD}",
"-DREANIMATED_VERSION=${REANIMATED_VERSION}"
Expand Down