Improved debug and fixed macros

This commit is contained in:
Nick Lockwood 2015-04-30 09:50:22 -07:00
parent d82aaa7fb3
commit eb0476074f
11 changed files with 74 additions and 74 deletions

View File

@ -632,6 +632,7 @@
buildSettings = { buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO; ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
GCC_PREPROCESSOR_DEFINITIONS = "$(inherited)";
HEADER_SEARCH_PATHS = ( HEADER_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Scheme <Scheme
LastUpgradeVersion = "0610" LastUpgradeVersion = "0630"
version = "1.3"> version = "1.3">
<BuildAction <BuildAction
parallelizeBuildables = "YES" parallelizeBuildables = "YES"

View File

@ -143,10 +143,7 @@
GCC_C_LANGUAGE_STANDARD = gnu99; GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO; GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0; GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = ( GCC_PREPROCESSOR_DEFINITIONS = "DEBUG=1";
"DEBUG=1",
"$(inherited)",
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO; GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
@ -182,6 +179,7 @@
ENABLE_NS_ASSERTIONS = NO; ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99; GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_PREPROCESSOR_DEFINITIONS = "";
GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNDECLARED_SELECTOR = YES;
@ -199,6 +197,7 @@
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
CLANG_STATIC_ANALYZER_MODE = deep; CLANG_STATIC_ANALYZER_MODE = deep;
GCC_PREPROCESSOR_DEFINITIONS = "$(inherited)";
HEADER_SEARCH_PATHS = ( HEADER_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,

View File

@ -10,7 +10,6 @@
#import "RCTTestRunner.h" #import "RCTTestRunner.h"
#import "FBSnapshotTestController.h" #import "FBSnapshotTestController.h"
#import "RCTDefines.h"
#import "RCTRedBox.h" #import "RCTRedBox.h"
#import "RCTRootView.h" #import "RCTRootView.h"
#import "RCTTestModule.h" #import "RCTTestModule.h"
@ -76,8 +75,6 @@
vc.view = [[UIView alloc] init]; vc.view = [[UIView alloc] init];
[vc.view addSubview:rootView]; // Add as subview so it doesn't get resized [vc.view addSubview:rootView]; // Add as subview so it doesn't get resized
#if RCT_DEBUG // Prevents build errors, as RCTRedBox is underfined if RCT_DEBUG=0
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS]; NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS];
NSString *error = [[RCTRedBox sharedInstance] currentErrorMessage]; NSString *error = [[RCTRedBox sharedInstance] currentErrorMessage];
while ([date timeIntervalSinceNow] > 0 && ![testModule isDone] && error == nil) { while ([date timeIntervalSinceNow] > 0 && ![testModule isDone] && error == nil) {
@ -98,13 +95,6 @@
} else { } else {
RCTAssert([testModule isDone], @"Test didn't finish within %d seconds", TIMEOUT_SECONDS); RCTAssert([testModule isDone], @"Test didn't finish within %d seconds", TIMEOUT_SECONDS);
} }
#else
expectErrorBlock(@"RCTRedBox unavailable. Set RCT_DEBUG=1 for testing.");
#endif
} }
@end @end

View File

@ -934,8 +934,6 @@ static id<RCTJavaScriptExecutor> _latestJSExecutor;
_loading = NO; _loading = NO;
if (error != nil) { if (error != nil) {
#if RCT_DEBUG // Red box is only available in debug mode
NSArray *stack = [[error userInfo] objectForKey:@"stack"]; NSArray *stack = [[error userInfo] objectForKey:@"stack"];
if (stack) { if (stack) {
[[RCTRedBox sharedInstance] showErrorMessage:[error localizedDescription] [[RCTRedBox sharedInstance] showErrorMessage:[error localizedDescription]
@ -945,8 +943,6 @@ static id<RCTJavaScriptExecutor> _latestJSExecutor;
withDetails:[error localizedFailureReason]]; withDetails:[error localizedFailureReason]];
} }
#endif
} else { } else {
[[NSNotificationCenter defaultCenter] postNotificationName:RCTJavaScriptDidLoadNotification [[NSNotificationCenter defaultCenter] postNotificationName:RCTJavaScriptDidLoadNotification
@ -980,33 +976,6 @@ static id<RCTJavaScriptExecutor> _latestJSExecutor;
action:^(UIKeyCommand *command) { action:^(UIKeyCommand *command) {
[weakSelf reload]; [weakSelf reload];
}]; }];
// reset to normal mode
[commands registerKeyCommandWithInput:@"n"
modifierFlags:UIKeyModifierCommand
action:^(UIKeyCommand *command) {
__strong RCTBridge *strongSelf = weakSelf;
strongSelf.executorClass = Nil;
[strongSelf reload];
}];
#if RCT_DEV // Debug executors are only available in dev mode
// reload in debug mode
[commands registerKeyCommandWithInput:@"d"
modifierFlags:UIKeyModifierCommand
action:^(UIKeyCommand *command) {
__strong RCTBridge *strongSelf = weakSelf;
strongSelf.executorClass = NSClassFromString(@"RCTWebSocketExecutor");
if (!strongSelf.executorClass) {
strongSelf.executorClass = NSClassFromString(@"RCTWebViewExecutor");
}
if (!strongSelf.executorClass) {
RCTLogError(@"WebSocket debugger is not available. "
"Did you forget to include RCTWebSocketExecutor?");
}
[strongSelf reload];
}];
#endif
#endif #endif
} }
@ -1091,7 +1060,7 @@ static id<RCTJavaScriptExecutor> _latestJSExecutor;
[self _invokeAndProcessModule:@"BatchedBridge" [self _invokeAndProcessModule:@"BatchedBridge"
method:@"callFunctionReturnFlushedQueue" method:@"callFunctionReturnFlushedQueue"
arguments:@[moduleID, methodID, args ?: @[]] arguments:@[moduleID ?: @0, methodID ?: @0, args ?: @[]]
context:RCTGetExecutorID(_javaScriptExecutor)]; context:RCTGetExecutorID(_javaScriptExecutor)];
} }

