Replaced preprocessor constant "NDEBUG" by the more standard "DEBUG" one and flipped behavior accordingly

This commit is contained in:
Pierre-Olivier Latour
2014-10-10 10:27:07 -07:00
parent 143e38c968
commit 420ddc3eac
7 changed files with 22 additions and 22 deletions

View File

@ -28,7 +28,6 @@ Pod::Spec.new do |s|
cs.ios.frameworks = 'MobileCoreServices', 'CFNetwork' cs.ios.frameworks = 'MobileCoreServices', 'CFNetwork'
cs.osx.library = 'z' cs.osx.library = 'z'
cs.osx.framework = 'SystemConfiguration' cs.osx.framework = 'SystemConfiguration'
cs.compiler_flags = '-DNDEBUG' # TODO: Only set this for Release configuration
end end
s.subspec 'WebDAV' do |cs| s.subspec 'WebDAV' do |cs|

View File

@ -512,6 +512,7 @@
buildSettings = { buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES; CLANG_ENABLE_OBJC_ARC = YES;
GCC_OPTIMIZATION_LEVEL = 0; GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = "DEBUG=1";
GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS = __GCDWEBSERVER_ENABLE_TESTING__; GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS = __GCDWEBSERVER_ENABLE_TESTING__;
HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/include/libxml2"; HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/include/libxml2";
ONLY_ACTIVE_ARCH = YES; ONLY_ACTIVE_ARCH = YES;
@ -539,7 +540,6 @@
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES; CLANG_ENABLE_OBJC_ARC = YES;
GCC_PREPROCESSOR_DEFINITIONS = NDEBUG;
GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS = __GCDWEBSERVER_ENABLE_TESTING__; GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS = __GCDWEBSERVER_ENABLE_TESTING__;
GCC_TREAT_WARNINGS_AS_ERRORS = YES; GCC_TREAT_WARNINGS_AS_ERRORS = YES;
HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/include/libxml2"; HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/include/libxml2";

View File

@ -33,8 +33,8 @@
/** /**
* Log levels used by GCDWebServer. * Log levels used by GCDWebServer.
* *
* @warning kGCDWebServerLogLevel_Debug is only available if "NDEBUG" is not * @warning kGCDWebServerLogLevel_Debug is only functional if the preprocessor
* defined when building. * constant "DEBUG" is is non-zero at build time.
*/ */
typedef NS_ENUM(int, GCDWebServerLogLevel) { typedef NS_ENUM(int, GCDWebServerLogLevel) {
kGCDWebServerLogLevel_Debug = 0, kGCDWebServerLogLevel_Debug = 0,
@ -489,8 +489,9 @@ extern NSString* const GCDWebServerAuthenticationMethod_DigestAccess;
/** /**
* Sets the current log level below which logged messages are discarded. * Sets the current log level below which logged messages are discarded.
* *
* The default level is either DEBUG or INFO if "NDEBUG" is defined at build-time. * The default level is INFO (or DEBUG if the preprocessor constant "DEBUG"
* It can also be set at runtime with the "logLevel" environment variable. * is non-zero at build time).
* It can also be set at run time with the "logLevel" environment variable.
*/ */
+ (void)setLogLevel:(GCDWebServerLogLevel)level; + (void)setLogLevel:(GCDWebServerLogLevel)level;

View File

@ -62,10 +62,10 @@ NSString* const GCDWebServerAuthenticationMethod_Basic = @"Basic";
NSString* const GCDWebServerAuthenticationMethod_DigestAccess = @"DigestAccess"; NSString* const GCDWebServerAuthenticationMethod_DigestAccess = @"DigestAccess";
#ifndef __GCDWEBSERVER_LOGGING_HEADER__ #ifndef __GCDWEBSERVER_LOGGING_HEADER__
#ifdef NDEBUG #if DEBUG
GCDWebServerLogLevel GCDLogLevel = kGCDWebServerLogLevel_Info;
#else
GCDWebServerLogLevel GCDLogLevel = kGCDWebServerLogLevel_Debug; GCDWebServerLogLevel GCDLogLevel = kGCDWebServerLogLevel_Debug;
#else
GCDWebServerLogLevel GCDLogLevel = kGCDWebServerLogLevel_Info;
#endif #endif
#endif #endif
@ -1138,7 +1138,7 @@ static void _LogResult(NSString* format, ...) {
_LogResult(@" Bodies not matching:\n Expected: %lu bytes\n Actual: %lu bytes", (unsigned long)expectedBody.length, (unsigned long)actualBody.length); _LogResult(@" Bodies not matching:\n Expected: %lu bytes\n Actual: %lu bytes", (unsigned long)expectedBody.length, (unsigned long)actualBody.length);
success = NO; success = NO;
#if !TARGET_OS_IPHONE #if !TARGET_OS_IPHONE
#ifndef NDEBUG #if DEBUG
if (GCDWebServerIsTextContentType([expectedHeaders objectForKey:@"Content-Type"])) { if (GCDWebServerIsTextContentType([expectedHeaders objectForKey:@"Content-Type"])) {
NSString* expectedPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[[[NSProcessInfo processInfo] globallyUniqueString] stringByAppendingPathExtension:@"txt"]]; NSString* expectedPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[[[NSProcessInfo processInfo] globallyUniqueString] stringByAppendingPathExtension:@"txt"]];
NSString* actualPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[[[NSProcessInfo processInfo] globallyUniqueString] stringByAppendingPathExtension:@"txt"]]; NSString* actualPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[[[NSProcessInfo processInfo] globallyUniqueString] stringByAppendingPathExtension:@"txt"]];

View File

@ -84,13 +84,7 @@ extern void GCDLogMessage(GCDWebServerLogLevel level, NSString* format, ...) NS_
#define LOG_ERROR(...) do { if (GCDLogLevel <= kGCDWebServerLogLevel_Error) GCDLogMessage(kGCDWebServerLogLevel_Error, __VA_ARGS__); } while (0) #define LOG_ERROR(...) do { if (GCDLogLevel <= kGCDWebServerLogLevel_Error) GCDLogMessage(kGCDWebServerLogLevel_Error, __VA_ARGS__); } while (0)
#define LOG_EXCEPTION(__EXCEPTION__) do { if (GCDLogLevel <= kGCDWebServerLogLevel_Exception) GCDLogMessage(kGCDWebServerLogLevel_Exception, @"%@", __EXCEPTION__); } while (0) #define LOG_EXCEPTION(__EXCEPTION__) do { if (GCDLogLevel <= kGCDWebServerLogLevel_Exception) GCDLogMessage(kGCDWebServerLogLevel_Exception, @"%@", __EXCEPTION__); } while (0)
#ifdef NDEBUG #if DEBUG
#define DCHECK(__CONDITION__)
#define DNOT_REACHED()
#define LOG_DEBUG(...)
#else
#define DCHECK(__CONDITION__) \ #define DCHECK(__CONDITION__) \
do { \ do { \
@ -101,6 +95,12 @@ extern void GCDLogMessage(GCDWebServerLogLevel level, NSString* format, ...) NS_
#define DNOT_REACHED() abort() #define DNOT_REACHED() abort()
#define LOG_DEBUG(...) do { if (GCDLogLevel <= kGCDWebServerLogLevel_Debug) GCDLogMessage(kGCDWebServerLogLevel_Debug, __VA_ARGS__); } while (0) #define LOG_DEBUG(...) do { if (GCDLogLevel <= kGCDWebServerLogLevel_Debug) GCDLogMessage(kGCDWebServerLogLevel_Debug, __VA_ARGS__); } while (0)
#else
#define DCHECK(__CONDITION__)
#define DNOT_REACHED()
#define LOG_DEBUG(...)
#endif #endif
#endif #endif

View File

@ -359,7 +359,7 @@ int main(int argc, const char* argv[]) {
if (webServer) { if (webServer) {
Delegate* delegate = [[Delegate alloc] init]; Delegate* delegate = [[Delegate alloc] init];
if (testDirectory) { if (testDirectory) {
#ifndef NDEBUG #if DEBUG
webServer.delegate = delegate; webServer.delegate = delegate;
#endif #endif
fprintf(stdout, "<RUNNING TESTS FROM \"%s\">\n\n", [testDirectory UTF8String]); fprintf(stdout, "<RUNNING TESTS FROM \"%s\">\n\n", [testDirectory UTF8String]);

View File

@ -303,20 +303,20 @@ HTTP connections are often initiated in batches (or bursts), for instance when l
Debug Builds & Custom Logging Debug Builds & Custom Logging
============================= =============================
When building GCDWebServer in "Debug" mode versus "Release" mode, GCDWebServer logs a lot more information and also performs a number of internal consistency checks. To disable this behavior, make sure to define the preprocessor constant ```NDEBUG``` when compiling GCDWebServer. In Xcode target settings, this can be done by adding ```NDEBUG``` to the build setting ```GCC_PREPROCESSOR_DEFINITIONS``` when building in Release configuration (this is done automatically for you if you use CocoaPods). When building GCDWebServer in "Debug" mode versus "Release" mode, GCDWebServer logs a lot more information and also performs a number of internal consistency checks. To enable this behavior, define the preprocessor constant ```DEBUG=1``` when compiling GCDWebServer. In Xcode target settings, this can be done by adding ```DEBUG=1``` to the build setting ```GCC_PREPROCESSOR_DEFINITIONS``` when building in Debug configuration.
It's also possible to replace the logging system used by GCDWebServer by a custom one. Simply define the preprocessor constant ```__GCDWEBSERVER_LOGGING_HEADER__``` to the name of a header file (e.g. "MyLogging.h") that defines these macros: It's also possible to replace the logging system used by GCDWebServer by a custom one. Simply define the preprocessor constant ```__GCDWEBSERVER_LOGGING_HEADER__``` to the name of a header file (e.g. "MyLogging.h") that defines these macros:
``` ```
#define LOG_DEBUG(...) // Should not do anything if NDEBUG is defined #define LOG_DEBUG(...) // Should not do anything unless the preprocessor constant DEBUG is non-zero
#define LOG_VERBOSE(...) #define LOG_VERBOSE(...)
#define LOG_INFO(...) #define LOG_INFO(...)
#define LOG_WARNING(...) #define LOG_WARNING(...)
#define LOG_ERROR(...) #define LOG_ERROR(...)
#define LOG_EXCEPTION(__EXCEPTION__) #define LOG_EXCEPTION(__EXCEPTION__)
#define DCHECK(__CONDITION__) // Should not do anything if NDEBUG is defined or abort if __CONDITION__ is false #define DCHECK(__CONDITION__) // Should not do anything unless the preprocessor constant DEBUG is non-zero
#define DNOT_REACHED() // Should not do anything if NDEBUG is defined #define DNOT_REACHED() // Should not do anything unless the preprocessor constant DEBUG is non-zero
``` ```
Advanced Example 1: Implementing HTTP Redirects Advanced Example 1: Implementing HTTP Redirects