Refactor webrtc/{api,audio} and modules/audio_coding for GN check

This moves some GN check configurations out of .gn to individual targets.
The now checked targets are:
"//webrtc/api/*",
"//webrtc/audio/*",
"//webrtc/modules/audio_coding/*",

Many targets were fixed by adding dependencies, but the ones that
requires more refactorings are left with the check_includes attribute
set to false instead.

Make //webrtc/test:test_support a public dep of //webrtc/test:test_main
to avoid having to add that to all users of it.

BUG=webrtc:6828
NOTRY=True

Review-Url: https://codereview.webrtc.org/2556943003
Cr-Commit-Position: refs/heads/master@{#15461}
diff --git a/.gn b/.gn
index 7ed519f..c44ccc8 100644
--- a/.gn
+++ b/.gn
@@ -22,22 +22,9 @@
 # "gn check" or "gn gen --check".
 # TODO(kjellander): Keep adding paths to this list as work in webrtc:5589 is done.
 check_targets = [
-  "//webrtc/api:audio_mixer_api",
-  "//webrtc/api:transport_api",
-  "//webrtc/api:rtc_stats_api",
-  "//webrtc/audio/utility/*",
-  "//webrtc/modules/audio_coding:audio_decoder_factory_interface",
-  "//webrtc/modules/audio_coding:audio_format",
-  "//webrtc/modules/audio_coding:audio_format_conversion",
-  "//webrtc/modules/audio_coding:g711_test",
-  "//webrtc/modules/audio_coding:g722_test",
-  "//webrtc/modules/audio_coding:ilbc_test",
-  "//webrtc/modules/audio_coding:isac",
-  "//webrtc/modules/audio_coding:isac_api_test",
-  "//webrtc/modules/audio_coding:isac_fix_test",
-  "//webrtc/modules/audio_coding:isac_switch_samprate_test",
-  "//webrtc/modules/audio_coding:isac_test",
-  "//webrtc/modules/audio_coding:webrtc_opus_fec_test",
+  "//webrtc/api/*",
+  "//webrtc/audio/*",
+  "//webrtc/modules/audio_coding/*",
   "//webrtc/modules/audio_device/*",
   "//webrtc/modules/audio_mixer/*",
   "//webrtc/stats:rtc_stats",
diff --git a/webrtc/api/BUILD.gn b/webrtc/api/BUILD.gn
index e838e7e..3b93673 100644
--- a/webrtc/api/BUILD.gn
+++ b/webrtc/api/BUILD.gn
@@ -30,6 +30,7 @@
     ":transport_api",
     "..:webrtc_common",
     "../base:rtc_base_approved",
+    "../modules/audio_coding:audio_decoder_factory_interface",
     "../modules/audio_coding:audio_encoder_interface",
   ]
 }
