diff --git a/internal/platform/implementation/ios/Source/Platform/log_message.h b/internal/platform/implementation/ios/Source/Platform/log_message.h index 03e3dc1c..0c14c7d8 100644 --- a/internal/platform/implementation/ios/Source/Platform/log_message.h +++ b/internal/platform/implementation/ios/Source/Platform/log_message.h @@ -15,7 +15,11 @@ #ifndef PLATFORM_IMPL_IOS_LOG_MESSAGE_H_ #define PLATFORM_IMPL_IOS_LOG_MESSAGE_H_ +#ifdef NEARBY_SWIFTPM +#include +#else #include "glog/logging.h" +#endif #include "internal/platform/implementation/log_message.h" namespace location { @@ -36,7 +40,11 @@ class LogMessage : public api::LogMessage { std::ostream& Stream() override; private: +#ifdef NEARBY_SWIFTPM + std::stringstream log_streamer_; +#else google::LogMessage log_streamer_; +#endif api::LogMessage::Severity severity_; }; diff --git a/internal/platform/implementation/ios/Source/Platform/log_message.mm b/internal/platform/implementation/ios/Source/Platform/log_message.mm index c3772da2..20bf0062 100644 --- a/internal/platform/implementation/ios/Source/Platform/log_message.mm +++ b/internal/platform/implementation/ios/Source/Platform/log_message.mm @@ -14,7 +14,9 @@ #include "internal/platform/implementation/ios/Source/Platform/log_message.h" +#ifndef NEARBY_SWIFTPM #include "glog/logging.h" +#endif #include "internal/platform/implementation/log_message.h" #include "GoogleToolboxForMac/GTMLogger.h" @@ -40,7 +42,11 @@ GTMLoggerLevel ConvertSeverity(api::LogMessage::Severity severity) { } LogMessage::LogMessage(const char* file, int line, Severity severity) +#ifdef NEARBY_SWIFTPM + : log_streamer_() {} +#else : log_streamer_(ConvertSeverity(severity), file, line), severity_(severity) {} +#endif void LogMessage::Print(const char* format, ...) { va_list ap; @@ -66,7 +72,11 @@ void LogMessage::Print(const char* format, ...) { // TODO(b/169292092): GTMLogger doesn't support stream. Temporarily use absl LogStreamer to make // build pass. +#ifdef NEARBY_SWIFTPM +std::ostream& LogMessage::Stream() { return log_streamer_; } +#else std::ostream& LogMessage::Stream() { return log_streamer_.stream(); } +#endif } // namespace ios diff --git a/internal/platform/logging.h b/internal/platform/logging.h index 954352ab..46a3e26c 100644 --- a/internal/platform/logging.h +++ b/internal/platform/logging.h @@ -19,6 +19,14 @@ // In Chrome this is base/check.h. See crbug/1212611. #ifdef NEARBY_CHROMIUM #include "base/check.h" +// base/logging.h is available externally as "glog". However, this repo contains +// template files that can't be built by Swift Package Manager. To build with +// SPM we only need CHECK and DCHECK defined. +#elif defined(NEARBY_SWIFTPM) +#include +#define CHECK(condition) static_cast(0), condition ? (void) 0 : abort() +#define DCHECK(condition) static_cast(0), (void) 0 +#define CHECK_GT(a, b) static_cast(0), a > b ? (void) 0 : abort() #else #include "glog/logging.h" #endif