Fix chromium compile erosion

This change makes a few more incremental changes to keep Chromium
compilation compatibility so we can try to land the compilation
upstream.

Bug: 951615
Change-Id: I69fc9f074268657c4fbef46c57775d9b985cc8e6
Reviewed-on: https://chromium-review.googlesource.com/c/openscreen/+/1580361
Reviewed-by: Ryan Keane <rwkeane@google.com>
Reviewed-by: mark a. foltz <mfoltz@chromium.org>
Commit-Queue: Brandon Tolsch <btolsch@chromium.org>
diff --git a/BUILD.gn b/BUILD.gn
index a7cea6f..547891f 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -49,7 +49,7 @@
     "sample:hello_unittests",
     "streaming/cast:cast_unittests",
     "third_party/abseil",
-    "//third_party/googletest:gtest_main",
+    "third_party/googletest:gtest_main",
   ]
 }
 
diff --git a/api/BUILD.gn b/api/BUILD.gn
index d9dbf0b..c44e8c4 100644
--- a/api/BUILD.gn
+++ b/api/BUILD.gn
@@ -45,12 +45,12 @@
   deps = [
     ":api",
     "../third_party/abseil",
+    "../third_party/googletest:gmock",
+    "../third_party/googletest:gtest",
     "impl/quic:test_support",
     "impl/testing",
     "impl/testing:fakes_unittests",
     "public:test_support",
-    "//third_party/googletest:gmock",
-    "//third_party/googletest:gtest",
   ]
   configs += [ "..:root_config_overrides" ]
 
diff --git a/api/impl/presentation/presentation_controller.cc b/api/impl/presentation/presentation_controller.cc
index 6f0673b..7409867 100644
--- a/api/impl/presentation/presentation_controller.cc
+++ b/api/impl/presentation/presentation_controller.cc
@@ -29,7 +29,7 @@
   static constexpr MessageDecodingFunction<ResponseMsgType> kDecoder = \
       &msgs::DecodePresentation##base_name##Response;                  \
   static constexpr msgs::Type kResponseType =                          \
-      msgs::Type::kPresentation##base_name##Response;
+      msgs::Type::kPresentation##base_name##Response
 
 struct StartRequest {
   DECLARE_MSG_REQUEST_RESPONSE(Start);
diff --git a/api/public/BUILD.gn b/api/public/BUILD.gn
index a6894a4..b74d8ad 100644
--- a/api/public/BUILD.gn
+++ b/api/public/BUILD.gn
@@ -2,6 +2,8 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
+import("//build_overrides/build.gni")
+
 source_set("api") {
   sources = [
     "client_config.cc",
@@ -42,6 +44,9 @@
     "../../base",
     "../../platform",
   ]
+  if (build_with_chromium) {
+    configs -= [ "//build/config/compiler:default_include_dirs" ]
+  }
   configs += [ "../..:root_config_overrides" ]
 }
 
diff --git a/base/BUILD.gn b/base/BUILD.gn
index daf00a4..f188ae9 100644
--- a/base/BUILD.gn
+++ b/base/BUILD.gn
@@ -2,6 +2,8 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
+import("//build_overrides/build.gni")
+
 source_set("base") {
   sources = [
     "big_endian.h",
@@ -40,8 +42,11 @@
   deps = [
     ":base",
     "../third_party/abseil",
-    "//third_party/googletest:gmock",
-    "//third_party/googletest:gtest",
+    "../third_party/googletest:gmock",
+    "../third_party/googletest:gtest",
   ]
+  if (build_with_chromium) {
+    configs -= [ "//build/config/compiler:default_include_dirs" ]
+  }
   configs += [ "..:root_config_overrides" ]
 }
diff --git a/discovery/mdns/BUILD.gn b/discovery/mdns/BUILD.gn
index 76590be..4046ac7 100644
--- a/discovery/mdns/BUILD.gn
+++ b/discovery/mdns/BUILD.gn
@@ -28,8 +28,8 @@
 
   deps = [
     ":mdns_interface",
-    "//third_party/googletest:gmock",
-    "//third_party/googletest:gtest",
+    "../../third_party/googletest:gmock",
+    "../../third_party/googletest:gtest",
   ]
   configs += [ "../..:root_config_overrides" ]
 
diff --git a/msgs/BUILD.gn b/msgs/BUILD.gn
index d744be2..99276de 100644
--- a/msgs/BUILD.gn
+++ b/msgs/BUILD.gn
@@ -64,7 +64,7 @@
 
   deps = [
     ":msgs",
-    "//third_party/googletest:gtest",
+    "../third_party/googletest:gtest",
   ]
   configs += [ "..:root_config_overrides" ]
 }
diff --git a/platform/BUILD.gn b/platform/BUILD.gn
index 6d28f75..2137718 100644
--- a/platform/BUILD.gn
+++ b/platform/BUILD.gn
@@ -18,8 +18,6 @@
     "api/task_runner.h",
     "api/task_runner_factory.h",
     "api/time.h",
-    "base/event_loop.cc",
-    "base/event_loop.h",
     "base/time.cc",
   ]
 
