From 6ceab083225dfa485bb48f9e43231c216acccbaf Mon Sep 17 00:00:00 2001 From: kjellander Date: Fri, 28 Oct 2016 05:44:03 -0700 Subject: [PATCH] GN: New conventions, default target and refactorings Introduce a convention on categorizing GN targets: 1. Production code 2. Tests 3. Examples 4. Tools The first two have targets spread out all over the tree, while the latter are isolated to examples/ and tools/ directories. Another new convention: Each directory's BUILD.gn file shall contain a target named similar to the directory name. This target shall contain the 'most common' production code, i.e. so that most consumers of the directory can depend on only the directory (which implicitly means that target in GN). //webrtc:webrtc_tests is changed to depend on all WebRTC tests. From now on, it's necessary to add new test targets to this dependency tree in order to get them compiled. Two new group targets are created: //webrtc/modules/audio_coding:audio_coding_tests //webrtc/modules/audio_processing:audio_processing_tests to reduce the long list of tests in //webrtc:webrtc_tests. Visibility on //webrtc:webrtc and //webrtc:webrtc_tests is restricted to the root target, to avoid circular dependencies due to the monolithic property of these targets (a problem we've had in the past). The 'root' target at the top level is renamed to 'default', which means GN will build this target instead of _all_ generated targets (see https://chromium.googlesource.com/chromium/src/+/master/tools/gn/docs/faq.md#Can-I-control-what-targets-are-built-by-default). This target now depends on everything we want to build, meaning all targets now explicitly needs to be wired up from the root target in order to get build. Having this, the number of compiled objects on Android is decreased from 8855 to 6276. It also gives us better control over our build. BUG=webrtc:6440 TESTED=git cl try --clobber NOTRY=True Review-Url: https://codereview.webrtc.org/2441383002 Cr-Commit-Position: refs/heads/master@{#14821} --- BUILD.gn | 6 +- webrtc/BUILD.gn | 92 +++++++++++++++++------- webrtc/api/BUILD.gn | 6 ++ webrtc/base/BUILD.gn | 11 +++ webrtc/examples/BUILD.gn | 12 +++- webrtc/logging/BUILD.gn | 9 +++ webrtc/modules/BUILD.gn | 11 +-- webrtc/modules/audio_coding/BUILD.gn | 40 ++++++++++- webrtc/modules/audio_mixer/BUILD.gn | 7 ++ webrtc/modules/audio_processing/BUILD.gn | 20 ++++++ webrtc/p2p/BUILD.gn | 5 ++ webrtc/sdk/BUILD.gn | 8 +++ webrtc/tools/BUILD.gn | 38 +++++++--- 13 files changed, 220 insertions(+), 45 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index c2b7ba4d19..b1301b0165 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -6,10 +6,12 @@ # in the file PATENTS. All contributing project authors may # be found in the AUTHORS file in the root of the source tree. -# This file is copied and modified from Chromium (src/BUILD.gn). -group("root") { +group("default") { + testonly = true deps = [ "//webrtc", + "//webrtc:webrtc_tests", "//webrtc/examples", + "//webrtc/tools", ] } diff --git a/webrtc/BUILD.gn b/webrtc/BUILD.gn index f06597dffa..9e420baa42 100644 --- a/webrtc/BUILD.gn +++ b/webrtc/BUILD.gn @@ -243,8 +243,12 @@ config("common_objc") { precompiled_source = "sdk/objc/WebRTC-Prefix.pch" } -if (!is_ios || !build_with_chromium) { +if (!build_with_chromium) { + # Target to build all the WebRTC production code. rtc_static_library("webrtc") { + # Only the root target should depend on this. + visibility = [ "//:default" ] + sources = [ # TODO(kjellander): Remove this whenever possible. GN's static_library # target type requires at least one object to avoid errors linking. @@ -258,37 +262,84 @@ if (!is_ios || !build_with_chromium) { deps = [ ":webrtc_common", + "api", "audio", - "base:rtc_base", + "base", "call", "common_audio", "common_video", + "libjingle/xmllite", + "libjingle/xmpp", + "logging", + "media", "modules", + "modules/video_capture:video_capture_internal_impl", + "p2p", + "pc", + "sdk", "stats", "system_wrappers", - "tools", "video", "voice_engine", ] - if (build_with_chromium) { - deps += [ "modules/video_capture" ] - } else { - # TODO(kjellander): Enable for Chromium as well when bugs.webrtc.org/4256 - # is fixed. Right now it's not possible due to circular dependencies. - deps += [ - "api", - "media", - "p2p", - "pc", - ] - } - if (rtc_enable_protobuf) { defines += [ "ENABLE_RTC_EVENT_LOG" ] deps += [ "logging:rtc_event_log_proto" ] } } + + if (rtc_include_tests) { + # Target to build all the WebRTC tests (but not examples or tools). + # Executable in order to get a target that links all WebRTC code. + rtc_executable("webrtc_tests") { + testonly = true + + # Only the root target should depend on this. + visibility = [ "//:default" ] + + deps = [ + ":rtc_unittests", + ":video_engine_tests", + ":webrtc_nonparallel_tests", + ":webrtc_perf_tests", + ":xmllite_xmpp_unittests", + "api:peerconnection_unittests", + "common_audio:common_audio_unittests", + "common_video:common_video_unittests", + "media:rtc_media_unittests", + "modules:modules_tests", + "modules:modules_unittests", + "modules/audio_coding:audio_coding_tests", + "modules/audio_processing:audio_processing_tests", + "modules/rtp_rtcp:test_packet_masks_metrics", + "modules/video_capture:video_capture_internal_impl", + "pc:rtc_pc_unittests", + "stats:rtc_stats_unittests", + "system_wrappers:system_wrappers_unittests", + "test", + "video:screenshare_loopback", + "video:video_loopback", + "video:video_tests", + "voice_engine:voe_cmd_test", + "voice_engine:voice_engine_unittests", + ] + if (is_android) { + deps += [ + ":android_junit_tests", + "api:libjingle_peerconnection_android_unittest", + ] + } else { + deps += [ "modules/video_capture:video_capture_tests" ] + } + if (!is_ios) { + deps += [ + "modules/audio_device:audio_device_tests", + "voice_engine:voe_auto_test", + ] + } + } + } } rtc_static_library("webrtc_common") { @@ -637,15 +688,6 @@ if (rtc_include_tests) { } } - rtc_executable("webrtc_tests") { - testonly = true - deps = [ - ":webrtc", - "modules/video_capture:video_capture_internal_impl", - "test", - ] - } - rtc_test("webrtc_perf_tests") { testonly = true configs += [ ":rtc_unittests_config" ] diff --git a/webrtc/api/BUILD.gn b/webrtc/api/BUILD.gn index 69fd7f44b2..3a33796123 100644 --- a/webrtc/api/BUILD.gn +++ b/webrtc/api/BUILD.gn @@ -16,6 +16,12 @@ group("api") { public_deps = [ ":libjingle_peerconnection", ] + if (is_android && !build_with_chromium) { + public_deps += [ + ":libjingle_peerconnection_java", + ":libjingle_peerconnection_so", + ] + } } rtc_source_set("call_api") { diff --git a/webrtc/base/BUILD.gn b/webrtc/base/BUILD.gn index f3a46f6e0e..aed11586b5 100644 --- a/webrtc/base/BUILD.gn +++ b/webrtc/base/BUILD.gn @@ -19,6 +19,17 @@ if (is_win) { import("//build/config/clang/clang.gni") } +group("base") { + public_deps = [ + ":rtc_base", + ":rtc_base_approved", + ":rtc_task_queue", + ] + if (is_android) { + public_deps += [ ":base_java" ] + } +} + config("rtc_base_approved_all_dependent_config") { if (is_mac && !build_with_chromium) { libs = [ "Foundation.framework" ] # needed for logging_mac.mm diff --git a/webrtc/examples/BUILD.gn b/webrtc/examples/BUILD.gn index e812f9ea9d..64ff05b430 100644 --- a/webrtc/examples/BUILD.gn +++ b/webrtc/examples/BUILD.gn @@ -20,12 +20,22 @@ if (is_linux) { } group("examples") { + # This target shall build all targets in examples. + testonly = true public_deps = [] if (is_android) { + public_deps += [ + ":AppRTCMobile", + ":AppRTCMobileTest", + ] + } + + if (is_ios || (is_mac && target_cpu != "x86")) { public_deps += [ ":AppRTCMobile" ] } - if (is_linux) { + + if (is_linux || is_win) { public_deps += [ ":peerconnection_client", ":peerconnection_server", diff --git a/webrtc/logging/BUILD.gn b/webrtc/logging/BUILD.gn index 54daa20929..a50d8e47dc 100644 --- a/webrtc/logging/BUILD.gn +++ b/webrtc/logging/BUILD.gn @@ -13,6 +13,15 @@ if (is_android) { import("//build/config/android/rules.gni") } +group("logging") { + public_deps = [ + ":rtc_event_log_impl", + ] + if (rtc_enable_protobuf) { + public_deps += [ ":rtc_event_log_parser" ] + } +} + rtc_source_set("rtc_event_log_api") { sources = [ "rtc_event_log/rtc_event_log.h", diff --git a/webrtc/modules/BUILD.gn b/webrtc/modules/BUILD.gn index 8f90a00f16..a7e388ea8f 100644 --- a/webrtc/modules/BUILD.gn +++ b/webrtc/modules/BUILD.gn @@ -19,13 +19,17 @@ group("modules") { "audio_coding", "audio_conference_mixer", "audio_device", - "audio_mixer:audio_mixer_impl", + "audio_mixer", "audio_processing", "bitrate_controller", + "congestion_controller", "desktop_capture", "media_file", + "pacing", + "remote_bitrate_estimator", "rtp_rtcp", "utility", + "video_capture", "video_coding", "video_processing", ] @@ -625,7 +629,7 @@ if (rtc_include_tests) { "../base:rtc_base", # TODO(kjellander): Cleanup in bugs.webrtc.org/3806. "../common_audio", "../common_video", - "../system_wrappers:system_wrappers", + "../system_wrappers", "../test:rtp_test_utils", "../test:test_common", "../test:test_support", @@ -645,8 +649,7 @@ if (rtc_include_tests) { "audio_coding:webrtc_opus", "audio_conference_mixer", "audio_device", - "audio_mixer:audio_frame_manipulator", - "audio_mixer:audio_mixer_impl", + "audio_mixer", "audio_processing", "audio_processing:audioproc_test_utils", "bitrate_controller", diff --git a/webrtc/modules/audio_coding/BUILD.gn b/webrtc/modules/audio_coding/BUILD.gn index 81e07920b2..bbf4668627 100644 --- a/webrtc/modules/audio_coding/BUILD.gn +++ b/webrtc/modules/audio_coding/BUILD.gn @@ -913,6 +913,42 @@ rtc_source_set("neteq_test_minimal") { } if (rtc_include_tests) { + group("audio_coding_tests") { + testonly = true + public_deps = [ + ":RTPchange", + ":RTPencode", + ":RTPjitter", + ":RTPtimeshift", + ":acm_receive_test", + ":acm_send_test", + ":audio_classifier_test", + ":audio_codec_speed_tests", + ":audio_decoder_unittests", + ":audio_decoder_unittests", + ":delay_test", + ":g711_test", + ":g722_test", + ":ilbc_test", + ":insert_packet_with_timing", + ":isac_api_test", + ":isac_fix_test", + ":isac_switch_samprate_test", + ":isac_test", + ":neteq_ilbc_quality_test", + ":neteq_isac_quality_test", + ":neteq_opus_quality_test", + ":neteq_pcmu_quality_test", + ":neteq_speed_test", + ":rtp_analyze", + ":rtpcat", + ":webrtc_opus_fec_test", + ] + if (rtc_enable_protobuf) { + public_deps += [ ":neteq_rtpplay" ] + } + } + rtc_source_set("acm_receive_test") { testonly = true sources = [ @@ -1028,7 +1064,7 @@ if (rtc_include_tests) { ":isac_fix", ":neteq", ":neteq_unittest_tools", - "../../common_audio/", + "../../common_audio", "../../test:test_support_main", "//testing/gtest", ] @@ -1128,7 +1164,7 @@ if (rtc_include_tests) { ":webrtc_opus", "../../system_wrappers:system_wrappers_default", "../../test:test_support_main", - "../audio_processing/", + "../audio_processing", "//testing/gtest", ] } diff --git a/webrtc/modules/audio_mixer/BUILD.gn b/webrtc/modules/audio_mixer/BUILD.gn index 41aaab0601..9b34d54300 100644 --- a/webrtc/modules/audio_mixer/BUILD.gn +++ b/webrtc/modules/audio_mixer/BUILD.gn @@ -8,6 +8,13 @@ import("../../build/webrtc.gni") +group("audio_mixer") { + public_deps = [ + ":audio_frame_manipulator", + ":audio_mixer_impl", + ] +} + rtc_static_library("audio_mixer_impl") { visibility = [ "../../audio:audio", diff --git a/webrtc/modules/audio_processing/BUILD.gn b/webrtc/modules/audio_processing/BUILD.gn index 4090f6d38b..8aded107be 100644 --- a/webrtc/modules/audio_processing/BUILD.gn +++ b/webrtc/modules/audio_processing/BUILD.gn @@ -315,6 +315,26 @@ if (rtc_build_with_neon) { } if (rtc_include_tests) { + group("audio_processing_tests") { + testonly = true + public_deps = [ + ":audioproc_f", + ":audioproc_test_utils", + ":click_annotate", + ":nonlinear_beamformer_test", + ":transient_suppression_test", + ":unpack_aecdump", + ] + + if (rtc_enable_intelligibility_enhancer) { + public_deps += [ ":intelligibility_proc" ] + } + + if (rtc_enable_protobuf) { + public_deps += [ ":audioproc_unittest_proto" ] + } + } + rtc_executable("unpack_aecdump") { testonly = true sources = [ diff --git a/webrtc/p2p/BUILD.gn b/webrtc/p2p/BUILD.gn index a0c4ea7697..03cbd6bca0 100644 --- a/webrtc/p2p/BUILD.gn +++ b/webrtc/p2p/BUILD.gn @@ -10,8 +10,13 @@ import("../build/webrtc.gni") group("p2p") { public_deps = [ + ":libstunprober", ":rtc_p2p", ] + if (!build_with_chromium) { + # TODO(kjellander): Move this to examples or tools. + public_deps += [ ":stun_prober" ] + } } config("rtc_p2p_inherited_config") { diff --git a/webrtc/sdk/BUILD.gn b/webrtc/sdk/BUILD.gn index a1bfbdaee3..0779291879 100644 --- a/webrtc/sdk/BUILD.gn +++ b/webrtc/sdk/BUILD.gn @@ -15,6 +15,14 @@ if (is_ios) { import("//build/config/ios/rules.gni") } +group("sdk") { + if (is_ios || (is_mac && mac_deployment_target == "10.7")) { + public_deps = [ + ":rtc_sdk_framework_objc", + ] + } +} + if (is_ios || (is_mac && mac_deployment_target == "10.7")) { config("rtc_sdk_common_objc_config") { include_dirs = [ diff --git a/webrtc/tools/BUILD.gn b/webrtc/tools/BUILD.gn index b94a10fab5..4ae1b38e16 100644 --- a/webrtc/tools/BUILD.gn +++ b/webrtc/tools/BUILD.gn @@ -10,16 +10,32 @@ import("//third_party/protobuf/proto_library.gni") import("../build/webrtc.gni") group("tools") { - deps = [ - ":command_line_parser", - ] + # This target shall build all targets in tools/. + testonly = true - if (!build_with_chromium) { - # TODO(kjellander): Enable these when webrtc:5970 is fixed. - deps += [ - ":frame_analyzer", - ":rgba_to_i420_converter", + public_deps = [ + ":command_line_parser", + ":frame_analyzer", + ":frame_editor", + ":psnr_ssim_analyzer", + ":rgba_to_i420_converter", + ] + if (rtc_include_internal_audio_device) { + public_deps += [ ":force_mic_volume_max" ] + } + if (rtc_enable_protobuf) { + public_deps += [ ":chart_proto" ] + } + + if (rtc_include_tests) { + public_deps += [ + ":activity_metric", + ":rtp_analyzer", + ":tools_unittests", ] + if (rtc_enable_protobuf) { + public_deps += [ ":event_log_visualizer" ] + } } } @@ -129,7 +145,7 @@ if (rtc_include_internal_audio_device) { } deps = [ - "../modules/audio_device:audio_device", + "../modules/audio_device", "../system_wrappers:system_wrappers_default", "//build/win:default_exe_manifest", ] @@ -163,8 +179,8 @@ if (rtc_enable_protobuf) { deps = [ "../logging:rtc_event_log_impl", "../logging:rtc_event_log_parser", - "../modules/congestion_controller:congestion_controller", - "../modules/rtp_rtcp:rtp_rtcp", + "../modules/congestion_controller", + "../modules/rtp_rtcp", "../system_wrappers:system_wrappers_default", "//build/config/sanitizers:deps", ]