@@ -44,6 +45,7 @@
 }
 
 rtc_static_library("libjingle_peerconnection") {
+  check_includes = false  # TODO(kjellander): Remove (bugs.webrtc.org/6828)
   cflags = []
   sources = [
     "audiotrack.cc",
@@ -218,6 +220,7 @@
   }
 
   rtc_test("peerconnection_unittests") {
+    check_includes = false  # TODO(kjellander): Remove (bugs.webrtc.org/6828)
     testonly = true
     sources = [
       "datachannel_unittest.cc",
@@ -331,6 +334,7 @@
 
     deps = [
       "//testing/gmock",
+      "//webrtc/test:test_support",
     ]
   }
 }
diff --git a/webrtc/audio/BUILD.gn b/webrtc/audio/BUILD.gn
index bfc2372..0669c60 100644
--- a/webrtc/audio/BUILD.gn
+++ b/webrtc/audio/BUILD.gn
@@ -30,11 +30,17 @@
   deps = [
     "..:webrtc_common",
     "../api:audio_mixer_api",
+    "../api:call_api",
     "../base:rtc_base_approved",
+    "../base:rtc_task_queue",
     "../call:call_interfaces",
     "../common_audio",
     "../modules/audio_device",
     "../modules/audio_processing",
+    "../modules/congestion_controller:congestion_controller",
+    "../modules/pacing:pacing",
+    "../modules/remote_bitrate_estimator:remote_bitrate_estimator",
+    "../modules/rtp_rtcp:rtp_rtcp",
     "../system_wrappers",
     "../voice_engine",
   ]
@@ -42,6 +48,11 @@
 if (rtc_include_tests) {
   rtc_source_set("audio_tests") {
     testonly = true
+
+    # TODO(kjellander): Remove (bugs.webrtc.org/6828)
+    # This needs remote_bitrate_estimator to be moved to webrtc/api first.
+    check_includes = false
+
     sources = [
       "audio_receive_stream_unittest.cc",
       "audio_send_stream_unittest.cc",
@@ -52,8 +63,11 @@
       ":audio",
       "../api:mock_audio_mixer",
       "../base:rtc_base_approved",
+      "../base:rtc_task_queue",
       "../modules/audio_device:mock_audio_device",
       "../modules/audio_mixer:audio_mixer_impl",
+      "../modules/congestion_controller:congestion_controller",
+      "../modules/pacing:pacing",
       "../test:test_common",
       "../test:test_support",
       "utility:audio_frame_operations",
diff --git a/webrtc/modules/BUILD.gn b/webrtc/modules/BUILD.gn
index bc2a0f0..46a2aa2 100644
--- a/webrtc/modules/BUILD.gn
+++ b/webrtc/modules/BUILD.gn
@@ -75,7 +75,6 @@
       "../modules/video_coding:video_codecs_test_framework",
       "../system_wrappers",
       "../test:test_main",
-      "../test:test_support",
       "//testing/gmock",
       "//testing/gtest",
     ]
@@ -650,7 +649,6 @@
       "../test:rtp_test_utils",
       "../test:test_common",
       "../test:test_main",
-      "../test:test_support",
       "../test:video_test_common",
       "audio_coding",
       "audio_coding:acm_receive_test",
diff --git a/webrtc/modules/audio_coding/BUILD.gn b/webrtc/modules/audio_coding/BUILD.gn
index efbf7e0..70ecc55 100644
--- a/webrtc/modules/audio_coding/BUILD.gn
+++ b/webrtc/modules/audio_coding/BUILD.gn
@@ -77,25 +77,38 @@
 }
 
 rtc_static_library("builtin_audio_decoder_factory") {
+  # TODO(kjellander): Remove (bugs.webrtc.org/6828)
+  # Errors on cyclic dependency with :isac_fix if enabled.
+  check_includes = false
+
   sources = [
     "codecs/builtin_audio_decoder_factory.cc",
     "codecs/builtin_audio_decoder_factory.h",
   ]
   deps = [
            "../..:webrtc_common",
+           "../../base:rtc_base_approved",
            ":audio_decoder_factory_interface",
          ] + audio_codec_deps
   defines = audio_codec_defines
 }
 
 rtc_static_library("rent_a_codec") {
+  # TODO(kjellander): Remove (bugs.webrtc.org/6828)
+  # Gives cyclic dependency with :neteq and :audio_coding if enabled.
+  check_includes = false
+
   sources = [
     "acm2/acm_codec_database.cc",
     "acm2/acm_codec_database.h",
     "acm2/rent_a_codec.cc",
     "acm2/rent_a_codec.h",
   ]
-  deps = [ "../..:webrtc_common" ] + audio_codec_deps
+  deps = [
+           ":audio_decoder_interface",
+           "../..:webrtc_common",
+           "../../base:rtc_base_approved",
+         ] + audio_codec_deps
   defines = audio_codec_defines
 }
 
@@ -140,8 +153,12 @@
   }
 
   deps = audio_coding_deps + [
+           ":audio_decoder_interface",
+           ":audio_decoder_factory_interface",
+           ":builtin_audio_decoder_factory",
            ":neteq",
            ":rent_a_codec",
+           "../../base:rtc_base_approved",
            "../../logging:rtc_event_log_api",
          ]
   defines = audio_coding_defines
@@ -190,6 +207,8 @@
 
   deps = [
     ":audio_encoder_interface",
+    "../..:webrtc_common",
+    "../../base:rtc_base_approved",
     "../../common_audio",
   ]
 }
@@ -208,6 +227,7 @@
 
   deps = [
     ":audio_encoder_interface",
+    "../../base:rtc_base_approved",
     "../../common_audio",
   ]
 }
@@ -232,6 +252,8 @@
   deps = [
     ":audio_decoder_interface",
     ":audio_encoder_interface",
+    "../..:webrtc_common",
+    "../../base:rtc_base_approved",
   ]
   public_deps = [
     ":g711_c",
@@ -246,6 +268,9 @@
     "codecs/g711/g711_interface.c",
     "codecs/g711/g711_interface.h",
   ]