@@ -36,6 +34,8 @@
     public_deps += [ "//base" ]
   } else {  # !build_with_chromium
     sources += [
+      "base/event_loop.cc",
+      "base/event_loop.h",
       "base/logging.cc",
       "base/task_runner_factory.cc",
       "base/task_runner_impl.cc",
@@ -96,7 +96,7 @@
 
   deps = [
     ":platform",
-    "//third_party/googletest:gtest",
+    "../third_party/googletest:gtest",
   ]
 
   configs += [ "..:root_config_overrides" ]
diff --git a/streaming/cast/BUILD.gn b/streaming/cast/BUILD.gn
index 83f7d3c..b80fa22 100644
--- a/streaming/cast/BUILD.gn
+++ b/streaming/cast/BUILD.gn
@@ -24,14 +24,17 @@
     "ssrc.h",
   ]
 
+  # TODO(btolsch): Here and elsewhere, this begs the question of whether we
+  # should either change //base to //osp_base (like webrtc) or maybe introduce
+  # an osp_source_set template (also like webrtc).
+  if (build_with_chromium) {
+    configs -= [ "//build/config/compiler:default_include_dirs" ]
+  }
+  configs += [ "../..:root_config_overrides" ]
   public_deps = [
     "../../third_party/abseil",
+    "../../third_party/boringssl",
   ]
-  if (build_with_chromium) {
-    public_deps += [ "//third_party/boringssl" ]
-  } else {
-    public_deps += [ "../../third_party/boringssl" ]
-  }
 
   deps = [
     "../../platform",
@@ -49,6 +52,10 @@
     "ssrc_unittest.cc",
   ]
 
+  if (build_with_chromium) {
+    configs -= [ "//build/config/compiler:default_include_dirs" ]
+  }
+  configs += [ "../..:root_config_overrides" ]
   deps = [
     ":cast",
     "../../third_party/googletest:gtest",
diff --git a/third_party/boringssl/BUILD.gn b/third_party/boringssl/BUILD.gn
index b6935a9..5c2d5ae 100644
--- a/third_party/boringssl/BUILD.gn
+++ b/third_party/boringssl/BUILD.gn
@@ -6,70 +6,79 @@
 import("BUILD.generated.gni")
 import("BUILD.generated_tests.gni")
 
-# Config for us and everybody else depending on BoringSSL.
-config("external_config") {
-  include_dirs = [ "src/include" ]
-}
-
-# Config internal to this build file, shared by boringssl and boringssl_fuzzer.
-config("internal_config") {
-  visibility = [ ":*" ]  # Only targets in this file can depend on this.
-  defines = [
-    "BORINGSSL_ALLOW_CXX_RUNTIME",
-    "BORINGSSL_IMPLEMENTATION",
-    "BORINGSSL_NO_STATIC_INITIALIZER",
-    "OPENSSL_SMALL",
-  ]
-  cflags_c = [ "-std=c99" ]
-  defines += [ "_XOPEN_SOURCE=700" ]
-}
-
-config("no_asm_config") {
-  visibility = [ ":*" ]  # Only targets in this file can depend on this.
-  defines = [ "OPENSSL_NO_ASM" ]
-}
-
-all_sources = crypto_sources + ssl_sources
-all_headers = crypto_headers + ssl_headers
-
-# This has no sources on some platforms so must be a source_set.
-source_set("boringssl_asm") {
-  visibility = [ ":*" ]  # Only targets in this file can depend on this.
-
-  sources = []
-  asmflags = []
-
-  if (is_linux) {
-    if (current_cpu == "x64") {
-      sources += crypto_sources_linux_x86_64
-    } else if (current_cpu == "x86") {
-      sources += crypto_sources_linux_x86
-    } else {
-      public_configs = [ ":no_asm_config" ]
-    }
-  } else if (is_mac) {
-    if (current_cpu == "x64") {
-      sources += crypto_sources_mac_x86_64
-    } else if (current_cpu == "x86") {
-      sources += crypto_sources_mac_x86
-    } else {
-      public_configs = [ ":no_asm_config" ]
-    }
-  } else {
-    public_configs = [ ":no_asm_config" ]
+if (build_with_chromium) {
+  group("boringssl") {
+    public_configs = [ "//build/config/compiler:default_include_dirs" ]
+    public_deps = [
+      "//third_party/boringssl",
+    ]
   }
-}
+} else {
+  # Config for us and everybody else depending on BoringSSL.
+  config("external_config") {
+    include_dirs = [ "src/include" ]
+  }
 
-source_set("boringssl") {
-  sources = all_sources
-  public = all_headers
-  deps = [
-    ":boringssl_asm",
-    "src/third_party/fiat:fiat_license",
-  ]
+  # Config internal to this build file, shared by boringssl and boringssl_fuzzer.
+  config("internal_config") {
+    visibility = [ ":*" ]  # Only targets in this file can depend on this.
+    defines = [
+      "BORINGSSL_ALLOW_CXX_RUNTIME",
+      "BORINGSSL_IMPLEMENTATION",
+      "BORINGSSL_NO_STATIC_INITIALIZER",
+      "OPENSSL_SMALL",
+    ]
+    cflags_c = [ "-std=c99" ]
+    defines += [ "_XOPEN_SOURCE=700" ]
+  }
 
-  public_configs = [ ":external_config" ]
-  configs += [ ":internal_config" ]
+  config("no_asm_config") {
+    visibility = [ ":*" ]  # Only targets in this file can depend on this.
+    defines = [ "OPENSSL_NO_ASM" ]
+  }
 
-  configs -= [ "//build:default_include_dirs" ]
+  all_sources = crypto_sources + ssl_sources
+  all_headers = crypto_headers + ssl_headers
+
+  # This has no sources on some platforms so must be a source_set.
+  source_set("boringssl_asm") {
+    visibility = [ ":*" ]  # Only targets in this file can depend on this.
+
+    sources = []
+    asmflags = []
+
+    if (is_linux) {
+      if (current_cpu == "x64") {
+        sources += crypto_sources_linux_x86_64
+      } else if (current_cpu == "x86") {
+        sources += crypto_sources_linux_x86
+      } else {
+        public_configs = [ ":no_asm_config" ]
+      }
+    } else if (is_mac) {
+      if (current_cpu == "x64") {
+        sources += crypto_sources_mac_x86_64
+      } else if (current_cpu == "x86") {
+        sources += crypto_sources_mac_x86
+      } else {
+        public_configs = [ ":no_asm_config" ]
+      }
+    } else {
+      public_configs = [ ":no_asm_config" ]
+    }
+  }
+
+  source_set("boringssl") {
+    sources = all_sources
+    public = all_headers
+    deps = [
+      ":boringssl_asm",
+      "src/third_party/fiat:fiat_license",
+    ]
+
+    public_configs = [ ":external_config" ]
+    configs += [ ":internal_config" ]
+
+    configs -= [ "//build:default_include_dirs" ]
+  }
 }
diff --git a/third_party/googletest/BUILD.gn b/third_party/googletest/BUILD.gn
index b7a718e..079df85 100644
--- a/third_party/googletest/BUILD.gn
+++ b/third_party/googletest/BUILD.gn
@@ -4,7 +4,31 @@
 
 import("//build_overrides/build.gni")
 
-if (!build_with_chromium) {
+if (build_with_chromium) {
+  source_set("gmock") {
+    testonly = true
+    public_configs = [ "//build/config/compiler:default_include_dirs" ]
+    public_deps = [
+      "//third_party/googletest:gmock",
+    ]
+  }
+
+  source_set("gtest") {
+    testonly = true
+    public_configs = [ "//build/config/compiler:default_include_dirs" ]
+    public_deps = [
+      "//third_party/googletest:gtest",
+    ]
+  }
+
+  source_set("gtest_main") {
+    testonly = true
+    public_configs = [ "//build/config/compiler:default_include_dirs" ]
+    public_deps = [
+      "//third_party/googletest:gtest_main",
+    ]
+  }
+} else {
   config("gmock_config") {
     visibility = [ ":*" ]
 
diff --git a/tools/cddl/cddl.py b/tools/cddl/cddl.py
index a0290cd..b9be470 100644
--- a/tools/cddl/cddl.py
+++ b/tools/cddl/cddl.py
@@ -77,7 +77,7 @@
 def echoAndRunCommand(commandArray, allowFailure, logfile = None):
   print("\tExecuting Command: '%s'" % " ".join(commandArray))
   if logfile != None:
-    process = subprocess.Popen(commandArray, stdout=logfile)
+    process = subprocess.Popen(commandArray, stdout=logfile, stderr=logfile)
     process.wait()
     logfile.flush()
   else:
@@ -87,7 +87,6 @@
   if returncode != None and returncode != 0:
     if not allowFailure:
       sys.exit("\t\tERROR: Command failed with error code: '%i'!" % returncode)
-      
     else:
       print("\t\tWARNING: Command failed with error code: '%i'!" % returncode)
 
diff --git a/tools/cddl/logging.h b/tools/cddl/logging.h
index 16133a9..a4fce44 100644
--- a/tools/cddl/logging.h
+++ b/tools/cddl/logging.h
@@ -81,14 +81,15 @@
 #elif defined(__GNUC__)
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wformat-security"
-#endif
-    asprintf(&str_buffer, message.c_str(),
-             this->MakePrintable(std::forward<Args>(args))...);
+#endif  // defined(__clang__)
+    int byte_count = asprintf(&str_buffer, message.c_str(),
+                              this->MakePrintable(std::forward<Args>(args))...);
 #if defined(__clang__)
 #pragma clang diagnostic pop
 #elif defined(__GNUC__)
 #pragma GCC diagnostic pop
-#endif
+#endif  // defined(__clang__)
+    OSP_CHECK_GE(byte_count, 0);
     stream << str_buffer;
     free(str_buffer);
   }