OSDN Git Service

Trigger a compilation error when LOG_TAG is not provided
authorJakub Pawlowski <jpawlowski@google.com>
Mon, 11 Apr 2016 08:54:54 +0000 (01:54 -0700)
committerJakub Pawlowski <jpawlowski@google.com>
Tue, 12 Apr 2016 18:45:12 +0000 (18:45 +0000)
When compiling for OS_GENERIC, lack of LOG_TAG causes a compilation error.
Most developement happens on Android, which compiles this without an
error. This patch triggers a compilation failure on Android when LOG_TAG is not
provided.

Bug: 28118588
Change-Id: I316aa01952fb88d77bbabb197c77e4287a3fc39b

osi/include/log.h

index 738462e..ec5653a 100644 (file)
 
 #include <cutils/log.h>
 
+/**
+ * These log statements are effectively executing only ALOG(_________, tag, fmt, ## args ).
+ * fprintf is only to cause compilation error when LOG_TAG is not provided,
+ * which breaks build on Linux (for OS_GENERIC).
+ */
+
 #if LOG_NDEBUG
-#define LOG_VERBOSE(...) ((void)0)
+#define LOG_VERBOSE(tag, fmt, args...)                                \
+    do {                                                              \
+        (true) ? ((int)0) : fprintf(stderr, "%s" fmt , tag, ## args); \
+    } while (0)
 #else  // LOG_NDEBUG
-#define LOG_VERBOSE(tag, fmt, args...) ALOG(LOG_VERBOSE, tag, fmt, ## args)
+#define LOG_VERBOSE(tag, fmt, args...)                                                            \
+    do {                                                                                          \
+        (true) ? ALOG(LOG_VERBOSE, tag, fmt, ## args) : fprintf(stderr, "%s" fmt , tag, ## args); \
+    } while (0)
 #endif  // !LOG_NDEBUG
-#define LOG_DEBUG(tag, fmt, args...)   ALOG(LOG_DEBUG, tag, fmt, ## args )
-#define LOG_INFO(tag, fmt, args...)    ALOG(LOG_INFO, tag, fmt, ## args)
-#define LOG_WARN(tag, fmt, args...)    ALOG(LOG_WARN, tag, fmt, ## args)
-#define LOG_ERROR(tag, fmt, args...)   ALOG(LOG_ERROR, tag, fmt, ## args)
+
+#define LOG_DEBUG(tag, fmt, args...)                                                             \
+    do {                                                                                         \
+        (true) ? ALOG(LOG_DEBUG, tag, fmt, ## args ) : fprintf(stderr, "%s" fmt , tag, ## args); \
+    } while (0)
+#define LOG_INFO(tag, fmt, args...)                                                            \
+    do {                                                                                       \
+        (true) ? ALOG(LOG_INFO, tag, fmt, ## args) : fprintf(stderr, "%s" fmt , tag, ## args); \
+    } while (0)
+#define LOG_WARN(tag, fmt, args...)                                                            \
+    do {                                                                                       \
+        (true) ? ALOG(LOG_WARN, tag, fmt, ## args) : fprintf(stderr, "%s" fmt , tag, ## args); \
+    } while (0)
+#define LOG_ERROR(tag, fmt, args...)                                                            \
+    do {                                                                                        \
+        (true) ? ALOG(LOG_ERROR, tag, fmt, ## args) : fprintf(stderr, "%s" fmt , tag, ## args); \
+    } while (0)
 
 #endif  /* defined(OS_GENERIC) */