From: Michael Froman <mfroman@mozilla.com>
Date: Thu, 10 Oct 2024 13:42:00 +0000
Subject: Bug 1921707 - webrtc.gni - filter out '//third_party/abseil-cpp/'
 deps r=ng,webrtc-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D224079
Mercurial Revision: https://hg.mozilla.org/mozilla-central/rev/45b99d1ba95b46896506de1c7dd92f19e4dc9207
---
 webrtc.gni | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 71 insertions(+)

diff --git a/webrtc.gni b/webrtc.gni
index bb386f6e3f..df16269eb4 100644
--- a/webrtc.gni
+++ b/webrtc.gni
@@ -706,6 +706,36 @@ template("rtc_source_set") {
         deps += [ "//third_party/abseil-cpp:absl" ]
       }
     }
+
+    # Rather than widespread changes to most, if not all, BUILD.gn files
+    # we'll do some filtering on dependencies here.
+    if (build_with_mozilla && defined(deps)) {
+      # Now that abseil-cpp is moved to Mozilla's third_party directory
+      # we remove all the abseil-cpp dependency listings so moz.build
+      # generation succeed.
+      filtered_deps = []
+      foreach (dep, deps) {
+        newdep = string_replace(dep, "//third_party/abseil-cpp/", "")
+        if (newdep == dep) {
+          filtered_deps += [ dep ]
+        }
+      }
+      deps = []
+      deps = filtered_deps
+
+      # We don't build any of the test code, but many of the test
+      # targets list gtest/gmock as a dependency.  We can simply
+      # filter them out here.
+      filtered_deps = []
+      foreach (dep, deps) {
+        newdep = string_replace(dep, "//testing/g", "")
+        if (newdep == dep) {
+          filtered_deps += [ dep ]
+        }
+      }
+      deps = []
+      deps = filtered_deps
+    }
   }
 }
 
@@ -940,6 +970,47 @@ template("rtc_library") {
         deps += [ "//third_party/abseil-cpp:absl" ]
       }
     }
+
+    # Rather than widespread changes to most, if not all, BUILD.gn files
+    # we'll do some filtering on dependencies here.
+    if (build_with_mozilla && defined(deps)) {
+      # Now that abseil-cpp is moved to Mozilla's third_party directory
+      # we remove all the abseil-cpp dependency listings so moz.build
+      # generation succeed.
+      filtered_deps = []
+      foreach (dep, deps) {
+        newdep = string_replace(dep, "//third_party/abseil-cpp/", "")
+        if (newdep == dep) {
+          filtered_deps += [ dep ]
+        }
+      }
+      deps = []
+      deps = filtered_deps
+
+      # We don't build any of the test code, but many of the test
+      # targets list gtest/gmock as a dependency.  We can simply
+      # filter them out here.
+      filtered_deps = []
+      foreach (dep, deps) {
+        newdep = string_replace(dep, "//testing/g", "")
+        if (newdep == dep) {
+          filtered_deps += [ dep ]
+        }
+      }
+      deps = []
+      deps = filtered_deps
+
+      # Moving the google build directory requires looking for libwebrtc's
+      # third_party dependencies under libwebrtc/third_party instead of
+      # simply third_party.
+      modified_deps = []
+      foreach (dep, deps) {
+        newdep = string_replace(dep, "//third_party/", "//libwebrtc/third_party/")
+        modified_deps += [ newdep ]
+      }
+      deps = []
+      deps = modified_deps
+    }
   }
 }
 