+  deps = [
+    "../..:webrtc_common",
+  ]
 }
 
 config("g722_config") {
@@ -268,6 +293,8 @@
   deps = [
     ":audio_decoder_interface",
     ":audio_encoder_interface",
+    "../..:webrtc_common",
+    "../../base:rtc_base_approved",
   ]
   public_deps = [
     ":g722_c",
@@ -283,6 +310,9 @@
     "codecs/g722/g722_interface.c",
     "codecs/g722/g722_interface.h",
   ]
+  deps = [
+    "../..:webrtc_common",
+  ]
 }
 
 config("ilbc_config") {
@@ -305,6 +335,7 @@
   deps = [
     ":audio_decoder_interface",
     ":audio_encoder_interface",
+    "../..:webrtc_common",
     "../../base:rtc_base_approved",
     "../../common_audio",
   ]
@@ -460,17 +491,29 @@
   public_configs = [ ":ilbc_config" ]
 
   deps = [
+    ":audio_decoder_interface",
+    ":audio_encoder_interface",
+    "../..:webrtc_common",
+    "../../base:rtc_base_approved",
     "../../common_audio",
   ]
 }
 
 rtc_static_library("isac_common") {
+  # TODO(kjellander): Remove (bugs.webrtc.org/6828)
+  # Has a cyclic dependency with :isac if checks are enabled.
+  check_includes = false
+
   sources = [
     "codecs/isac/audio_encoder_isac_t.h",
     "codecs/isac/audio_encoder_isac_t_impl.h",
     "codecs/isac/locked_bandwidth_info.cc",
     "codecs/isac/locked_bandwidth_info.h",
   ]
+  deps = [
+    ":audio_encoder_interface",
+    "../../base:rtc_base_approved",
+  ]
 }
 
 config("isac_config") {
@@ -560,6 +603,7 @@
   public_configs = [ ":isac_config" ]
 
   deps = [
+    ":isac_common",
     "../..:webrtc_common",
     "../../base:rtc_base_approved",
     "../../common_audio",
@@ -598,6 +642,10 @@
 }
 
 rtc_source_set("isac_fix_c") {
+  # TODO(kjellander): Remove (bugs.webrtc.org/6828)
+  # Errors on cyclic dependency with :builtin_audio_decoder_factory if enabled.
+  check_includes = false
+
   visibility = [ ":*" ]  # Only targets in this file can depend on this.
   sources = [
     "codecs/isac/fix/include/audio_decoder_isacfix.h",
@@ -650,6 +698,16 @@
 
   public_configs = [ ":isac_fix_config" ]
 
+  deps = [
+    ":audio_decoder_interface",
+    ":audio_encoder_interface",
+    ":isac_common",
+    "../..:webrtc_common",
+    "../../base:rtc_base_approved",
+    "../../common_audio",
+    "../../system_wrappers",
+  ]
+
   if (current_cpu == "arm" && arm_version >= 7) {
     sources += [
       "codecs/isac/fix/source/lattice_armv7.S",
@@ -684,10 +742,6 @@
       sources -= [ "codecs/isac/fix/source/pitch_filter_c.c" ]
     }
   }
-
-  deps = [
-    "../../common_audio",
-  ]
 }
 
 if (rtc_build_with_neon) {
@@ -718,6 +772,8 @@
     }
 
     deps = [
+      ":isac_fix_c",
+      "../../base:rtc_base_approved",
       "../../common_audio",
     ]
   }
@@ -742,6 +798,8 @@
     ":audio_decoder_interface",
     ":audio_encoder_interface",
     ":g711",
+    "../..:webrtc_common",
+    "../../base:rtc_base_approved",
   ]
   public_deps = [
     ":pcm16b_c",
@@ -757,6 +815,9 @@
   ]
 
   public_configs = [ ":pcm16b_config" ]
+  deps = [
+    "../..:webrtc_common",
+  ]
 }
 
 config("opus_config") {
@@ -775,8 +836,10 @@
     ":audio_decoder_interface",
     ":audio_encoder_interface",
     ":audio_network_adaptor",
+    "../..:webrtc_common",
     "../../base:rtc_analytics",
     "../../base:rtc_base_approved",
+    "../../system_wrappers",
   ]
   public_deps = [
     ":webrtc_opus_c",
@@ -813,6 +876,7 @@
   }
 
   deps = [
+    "../..:webrtc_common",
     "../../base:rtc_base_approved",
   ]
 }
