diff --git a/React/React.xcodeproj/project.pbxproj b/React/React.xcodeproj/project.pbxproj index ec0a58585a..48033e7384 100644 --- a/React/React.xcodeproj/project.pbxproj +++ b/React/React.xcodeproj/project.pbxproj @@ -1077,6 +1077,12 @@ AC90463F21C91D02005B24B3 /* CompactValue.h in Headers */ = {isa = PBXBuildFile; fileRef = AC90463D21C91CC2005B24B3 /* CompactValue.h */; }; AC90464021C91D14005B24B3 /* CompactValue.h in Headers */ = {isa = PBXBuildFile; fileRef = AC90463D21C91CC2005B24B3 /* CompactValue.h */; }; AC90464121C91DB8005B24B3 /* YGConfig.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 5CE2080120772F7C009A43B3 /* YGConfig.h */; }; + ACC75C54221AA188002F24E8 /* log.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ACC75C53221AA188002F24E8 /* log.cpp */; }; + ACC75C56221AA194002F24E8 /* log.h in Headers */ = {isa = PBXBuildFile; fileRef = ACC75C55221AA194002F24E8 /* log.h */; }; + ACC75C57221AA1BD002F24E8 /* log.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ACC75C53221AA188002F24E8 /* log.cpp */; }; + ACC75C58221AA1CF002F24E8 /* log.h in Headers */ = {isa = PBXBuildFile; fileRef = ACC75C55221AA194002F24E8 /* log.h */; }; + ACC75C59221AA1E1002F24E8 /* log.h in Headers */ = {isa = PBXBuildFile; fileRef = ACC75C55221AA194002F24E8 /* log.h */; }; + ACC75C5A221AA1EA002F24E8 /* log.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ACC75C53221AA188002F24E8 /* log.cpp */; }; B233E6EA1D2D845D00BC68BA /* RCTI18nManager.m in Sources */ = {isa = PBXBuildFile; fileRef = B233E6E91D2D845D00BC68BA /* RCTI18nManager.m */; }; B95154321D1B34B200FE7B80 /* RCTActivityIndicatorView.m in Sources */ = {isa = PBXBuildFile; fileRef = B95154311D1B34B200FE7B80 /* RCTActivityIndicatorView.m */; }; BA0501AD2109DCF200A6BBC4 /* ReactMarker.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 13DA8A2F2097A90A00276ED4 /* ReactMarker.h */; }; @@ -2210,6 +2216,8 @@ AC70D2EB1DE48A22002E6351 /* JSBundleType.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSBundleType.cpp; sourceTree = ""; }; AC8360CC21B0256A00FC46B9 /* YGMarker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGMarker.h; sourceTree = ""; }; AC90463D21C91CC2005B24B3 /* CompactValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CompactValue.h; sourceTree = ""; }; + ACC75C53221AA188002F24E8 /* log.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = log.cpp; sourceTree = ""; }; + ACC75C55221AA194002F24E8 /* log.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = log.h; sourceTree = ""; }; ACDD3FDA1BC7430D00E7DE33 /* RCTBorderStyle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTBorderStyle.h; sourceTree = ""; }; B233E6E81D2D843200BC68BA /* RCTI18nManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = RCTI18nManager.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; B233E6E91D2D845D00BC68BA /* RCTI18nManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTI18nManager.m; sourceTree = ""; }; @@ -2332,6 +2340,8 @@ 130A77021DF767AF001F9587 /* yoga */ = { isa = PBXGroup; children = ( + ACC75C55221AA194002F24E8 /* log.h */, + ACC75C53221AA188002F24E8 /* log.cpp */, AC4A6AF821FB4EA900FBEC39 /* YGMarker.cpp */, AC52CEDD21FB3FF9003C6BEC /* instrumentation.h */, AC90463D21C91CC2005B24B3 /* CompactValue.h */, @@ -3255,6 +3265,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( + ACC75C58221AA1CF002F24E8 /* log.h in Headers */, AC52CEE021FB403B003C6BEC /* instrumentation.h in Headers */, AC90463F21C91D02005B24B3 /* CompactValue.h in Headers */, AC6B69E821B146C500B2B68A /* YGValue.h in Headers */, @@ -3321,6 +3332,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( + ACC75C59221AA1E1002F24E8 /* log.h in Headers */, AC52CEDF21FB401D003C6BEC /* instrumentation.h in Headers */, AC90464021C91D14005B24B3 /* CompactValue.h in Headers */, AC6B69E521B1469A00B2B68A /* YGValue.h in Headers */, @@ -3511,6 +3523,7 @@ 3D80DA7C1DF820620028D040 /* RCTRefreshControlManager.h in Headers */, 59D031ED1F8353D3008361F0 /* RCTSafeAreaShadowView.h in Headers */, 3D80DA7D1DF820620028D040 /* RCTRootShadowView.h in Headers */, + ACC75C56221AA194002F24E8 /* log.h in Headers */, 134D63C31F1FEC4B008872B5 /* RCTCxxBridgeDelegate.h in Headers */, 657734901EE8354A00A0E9EA /* RCTInspectorPackagerConnection.h in Headers */, 3D7BFD1D1EA8E351008DFB7A /* RCTPackagerConnection.h in Headers */, @@ -4349,6 +4362,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + ACC75C5A221AA1EA002F24E8 /* log.cpp in Sources */, AC4A6AFA21FB4EBF00FBEC39 /* YGMarker.cpp in Sources */, AC6B69E721B146B400B2B68A /* YGValue.cpp in Sources */, AC8360D121B025BC00FC46B9 /* YGConfig.cpp in Sources */, @@ -4366,6 +4380,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + ACC75C57221AA1BD002F24E8 /* log.cpp in Sources */, AC4A6AFB21FB4ECA00FBEC39 /* YGMarker.cpp in Sources */, AC6B69EA21B146E700B2B68A /* YGValue.cpp in Sources */, BA0501B02109DD1800A6BBC4 /* YGConfig.cpp in Sources */, @@ -4492,6 +4507,7 @@ 59EDBCBB1FDF4E0C003573DE /* RCTScrollViewManager.m in Sources */, 599FAA441FB274980058CCF6 /* RCTSurfaceRootView.mm in Sources */, C60669361F3CCF1B00E67165 /* RCTManagedPointer.mm in Sources */, + ACC75C54221AA188002F24E8 /* log.cpp in Sources */, 13B080261A694A8400A75B9A /* RCTWrapperViewController.m in Sources */, A2440AA31DF8D854006E7BFC /* RCTReloadCommand.m in Sources */, 6577348F1EE8354A00A0E9EA /* RCTInspector.mm in Sources */, diff --git a/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.cpp b/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.cpp index 915876b5ad..b08342c7c4 100644 --- a/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.cpp +++ b/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.cpp @@ -7,10 +7,12 @@ #include #include #include +#include #include using namespace facebook::jni; using namespace std; +using facebook::yoga::detail::Log; struct JYogaNode : public JavaClass { static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaNode;"; @@ -51,7 +53,7 @@ static void YGTransferLayoutOutputsRecursive(YGNodeRef root) { } auto obj = YGNodeJobject(root)->lockLocal(); if (!obj) { - YGLog( + Log::log( root, YGLogLevelError, "Java YGNode was GCed during layout calculation\n"); @@ -154,7 +156,7 @@ static void YGPrint(YGNodeRef node) { if (auto obj = YGNodeJobject(node)->lockLocal()) { cout << obj->toString() << endl; } else { - YGLog( + Log::log( node, YGLogLevelError, "Java YGNode was GCed during layout calculation\n"); @@ -240,7 +242,7 @@ static YGSize YGJNIMeasureFunc( return YGSize{*measuredWidth, *measuredHeight}; } else { - YGLog( + Log::log( node, YGLogLevelError, "Java YGNode was GCed during layout calculation\n"); diff --git a/ReactCommon/yoga/yoga/Yoga.cpp b/ReactCommon/yoga/yoga/Yoga.cpp index 3f65092b69..3b3208af01 100644 --- a/ReactCommon/yoga/yoga/Yoga.cpp +++ b/ReactCommon/yoga/yoga/Yoga.cpp @@ -5,6 +5,7 @@ * file in the root directory of this source tree. */ #include "Yoga.h" +#include "log.h" #include #include #include @@ -25,6 +26,7 @@ __forceinline const float fmaxf(const float a, const float b) { #endif using namespace facebook::yoga; +using detail::Log; #ifdef ANDROID static int YGAndroidLog( @@ -1028,7 +1030,7 @@ static void YGNodePrintInternal( const YGPrintOptions options) { std::string str; facebook::yoga::YGNodeToString(str, node, options, 0); - YGLog(node, YGLogLevelDebug, str.c_str()); + Log::log(node, YGLogLevelDebug, str.c_str()); } void YGNodePrint(const YGNodeRef node, const YGPrintOptions options) { @@ -3814,7 +3816,7 @@ bool YGLayoutNodeInternal( : layoutMarkerData.cachedMeasures) += 1; if (gPrintChanges && gPrintSkips) { - YGLog( + Log::log( node, YGLogLevelVerbose, "%s%d.{[skipped] ", @@ -3823,7 +3825,7 @@ bool YGLayoutNodeInternal( if (node->getPrintFunc() != nullptr) { node->getPrintFunc()(node); } - YGLog( + Log::log( node, YGLogLevelVerbose, "wm: %s, hm: %s, aw: %f ah: %f => d: (%f, %f) %s\n", @@ -3837,7 +3839,7 @@ bool YGLayoutNodeInternal( } } else { if (gPrintChanges) { - YGLog( + Log::log( node, YGLogLevelVerbose, "%s%d.{%s", @@ -3847,7 +3849,7 @@ bool YGLayoutNodeInternal( if (node->getPrintFunc() != nullptr) { node->getPrintFunc()(node); } - YGLog( + Log::log( node, YGLogLevelVerbose, "wm: %s, hm: %s, aw: %f ah: %f %s\n", @@ -3872,7 +3874,7 @@ bool YGLayoutNodeInternal( layoutMarkerData); if (gPrintChanges) { - YGLog( + Log::log( node, YGLogLevelVerbose, "%s%d.}%s", @@ -3882,7 +3884,7 @@ bool YGLayoutNodeInternal( if (node->getPrintFunc() != nullptr) { node->getPrintFunc()(node); } - YGLog( + Log::log( node, YGLogLevelVerbose, "wm: %s, hm: %s, d: (%f, %f) %s\n", @@ -3903,7 +3905,7 @@ bool YGLayoutNodeInternal( } if (layout->nextCachedMeasurementsIndex == YG_MAX_CACHED_RESULT_COUNT) { if (gPrintChanges) { - YGLog(node, YGLogLevelVerbose, "Out of cache entries!\n"); + Log::log(node, YGLogLevelVerbose, "Out of cache entries!\n"); } layout->nextCachedMeasurementsIndex = 0; } @@ -4196,43 +4198,9 @@ void YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour( config->shouldDiffLayoutWithoutLegacyStretchBehaviour = shouldDiffLayout; } -static void YGVLog( - const YGConfigRef config, - const YGNodeRef node, - YGLogLevel level, - const char* format, - va_list args) { - const YGConfigRef logConfig = - config != nullptr ? config : YGConfigGetDefault(); - logConfig->logger(logConfig, node, level, format, args); - - if (level == YGLogLevelFatal) { - abort(); - } -} - -void YGLogWithConfig( - const YGConfigRef config, - YGLogLevel level, - const char* format, - ...) { - va_list args; - va_start(args, format); - YGVLog(config, nullptr, level, format, args); - va_end(args); -} - -void YGLog(const YGNodeRef node, YGLogLevel level, const char* format, ...) { - va_list args; - va_start(args, format); - YGVLog( - node == nullptr ? nullptr : node->getConfig(), node, level, format, args); - va_end(args); -} - void YGAssert(const bool condition, const char* message) { if (!condition) { - YGLog(nullptr, YGLogLevelFatal, "%s\n", message); + Log::log(YGNodeRef{nullptr}, YGLogLevelFatal, "%s\n", message); } } @@ -4241,7 +4209,7 @@ void YGAssertWithNode( const bool condition, const char* message) { if (!condition) { - YGLog(node, YGLogLevelFatal, "%s\n", message); + Log::log(node, YGLogLevelFatal, "%s\n", message); } } @@ -4250,7 +4218,7 @@ void YGAssertWithConfig( const bool condition, const char* message) { if (!condition) { - YGLogWithConfig(config, YGLogLevelFatal, "%s\n", message); + Log::log(config, YGLogLevelFatal, "%s\n", message); } } diff --git a/ReactCommon/yoga/yoga/Yoga.h b/ReactCommon/yoga/yoga/Yoga.h index 214c5f6921..e3ca1fea6c 100644 --- a/ReactCommon/yoga/yoga/Yoga.h +++ b/ReactCommon/yoga/yoga/Yoga.h @@ -348,16 +348,6 @@ WIN_EXPORT float YGNodeLayoutGetPadding( const YGEdge edge); WIN_EXPORT void YGConfigSetLogger(const YGConfigRef config, YGLogger logger); -WIN_EXPORT void YGLog( - const YGNodeRef node, - YGLogLevel level, - const char* message, - ...); -WIN_EXPORT void YGLogWithConfig( - const YGConfigRef config, - YGLogLevel level, - const char* format, - ...); WIN_EXPORT void YGAssert(const bool condition, const char* message); WIN_EXPORT void YGAssertWithNode( const YGNodeRef node, diff --git a/ReactCommon/yoga/yoga/log.cpp b/ReactCommon/yoga/yoga/log.cpp new file mode 100644 index 0000000000..256bd81101 --- /dev/null +++ b/ReactCommon/yoga/yoga/log.cpp @@ -0,0 +1,60 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the LICENSE + * file in the root directory of this source tree. + */ + +#include "log.h" + +#include "Yoga.h" +#include "YGConfig.h" +#include "YGNode.h" + +namespace facebook { +namespace yoga { +namespace detail { + +namespace { + +void vlog( + YGConfig* config, + YGNode* node, + YGLogLevel level, + const char* format, + va_list args) { + YGConfig* logConfig = config != nullptr ? config : YGConfigGetDefault(); + logConfig->logger(logConfig, node, level, format, args); + + if (level == YGLogLevelFatal) { + abort(); + } +} +} // namespace + +void Log::log( + YGNode* node, + YGLogLevel level, + const char* format, + ...) noexcept { + va_list args; + va_start(args, format); + vlog( + node == nullptr ? nullptr : node->getConfig(), node, level, format, args); + va_end(args); +} + +void Log::log( + YGConfig* config, + YGLogLevel level, + const char* format, + ...) noexcept { + va_list args; + va_start(args, format); + vlog(config, nullptr, level, format, args); + va_end(args); +} + +} // namespace detail +} // namespace yoga +} // namespace facebook diff --git a/ReactCommon/yoga/yoga/log.h b/ReactCommon/yoga/yoga/log.h new file mode 100644 index 0000000000..b1fa9e2d12 --- /dev/null +++ b/ReactCommon/yoga/yoga/log.h @@ -0,0 +1,35 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the LICENSE + * file in the root directory of this source tree. + */ +#pragma once + +#include "YGEnums.h" + +struct YGNode; +struct YGConfig; + +namespace facebook { +namespace yoga { + +namespace detail { + +struct Log { + static void log( + YGNode* node, + YGLogLevel level, + const char* message, + ...) noexcept; + + static void log( + YGConfig* config, + YGLogLevel level, + const char* format, + ...) noexcept; +}; + +} // namespace detail +} // namespace yoga +} // namespace facebook