[go: nahoru, domu]

[Chromecast] Use source_set for shlibs on Android

We don't have vendor-supplied shlibs on Android. Building and linking
dummy shlibs wastes space with extra copies of //base and other code.

This change introduces a gn arg called "use_vendor_shlibs" which, when
false, makes "cast_shared_libraries" into "source_set"s, thus
statically-linking shlib implementations.

Bug: None
Test: build&run
Change-Id: I3f1124be285b48cd3314566ff9f220f121517108
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3765979
Reviewed-by: Simeon Anfinrud <sanfin@chromium.org>
Reviewed-by: Yuchen Liu <yucliu@chromium.org>
Commit-Queue: Thoren Paulson <thoren@google.com>
Cr-Commit-Position: refs/heads/main@{#1025882}
diff --git a/chromecast/android/BUILD.gn b/chromecast/android/BUILD.gn
index 24eb583..3f54dca5 100644
--- a/chromecast/android/BUILD.gn
+++ b/chromecast/android/BUILD.gn
@@ -47,12 +47,14 @@
   }
 }
 
-cast_shared_library("libcast_shell_android") {
+shared_library("libcast_shell_android") {
   # TODO: Remove the ldflags after migrating away from protobuf_lite to
   # protobuf_full.
   ldflags = [ "-Wl,-z,muldefs" ]
 
   sources = [ "//chromecast/app/android/cast_jni_loader.cc" ]
+  configs += [ "//chromecast:cast_config" ]
+  configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
 
   deps = [
     ":common_apk_deps",
@@ -60,12 +62,14 @@
   ]
 }
 
-cast_shared_library("libcast_browser_android") {
+shared_library("libcast_browser_android") {
   # TODO: Remove the ldflags after migrating away from protobuf_lite to
   # protobuf_full.
   ldflags = [ "-Wl,-z,muldefs" ]
 
   sources = [ "//chromecast/app/android/cast_jni_loader.cc" ]
+  configs += [ "//chromecast:cast_config" ]
+  configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
 
   deps = [
     ":common_apk_deps",
diff --git a/chromecast/chromecast.gni b/chromecast/chromecast.gni
index e5b5376..eeb2e3f 100644
--- a/chromecast/chromecast.gni
+++ b/chromecast/chromecast.gni
@@ -145,6 +145,11 @@
 
   # device specific string to append to User string.
   device_user_agent_suffix = ""
+
+  # link vendor-supplied functionality as shared libraries. When true,
+  # cast_shared_library targets are normal shared libraries. When false,
+  # they become source_sets.
+  use_vendor_shlibs = !is_android
 }
 
 declare_args() {
@@ -196,19 +201,33 @@
 foreach(target_type,
         [
           "executable",
-          "shared_library",
           "loadable_module",
           "source_set",
         ]) {
   template("cast_${target_type}") {
     target(target_type, target_name) {
-      forward_variables_from(invoker, "*")
+      forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
+      forward_variables_from(invoker, [ "testonly" ])
 
       configs += [ "//chromecast:cast_config" ]
     }
   }
 }
 
+template("cast_shared_library") {
+  if (use_vendor_shlibs) {
+    target_type = "shared_library"
+  } else {
+    target_type = "source_set"
+  }
+  target(target_type, target_name) {
+    forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
+    forward_variables_from(invoker, [ "testonly" ])
+
+    configs += [ "//chromecast:cast_config" ]
+  }
+}
+
 # Set the defaults for each target. The defaults for these target wrappers
 # should match their unwrapped counterparts in BUILDCONFIG.gn. The variables
 # referenced below are declared in BUILDCONFIG.gn.