View File

@ -16,10 +16,10 @@
/** /**
* Developer menu, useful for exposing extra functionality when debugging. * Developer menu, useful for exposing extra functionality when debugging.
*/ */
@interface RCTDevMenu : NSObject <RCTBridgeModule, RCTInvalidating> @interface RCTDevMenu : NSObject
/** /**
* Is the menu enabled. The menu is enabled by default in debug mode, but * Is the menu enabled. The menu is enabled by default if RCT_DEV=1, but
* you may wish to disable it so that you can provide your own shake handler. * you may wish to disable it so that you can provide your own shake handler.
*/ */
@property (nonatomic, assign) BOOL shakeToShow; @property (nonatomic, assign) BOOL shakeToShow;
@ -41,7 +41,7 @@
@property (nonatomic, assign) NSTimeInterval liveReloadPeriod; @property (nonatomic, assign) NSTimeInterval liveReloadPeriod;
/** /**
* Manually show the menu. This will. * Manually show the dev menu.
*/ */
- (void)show; - (void)show;

View File

@ -10,12 +10,16 @@
#import "RCTDevMenu.h" #import "RCTDevMenu.h"
#import "RCTBridge.h" #import "RCTBridge.h"
#import "RCTDefines.h"
#import "RCTKeyCommands.h"
#import "RCTLog.h" #import "RCTLog.h"
#import "RCTProfile.h" #import "RCTProfile.h"
#import "RCTRootView.h" #import "RCTRootView.h"
#import "RCTSourceCode.h" #import "RCTSourceCode.h"
#import "RCTUtils.h" #import "RCTUtils.h"
#if RCT_DEV
@interface RCTBridge (Profiling) @interface RCTBridge (Profiling)
- (void)startProfiling; - (void)startProfiling;
@ -36,7 +40,7 @@ static NSString *const RCTShowDevMenuNotification = @"RCTShowDevMenuNotification
@end @end
@interface RCTDevMenu () <UIActionSheetDelegate> @interface RCTDevMenu () <RCTBridgeModule, RCTInvalidating, UIActionSheetDelegate>
@end @end
@ -68,6 +72,28 @@ RCT_EXPORT_MODULE()
selector:@selector(showOnShake) selector:@selector(showOnShake)
name:RCTShowDevMenuNotification name:RCTShowDevMenuNotification
object:nil]; object:nil];
#if TARGET_IPHONE_SIMULATOR
__weak RCTDevMenu *weakSelf = self;
RCTKeyCommands *commands = [RCTKeyCommands sharedInstance];
// Workaround around the first cmd+D not working: http://openradar.appspot.com/19613391
// You can register just the cmd key and do nothing. This will trigger the bug and cmd+R
// will work like a charm!
[commands registerKeyCommandWithInput:@""
modifierFlags:UIKeyModifierCommand
action:NULL];
// reload in debug mode
[commands registerKeyCommandWithInput:@"d"
modifierFlags:UIKeyModifierCommand
action:^(UIKeyCommand *command) {
__strong RCTDevMenu *strongSelf = weakSelf;
[strongSelf show];
}];
#endif
} }
return self; return self;
} }
@ -104,6 +130,7 @@ RCT_EXPORT_MODULE()
actionSheet.actionSheetStyle = UIBarStyleBlack; actionSheet.actionSheetStyle = UIBarStyleBlack;
[actionSheet showInView:[UIApplication sharedApplication].keyWindow.rootViewController.view]; [actionSheet showInView:[UIApplication sharedApplication].keyWindow.rootViewController.view];
_actionSheet = actionSheet;
} }
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
@ -218,6 +245,16 @@ RCT_EXPORT_MODULE()
@end @end
#else // Unvailable
@implementation RCTDevMenu
- (void)show {}
@end
#endif
@implementation RCTBridge (RCTDevMenu) @implementation RCTBridge (RCTDevMenu)
- (RCTDevMenu *)devMenu - (RCTDevMenu *)devMenu

View File

