GN: Refactor base/BUILD.gn and fix dbus-glib error.

Refactor webrtc/base/BUILD.gn to not have any subtracted
source entries.

Also fix an error in webrtc/BUILD.gn that occurs when running
on Chormium trybots as a part of enabling WebRTC for GN in
https://codereview.chromium.org/321313006/
The error is that pkg-config for dbus-glib fails. Workaround
this by putting the pkg-config entry within the proper condition.

BUG=webrtc:3441
TEST=
Successful compilation of WebRTC as standalone:
gn gen out/Default --args="build_with_chromium=false" && ninja -C out/Default
gn gen out/Default --args="build_with_chromium=false is_clang=true clang_use_chrome_plugins=false" && ninja -C out/Default

I built successfully from a Chromium checkout (with
https://codereview.chromium.org/321313006/ applied) using:
gn gen out/Default && ninja -C out/Default webrtc

R=brettw@chromium.org, henrike@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/16759004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@6560 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/BUILD.gn b/webrtc/BUILD.gn
index 1e8c328..6f9f068 100644
--- a/webrtc/BUILD.gn
+++ b/webrtc/BUILD.gn
@@ -6,6 +6,8 @@
 # in the file PATENTS.  All contributing project authors may
 # be found in the AUTHORS file in the root of the source tree.
 
+# TODO(kjellander): Rebase this to webrtc/build/common.gypi changes after r6330.
+
 import("//build/config/arm.gni")
 import("//build/config/crypto.gni")
 import("//build/config/linux/pkg_config.gni")
@@ -61,8 +63,10 @@
   }
 }
 
