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}
diff --git a/BUILD.gn b/BUILD.gn
index c2b7ba4..b1301b0 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 f06597d..9e420ba 100644
--- a/webrtc/BUILD.gn
+++ b/webrtc/BUILD.gn
@@ -243,8 +243,12 @@
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 @@
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 @@
}
}
- 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 69fd7f4..3a33796 100644
--- a/webrtc/api/BUILD.gn
+++ b/webrtc/api/BUILD.gn
@@ -16,6 +16,12 @@
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 f3a46f6..aed1158 100644
--- a/webrtc/base/BUILD.gn
+++ b/webrtc/base/BUILD.gn
@@ -19,6 +19,17 @@
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 e812f9e..64ff05b 100644
--- a/webrtc/examples/BUILD.gn
+++ b/webrtc/examples/BUILD.gn
@@ -20,12 +20,22 @@
}
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 54daa20..a50d8e4 100644
--- a/webrtc/logging/BUILD.gn
+++ b/webrtc/logging/BUILD.gn
@@ -13,6 +13,15 @@
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 8f90a00..a7e388e 100644
--- a/webrtc/modules/BUILD.gn
+++ b/webrtc/modules/BUILD.gn
@@ -19,13 +19,17 @@
"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 @@
"../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 @@
"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 81e0792..bbf4668 100644
--- a/webrtc/modules/audio_coding/BUILD.gn
+++ b/webrtc/modules/audio_coding/BUILD.gn
@@ -913,6 +913,42 @@
}
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 @@
":isac_fix",
":neteq",
":neteq_unittest_tools",
- "../../common_audio/",
+ "../../common_audio",
"../../test:test_support_main",
"//testing/gtest",
]
@@ -1128,7 +1164,7 @@
":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 41aaab0..9b34d54 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 4090f6d..8aded10 100644
--- a/webrtc/modules/audio_processing/BUILD.gn
+++ b/webrtc/modules/audio_processing/BUILD.gn
@@ -315,6 +315,26 @@
}
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 a0c4ea7..03cbd6b 100644
--- a/webrtc/p2p/BUILD.gn
+++ b/webrtc/p2p/BUILD.gn
@@ -10,8 +10,13 @@
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 a1bfbda..0779291 100644
--- a/webrtc/sdk/BUILD.gn
+++ b/webrtc/sdk/BUILD.gn
@@ -15,6 +15,14 @@
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 b94a10f..4ae1b38 100644
--- a/webrtc/tools/BUILD.gn
+++ b/webrtc/tools/BUILD.gn
@@ -10,16 +10,32 @@
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 @@
}
deps = [
- "../modules/audio_device:audio_device",
+ "../modules/audio_device",
"../system_wrappers:system_wrappers_default",
"//build/win:default_exe_manifest",
]
@@ -163,8 +179,8 @@
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",
]