@@ -858,6 +922,8 @@
 
   deps = [
     "../..:webrtc_common",
+    "../../base:rtc_base_approved",
+    "../../common_audio",
     "../../system_wrappers",
   ]
 
@@ -879,6 +945,10 @@
 }
 
 rtc_static_library("neteq") {
+  # TODO(kjellander): Remove (bugs.webrtc.org/6828)
+  # Cyclic dependency with :audio_coding if enabled.
+  check_includes = false
+
   sources = [
     "neteq/accelerate.cc",
     "neteq/accelerate.h",
@@ -958,13 +1028,18 @@
   public_configs = [ ":neteq_config" ]
 
   deps = [
+    ":audio_decoder_factory_interface",
     ":audio_decoder_interface",
+    ":audio_format",
     ":builtin_audio_decoder_factory",
     ":cng",
     ":g711",
+    ":isac_fix",
     ":pcm16b",
     ":rent_a_codec",
     "../..:webrtc_common",
+    "../../base:gtest_prod",
+    "../../base:rtc_base_approved",
     "../../common_audio",
     "../../system_wrappers",
   ]
@@ -998,6 +1073,11 @@
 # does not set the rtc_include_tests flag.
 rtc_source_set("neteq_test_minimal") {
   testonly = true
+
+  # TODO(kjellander): Remove (bugs.webrtc.org/6828)
+  # Has cyclic dependency with :neteq_unittest_tools
+  check_includes = false
+
   sources = [
     "neteq/tools/encode_neteq_input.cc",
     "neteq/tools/encode_neteq_input.h",
@@ -1009,6 +1089,14 @@
     # Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
     suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
   }
+
+  deps = [
+    ":audio_encoder_interface",
+    ":builtin_audio_decoder_factory",
+    ":neteq",
+    "../..:webrtc_common",
+    "../../base:rtc_base_approved",
+  ]
 }
 
 if (rtc_include_tests) {
@@ -1059,7 +1147,12 @@
 
     deps = audio_coding_deps + [
              ":audio_coding",
+             ":audio_format_conversion",
+             ":audio_decoder_factory_interface",
+             ":builtin_audio_decoder_factory",
              ":neteq_unittest_tools",
+             "../../base:rtc_base_approved",
+             "../../test:test_support",
              "//testing/gtest",
            ]
   }
@@ -1075,7 +1168,11 @@
 
     deps = audio_coding_deps + [
              ":audio_coding",
+             ":audio_decoder_interface",
+             ":audio_encoder_interface",
              ":neteq_unittest_tools",
+             "../../base:rtc_base_approved",
+             "../../test:test_support",
              "//testing/gtest",
            ]
   }
@@ -1093,6 +1190,7 @@
       ":audio_coding",
       ":audio_format_conversion",
       "../../:webrtc_common",
+      "../../base:rtc_base_approved",
       "../../system_wrappers",
       "../../system_wrappers:system_wrappers_default",
       "../../test:test_support",
@@ -1119,6 +1217,7 @@
       ":audio_coding",
       ":audio_format_conversion",
       "../../:webrtc_common",
+      "../../base:rtc_base_approved",
       "../../system_wrappers",
       "../../system_wrappers:system_wrappers_default",
       "../../test:test_support",
@@ -1189,6 +1288,11 @@
 
     rtc_static_library("rtc_event_log_source") {
       testonly = true
+
+      # TODO(kjellander): Remove (bugs.webrtc.org/6828)
+      # Needs call.h to be moved to webrtc/api first.
+      check_includes = false
+
       sources = [
         "neteq/tools/rtc_event_log_source.cc",
         "neteq/tools/rtc_event_log_source.h",
@@ -1200,6 +1304,7 @@
       }
 
       deps = [
+        "../../base:rtc_base_approved",
         "../../logging:rtc_event_log_parser",
       ]
       public_deps = [
@@ -1230,6 +1335,8 @@
       deps += [
         ":neteq",
         ":neteq_unittest_tools",
+        "../..:webrtc_common",
+        "../../base:rtc_base_approved",
         "../../system_wrappers:system_wrappers_default",
         "../../test:test_support",
         "//third_party/gflags",
@@ -1261,6 +1368,8 @@
     deps += [
       ":isac_fix",
       ":webrtc_opus",
+      "../..:webrtc_common",
+      "../../base:rtc_base_approved",
       "../../system_wrappers:system_wrappers_default",
       "../../test:test_main",
       "../audio_processing",
@@ -1283,9 +1392,15 @@
     }
 
     deps = [
+      ":audio_decoder_interface",
+      ":builtin_audio_decoder_factory",
       ":neteq",
       ":neteq_unittest_tools",
       ":pcm16b",
+      "../..:webrtc_common",
+      "../../base:rtc_base_approved",
+      "../../system_wrappers",
+      "../../test:test_support",
       "//testing/gtest",
     ]
   }
@@ -1303,8 +1418,12 @@
     }
 
     deps = [
+      ":builtin_audio_decoder_factory",
       ":neteq",
       ":neteq_unittest_tools",
+      "../..:webrtc_common",
+      "../../base:rtc_base_approved",
+      "../../test:test_support",
       "//testing/gtest",
       "//third_party/gflags",
     ]
@@ -1355,12 +1474,20 @@
     }
 
     deps = [
-      ":neteq_test_minimal",
+      ":audio_decoder_interface",
+      ":audio_encoder_interface",
+      ":pcm16b",
+      "../..:webrtc_common",
+      "../../base:rtc_base_approved",
       "../../common_audio",
       "../../test:rtp_test_utils",
       "../rtp_rtcp",
     ]
 
+    public_deps = [
+      ":neteq_test_minimal",
+    ]
+
     if (rtc_enable_protobuf) {
       deps += [ ":rtc_event_log_source" ]
     }
@@ -1430,9 +1557,12 @@
       ":g722",
       ":ilbc",
       ":isac",
+      ":neteq",
       ":neteq_test_tools",
       ":pcm16b",
       ":webrtc_opus",
+      "../..:webrtc_common",
+      "../../base:rtc_base_approved",
       "../../common_audio",
     ]
 