-pkg_config("dbus-glib") {
-  packages = [ "dbus-glib-1" ]
+if (have_dbus_glib) {
+  pkg_config("dbus-glib") {
+    packages = [ "dbus-glib-1" ]
+  }
 }
 
 config("common_config") {
diff --git a/webrtc/base/BUILD.gn b/webrtc/base/BUILD.gn
index f8fb0bd..62566a2 100644
--- a/webrtc/base/BUILD.gn
+++ b/webrtc/base/BUILD.gn
@@ -6,6 +6,8 @@
 # in the file PATENTS.  All contributing project authors may
 # be found in the AUTHORS file in the root of the source tree.
 
+# TODO(kjellander): Rebase this to base.gyp changes after r6438.
+
 import("//build/config/crypto.gni")
 import("../build/webrtc.gni")
 
@@ -121,6 +123,7 @@
 static_library("webrtc_base") {
   cflags = []
   cflags_cc = []
+  deps= []
 
   configs += [
     "..:common_config",
@@ -142,62 +145,41 @@
     "asyncfile.h",
     "asynchttprequest.cc",
     "asynchttprequest.h",
-    "asyncinvoker.cc",
-    "asyncinvoker.h",
-    "asyncinvoker-inl.h",
     "asyncpacketsocket.h",
-    "asyncresolverinterface.h",
     "asyncsocket.cc",
     "asyncsocket.h",
     "asynctcpsocket.cc",
     "asynctcpsocket.h",
     "asyncudpsocket.cc",
     "asyncudpsocket.h",
-    "atomicops.h",
     "autodetectproxy.cc",
     "autodetectproxy.h",
-    "bandwidthsmoother.cc",
-    "bandwidthsmoother.h",
     "base64.cc",
     "base64.h",
     "basicdefs.h",
-    "basictypes.h",
-    "bind.h",
-    "bind.h.pump",
-    "buffer.h",
     "bytebuffer.cc",
     "bytebuffer.h",
     "byteorder.h",
-    "callback.h",
-    "callback.h.pump",
     "checks.cc",
     "checks.h",
     "common.cc",
     "common.h",
-    "constructormagic.h",
     "cpumonitor.cc",
     "cpumonitor.h",
     "crc32.cc",
     "crc32.h",
     "criticalsection.h",
     "cryptstring.h",
-    "dbus.cc",
-    "dbus.h",
     "diskcache.cc",
     "diskcache.h",
     "event.cc",
     "event.h",
-    "filelock.cc",
-    "filelock.h",
     "fileutils.cc",
     "fileutils.h",
-    "fileutils_mock.h",
     "firewallsocketserver.cc",
     "firewallsocketserver.h",
     "flags.cc",
     "flags.h",
-    "genericslot.h",
-    "genericslot.h.pump",
     "gunit_prod.h",
     "helpers.cc",
     "helpers.h",
@@ -210,44 +192,10 @@
     "httpcommon.h",
     "httprequest.cc",
     "httprequest.h",
-    "httpserver.cc",
-    "httpserver.h",
-    "ifaddrs-android.cc",
-    "ifaddrs-android.h",
     "iosfilesystem.mm",
     "ipaddress.cc",
     "ipaddress.h",
-    "json.cc",
-    "json.h",
-    "latebindingsymboltable.cc",
-    "latebindingsymboltable.cc.def",
-    "latebindingsymboltable.h",
-    "latebindingsymboltable.h.def",
-    "libdbusglibsymboltable.cc",
-    "libdbusglibsymboltable.h",
-    "linux.cc",
-    "linux.h",
-    "linuxfdwalk.c",
-    "linuxfdwalk.h",
-    "linuxwindowpicker.cc",
-    "linuxwindowpicker.h",
     "linked_ptr.h",
-    "logging.cc",
-    "logging.h",
-    "macasyncsocket.cc",
-    "macasyncsocket.h",
-    "maccocoasocketserver.h",
-    "maccocoasocketserver.mm",
-    "maccocoathreadhelper.h",
-    "maccocoathreadhelper.mm",
-    "macconversion.cc",
-    "macconversion.h",
-    "macsocketserver.cc",
-    "macsocketserver.h",
-    "macutils.cc",
-    "macutils.h",
-    "macwindowpicker.cc",
-    "macwindowpicker.h",
     "mathutils.h",
     "md5.cc",
     "md5.h",
@@ -258,14 +206,6 @@
     "messagehandler.h",
     "messagequeue.cc",
     "messagequeue.h",
-    "multipart.cc",
-    "multipart.h",
-    "natserver.cc",
-    "natserver.h",
-    "natsocketfactory.cc",
-    "natsocketfactory.h",
-    "nattypes.cc",
-    "nattypes.h",
     "nethelpers.cc",
     "nethelpers.h",
     "network.cc",
@@ -275,51 +215,26 @@
     "nssstreamadapter.cc",
     "nssstreamadapter.h",
     "nullsocketserver.h",
-    "openssl.h",
-    "openssladapter.cc",
-    "openssladapter.h",
-    "openssldigest.cc",
-    "openssldigest.h",
-    "opensslidentity.cc",
-    "opensslidentity.h",
-    "opensslstreamadapter.cc",
-    "opensslstreamadapter.h",
-    "optionsfile.cc",
-    "optionsfile.h",
     "pathutils.cc",
     "pathutils.h",
     "physicalsocketserver.cc",
     "physicalsocketserver.h",
-    "posix.cc",
-    "posix.h",
-    "profiler.cc",
-    "profiler.h",
     "proxydetect.cc",
     "proxydetect.h",
     "proxyinfo.cc",
     "proxyinfo.h",
-    "proxyserver.cc",
-    "proxyserver.h",
     "ratelimiter.cc",
     "ratelimiter.h",
     "ratetracker.cc",
     "ratetracker.h",
-    "refcount.h",
-    "referencecountedsingletonfactory.h",
-    "rollingaccumulator.h",
-    "schanneladapter.cc",
-    "schanneladapter.h",
+    "safe_conversions.h",
+    "safe_conversions_impl.h",
     "scoped_autorelease_pool.h",
     "scoped_autorelease_pool.mm",
     "scoped_ptr.h",
-    "scoped_ref_ptr.h",
-    "scopedptrcollection.h",
-    "sec_buffer.h",
     "sha1.cc",
     "sha1.h",
     "sha1digest.h",
-    "sharedexclusivelock.cc",
-    "sharedexclusivelock.h",
     "signalthread.cc",
     "signalthread.h",
     "sigslot.h",
@@ -339,12 +254,10 @@
     "socketstream.h",
     "ssladapter.cc",
     "ssladapter.h",
-    "sslconfig.h",
     "sslfingerprint.cc",
     "sslfingerprint.h",
     "sslidentity.cc",
     "sslidentity.h",
-    "sslroots.h",
     "sslsocketfactory.cc",
     "sslsocketfactory.h",
     "sslstreamadapter.cc",
@@ -353,7 +266,6 @@
     "sslstreamadapterhelper.h",
     "stream.cc",
     "stream.h",
-    "stringdigest.h",
     "stringencode.cc",
     "stringencode.h",
     "stringutils.cc",
@@ -366,50 +278,25 @@
     "taskparent.h",
     "taskrunner.cc",
     "taskrunner.h",
-    "testclient.cc",
-    "testclient.h",
     "thread.cc",
     "thread.h",
     "timeutils.cc",
     "timeutils.h",
     "timing.cc",
     "timing.h",
-    "transformadapter.cc",
-    "transformadapter.h",
-    "unixfilesystem.cc",
-    "unixfilesystem.h",
     "urlencode.cc",
     "urlencode.h",
-    "versionparsing.cc",
-    "versionparsing.h",
-    "virtualsocketserver.cc",
-    "virtualsocketserver.h",
-    "win32.cc",
-    "win32.h",
-    "win32filesystem.cc",
-    "win32filesystem.h",
-    "win32regkey.cc",
-    "win32regkey.h",
-    "win32securityerrors.cc",
-    "win32socketinit.cc",
-    "win32socketinit.h",
-    "win32socketserver.cc",
-    "win32socketserver.h",
-    "win32window.cc",
-    "win32window.h",
-    "win32windowpicker.cc",
-    "win32windowpicker.h",
-    "window.h",
-    "windowpicker.h",
-    "windowpickerfactory.h",
-    "winfirewall.cc",
-    "winfirewall.h",
-    "winping.cc",
-    "winping.h",
     "worker.cc",
     "worker.h",
   ]
 
+  if (is_posix) {
+    sources += [
+      "unixfilesystem.cc",
+      "unixfilesystem.h",
+    ]
+  }
+
   if (build_with_chromium) {
     sources += [
       "../overrides/webrtc/base/basictypes.h",
@@ -417,10 +304,19 @@
       "../overrides/webrtc/base/logging.cc",
       "../overrides/webrtc/base/logging.h",
     ]
+
     if (is_win) {
       sources += [ "../overrides/webrtc/base/win32socketinit.cc" ]
     }
-    sources -= [
+
+    include_dirs = [
+      "../overrides",
+      "../../openssl/openssl/include",
+    ]
+
+    direct_dependent_configs += [ ":webrtc_base_chromium_config" ]
+  } else {
+    sources += [
       "asyncinvoker.cc",
       "asyncinvoker.h",
       "asyncinvoker-inl.h",
@@ -435,8 +331,6 @@
       "callback.h",
       "callback.h.pump",
       "constructormagic.h",
-      "dbus.cc",
-      "dbus.h",
       "filelock.cc",
       "filelock.h",
       "fileutils_mock.h",
@@ -446,26 +340,8 @@
       "httpserver.h",
       "json.cc",
       "json.h",
-      "latebindingsymboltable.cc",
-      "latebindingsymboltable.cc.def",
-      "latebindingsymboltable.h",
-      "latebindingsymboltable.h.def",
-      "libdbusglibsymboltable.cc",
-      "libdbusglibsymboltable.h",
-      "linuxfdwalk.c",
-      "linuxfdwalk.h",
-      "linuxwindowpicker.cc",
-      "linuxwindowpicker.h",
       "logging.cc",
       "logging.h",
-      #"macasyncsocket.cc",
-      #"macasyncsocket.h",
-      #"maccocoasocketserver.h",
-      #"maccocoasocketserver.mm",
-      #"macsocketserver.cc",
-      #"macsocketserver.h",
-      #"macwindowpicker.cc",
-      #"macwindowpicker.h",
       "mathutils.h",
       "multipart.cc",
       "multipart.h",
@@ -478,8 +354,6 @@
       "openssl.h",
       "optionsfile.cc",
       "optionsfile.h",
-      "posix.cc",
-      "posix.h",
       "profiler.cc",
       "profiler.h",
       "proxyserver.cc",
@@ -487,8 +361,6 @@
       "refcount.h",
       "referencecountedsingletonfactory.h",
       "rollingaccumulator.h",
-      #"safe_conversions.h",
-      #"safe_conversions_impl.h",
       "scopedptrcollection.h",
       "scoped_ref_ptr.h",
       "sec_buffer.h",
@@ -497,44 +369,71 @@
       "sslconfig.h",
       "sslroots.h",
       "stringdigest.h",
-      #"testbase64.h",
       "testclient.cc",
       "testclient.h",
-      #"testutils.h",
       "transformadapter.cc",
       "transformadapter.h",
       "versionparsing.cc",
       "versionparsing.h",
       "virtualsocketserver.cc",
       "virtualsocketserver.h",
-      #"win32regkey.cc",
-      #"win32regkey.h",
-      #"win32socketinit.cc",
-      #"win32socketinit.h",
-      #"win32socketserver.cc",
-      #"win32socketserver.h",
-      #"win32toolhelp.h",
       "window.h",
       "windowpickerfactory.h",
       "windowpicker.h",
     ]
 
-    include_dirs = [
-      "../overrides",
-      "../../openssl/openssl/include",
-    ]
+    if (is_posix) {
+      sources += [
+        "latebindingsymboltable.cc",
+        "latebindingsymboltable.cc.def",
+        "latebindingsymboltable.h",
+        "latebindingsymboltable.h.def",
+        "posix.cc",
+        "posix.h",
+      ]
+    }
 
-    direct_dependent_configs += [ ":webrtc_base_chromium_config" ]
-  } else {
+    if (is_linux) {
+      sources += [
+        "dbus.cc",
+        "dbus.h",
+        "libdbusglibsymboltable.cc",
+        "libdbusglibsymboltable.h",
+        "linuxfdwalk.c",
+        "linuxfdwalk.h",
+        "linuxwindowpicker.cc",
+        "linuxwindowpicker.h",
+      ]
+    }
+
+    if (is_mac) {
+      sources += [
+        "macasyncsocket.cc",
+        "macasyncsocket.h",
+        "maccocoasocketserver.h",
+        "maccocoasocketserver.mm",
+        "macsocketserver.cc",
+        "macsocketserver.h",
+        "macwindowpicker.cc",
+        "macwindowpicker.h",
+      ]
+    }
+
     if (is_win) {
       sources += [
         "diskcache_win32.cc",
         "diskcache_win32.h",
+        "win32regkey.cc",
+        "win32regkey.h",
+        "win32socketinit.cc",
+        "win32socketinit.h",
+        "win32socketserver.cc",
+        "win32socketserver.h",
       ]
     }
 
-    deps = [ "//third_party/jsoncpp" ]
-  }
+    deps += [ "//third_party/jsoncpp" ]
+  }  # !build_with_chromium
 
   # TODO(henrike): issue 3307, make webrtc_base build without disabling
   # these flags.
@@ -547,12 +446,17 @@
   if (use_openssl) {
     direct_dependent_configs += [ ":openssl_config" ]
 
-    deps = [ "//third_party/openssl" ]
+    deps += [ "//third_party/openssl" ]
   } else {
     direct_dependent_configs += [ ":no_openssl_config" ]
   }
 
   if (is_android) {
+    sources += [
+      "ifaddrs-android.cc",
+      "ifaddrs-android.h",
+    ]
+
     direct_dependent_configs += [ ":android_config" ]
 
     libs = [
@@ -561,17 +465,12 @@
     ]
   } else {
     direct_dependent_configs += [ ":no_android_config" ]
-
-    sources -= [
-      "ifaddrs-android.cc",
-      "ifaddrs-android.h",
-    ]
   }
 
   if (is_ios) {
     all_dependent_configs += [ ":ios_config" ]
 
-    deps = [ "//net/third_party/nss/ssl:libssl" ]
+    deps += [ "//net/third_party/nss/ssl:libssl" ]
   }
 
   if (is_linux) {
@@ -585,20 +484,18 @@
       "Xrender",
     ]
     configs += [ "//third_party/nss:system_nss_no_ssl_config" ]
-  } else {
-    sources -= [
-      "dbus.cc",
-      "dbus.h",
-      "libdbusglibsymboltable.cc",
-      "libdbusglibsymboltable.h",
-      "linuxfdwalk.c",
-      "linuxfdwalk.h",
-      "linuxwindowpicker.cc",
-      "linuxwindowpicker.h",
-    ]
   }
 
   if (is_mac) {
+    sources += [
+      "maccocoathreadhelper.h",
+      "maccocoathreadhelper.mm",
+      "macconversion.cc",
+      "macconversion.h",
+      "macutils.cc",
+      "macutils.h",
+    ]
+
     all_dependent_configs = [ ":mac_config" ]
 
     libs = [
@@ -608,24 +505,27 @@
     if (cpu_arch == "x86") {
       all_dependent_configs += [ ":mac_x86_config" ]
     }
-  } else {
-    sources -= [
-      "macasyncsocket.cc",
-      "macasyncsocket.h",
-      "maccocoasocketserver.h",
-      #"maccocoasocketserver.mm",  # Seems to be excluded by default with GN.
-      "macconversion.cc",
-      "macconversion.h",
-      "macsocketserver.cc",
-      "macsocketserver.h",
-      "macutils.cc",
-      "macutils.h",
-      "macwindowpicker.cc",
-      "macwindowpicker.h",
-    ]
   }
 
   if (is_win) {
+    sources += [
+      "schanneladapter.cc",
+      "schanneladapter.h",
+      "win32.cc",
+      "win32.h",
+      "win32filesystem.cc",
+      "win32filesystem.h",
+      "win32securityerrors.cc",
+      "win32window.cc",
+      "win32window.h",
+      "win32windowpicker.cc",
+      "win32windowpicker.h",
+      "winfirewall.cc",
+      "winfirewall.h",
+      "winping.cc",
+      "winping.h",
+    ]
+
     libs = [
       "crypt32.lib",
       "iphlpapi.lib",
@@ -639,54 +539,21 @@
     ]
 
     defines += [ "_CRT_NONSTDC_NO_DEPRECATE" ]
-  } else {
-    sources -= [
-      "schanneladapter.cc",
-      "schanneladapter.h",
-      "winping.cc",
-      "winping.h",
-      "winfirewall.cc",
-      "winfirewall.h",
-      # The files below were covered by a regex exclude in GYP.
-      "win32.cc",
-      "win32.h",
-      "win32filesystem.cc",
-      "win32filesystem.h",
-      "win32regkey.cc",
-      "win32regkey.h",
-      "win32securityerrors.cc",
-      "win32socketinit.cc",
-      "win32socketinit.h",
-      "win32socketserver.cc",
-      "win32socketserver.h",
-      "win32window.cc",
-      "win32window.h",
-      "win32windowpicker.cc",
-      "win32windowpicker.h",
-    ]
   }
 
-  if (is_posix) {
-    if (is_debug) {
-      defines += [ "_DEBUG" ]
-    }
-  } else {
-    sources -= [
-      "latebindingsymboltable.cc",
-      "latebindingsymboltable.h",
-      "posix.cc",
-      "posix.h",
-      "unixfilesystem.cc",
-      "unixfilesystem.h",
-    ]
+  if (is_posix && is_debug) {
+    # Chromium's build/common.gypi defines this for all posix
+    # _except_ for ios & mac.  We want it there as well, e.g.
+    # because ASSERT and friends trigger off of it.
+    defines += [ "_DEBUG" ]
   }
 
   if (is_ios || (is_mac && cpu_arch != "x86")) {
     defines += [ "CARBON_DEPRECATED=YES" ]
   }
 
-  if (is_ios || !is_posix) {
-    sources -= [
+  if (!is_ios && is_posix) {
+    sources += [
       "openssl.h",
       "openssladapter.cc",
       "openssladapter.h",
@@ -699,8 +566,8 @@
     ]
   }
 
-  if (!is_linux && !is_android) {
-    sources -= [
+  if (is_linux || is_android) {
+    sources += [
       "linux.cc",
       "linux.h",
     ]