@ -7,10 +7,6 @@
* of patent rights can be found in the PATENTS file in the same directory. * of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import "RCTDefines.h"
#if RCT_DEBUG // Red box is only available in debug mode
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
@interface RCTRedBox : NSObject @interface RCTRedBox : NSObject
@ -27,5 +23,3 @@
- (void)dismiss; - (void)dismiss;
@end @end
#endif

View File

@ -7,15 +7,14 @@
* of patent rights can be found in the PATENTS file in the same directory. * of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import "RCTDefines.h"
#if RCT_DEBUG // Red box is only available in debug mode
#import "RCTRedBox.h" #import "RCTRedBox.h"
#import "RCTBridge.h" #import "RCTBridge.h"
#import "RCTDefines.h"
#import "RCTUtils.h" #import "RCTUtils.h"
#if RCT_DEBUG
@interface RCTRedBoxWindow : UIWindow <UITableViewDelegate, UITableViewDataSource> @interface RCTRedBoxWindow : UIWindow <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, copy) NSString *lastErrorMessage; @property (nonatomic, copy) NSString *lastErrorMessage;
@ -310,4 +309,19 @@
@end @end
#else // Disabled
@implementation RCTRedBox
+ (instancetype)sharedInstance { return nil; }
- (void)showErrorMessage:(NSString *)message {}
- (void)showErrorMessage:(NSString *)message withDetails:(NSString *)details {}
- (void)showErrorMessage:(NSString *)message withStack:(NSArray *)stack {}
- (void)updateErrorMessage:(NSString *)message withStack:(NSArray *)stack {}
- (void)showErrorMessage:(NSString *)message withStack:(NSArray *)stack showIfHidden:(BOOL)shouldShow {}
- (NSString *)currentErrorMessage { return nil; }
- (void)dismiss {}
@end
#endif #endif

View File

@ -61,12 +61,8 @@ RCT_EXPORT_METHOD(reportUnhandledException:(NSString *)message
} else { } else {
// Filter out numbers so the same base errors are mapped to the same categories independent of incorrect values. if (message.length > maxMessageLength) {
NSString *pattern = @"[+-]?\\d+[,.]?\\d*"; message = [[message substringToIndex:maxMessageLength] stringByAppendingString:@"..."];
NSString *sanitizedMessage = [message stringByReplacingOccurrencesOfString:pattern withString:@"<num>" options:NSRegularExpressionSearch range:(NSRange){0, message.length}];
if (sanitizedMessage.length > maxMessageLength) {
sanitizedMessage = [[sanitizedMessage substringToIndex:maxMessageLength] stringByAppendingString:@"..."];
} }
NSMutableString *prettyStack = [NSMutableString stringWithString:@"\n"]; NSMutableString *prettyStack = [NSMutableString stringWithString:@"\n"];
@ -74,7 +70,7 @@ RCT_EXPORT_METHOD(reportUnhandledException:(NSString *)message
[prettyStack appendFormat:@"%@@%@:%@\n", frame[@"methodName"], frame[@"lineNumber"], frame[@"column"]]; [prettyStack appendFormat:@"%@@%@:%@\n", frame[@"methodName"], frame[@"lineNumber"], frame[@"column"]];
} }
NSString *name = [@"Unhandled JS Exception: " stringByAppendingString:sanitizedMessage]; NSString *name = [@"Unhandled JS Exception: " stringByAppendingString:message];
[NSException raise:name format:@"Message: %@, stack: %@", message, prettyStack]; [NSException raise:name format:@"Message: %@, stack: %@", message, prettyStack];
} }

View File

@ -582,8 +582,9 @@
GCC_DYNAMIC_NO_PIC = NO; GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0; GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = ( GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1", "RCT_DEBUG=1",
"$(inherited)", "RCT_DEV=1",
"RCT_NSASSERT=1",
); );
GCC_SYMBOLS_PRIVATE_EXTERN = NO; GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
@ -621,6 +622,7 @@
ENABLE_NS_ASSERTIONS = NO; ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99; GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_PREPROCESSOR_DEFINITIONS = "";
GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNDECLARED_SELECTOR = YES;
@ -638,10 +640,7 @@
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
CLANG_STATIC_ANALYZER_MODE = deep; CLANG_STATIC_ANALYZER_MODE = deep;
GCC_PREPROCESSOR_DEFINITIONS = ( GCC_PREPROCESSOR_DEFINITIONS = "$(inherited)";
"DEBUG=1",
"$(inherited)",
);
GCC_WARN_ABOUT_MISSING_NEWLINE = YES; GCC_WARN_ABOUT_MISSING_NEWLINE = YES;
HEADER_SEARCH_PATHS = ( HEADER_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
@ -658,6 +657,7 @@
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
CLANG_STATIC_ANALYZER_MODE = deep; CLANG_STATIC_ANALYZER_MODE = deep;
GCC_PREPROCESSOR_DEFINITIONS = "$(inherited)";
GCC_WARN_ABOUT_MISSING_NEWLINE = YES; GCC_WARN_ABOUT_MISSING_NEWLINE = YES;
HEADER_SEARCH_PATHS = ( HEADER_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",