@@ -1475,6 +1605,7 @@
     ]
 
     deps = [
+      "../../base:rtc_base_approved",
       "../../system_wrappers:system_wrappers_default",
       "../../test:rtp_test_utils",
       "//testing/gtest",
@@ -1490,6 +1621,7 @@
 
     deps = [
       ":neteq_test_tools",
+      "../../test:test_support",
       "//testing/gtest",
     ]
   }
@@ -1499,6 +1631,7 @@
     deps = [
       "../..:webrtc_common",
       "../../base:rtc_base_approved",
+      "../../test:test_support",
       "//testing/gtest",
     ]
     sources = [
@@ -1556,6 +1689,7 @@
     deps = [
       ":neteq",
       ":neteq_test_support",
+      "../..:webrtc_common",
       "../../system_wrappers:system_wrappers_default",
       "../../test:test_support",
       "//third_party/gflags",
@@ -1586,6 +1720,8 @@
       ":neteq",
       ":neteq_quality_test_support",
       ":neteq_unittest_tools",
+      "../..:webrtc_common",
+      "../../base:rtc_base_approved",
       "../../system_wrappers:system_wrappers_default",
       "../../test:test_main",
       "//testing/gtest",
@@ -1604,6 +1740,7 @@
       ":isac_fix",
       ":neteq",
       ":neteq_quality_test_support",
+      "../../base:rtc_base_approved",
       "../../test:test_main",
       "//testing/gtest",
       "//third_party/gflags",
@@ -1621,6 +1758,7 @@
       ":g711",
       ":neteq",
       ":neteq_quality_test_support",
+      "../../base:rtc_base_approved",
       "../../test:test_main",
       "//testing/gtest",
       "//third_party/gflags",
@@ -1775,7 +1913,6 @@
       "../../base:rtc_base_approved",
       "../../common_audio",
       "../../test:test_main",
-      "../../test:test_support",
       "//testing/gtest",
     ]
 
diff --git a/webrtc/test/BUILD.gn b/webrtc/test/BUILD.gn
index 22f890b..c476a12 100644
--- a/webrtc/test/BUILD.gn
+++ b/webrtc/test/BUILD.gn
@@ -94,9 +94,11 @@
     "test_main.cc",
   ]
 
+  public_deps = [
+    ":test_support",
+  ]
   deps = [
     ":field_trial",
-    ":test_support",
     "../system_wrappers:metrics_default",
     "//testing/gmock",
     "//testing/gtest",