From e7f363e6010af2da97435d38ad33989f13ef996b Mon Sep 17 00:00:00 2001
From: Matt Jolly <kangie@gentoo.org>
Date: Thu, 6 Nov 2025 23:25:32 +1000
Subject: [PATCH] M143 revert libpng testiness

This patch reverts 4f7637304eca894adf2e70078a55654a88224a30
which breaks system-libpng usage by making libpng a testonly target.

Really we just want to unbundle libpng at that point, though soon it
will be replaced by something perhaps a little more oxidised.

Probably we should just drop system-png at this point, but let's get
a working build for now.

Signed-off-by: Matt Jolly <kangie@gentoo.org>
---
 chrome/test/BUILD.gn               |  6 ++---
 testing/libfuzzer/fuzzers/BUILD.gn |  2 +-
 third_party/libpng/BUILD.gn        |  8 -------
 third_party/libpng/visibility.gni  | 38 ++++++++++--------------------
 tools/imagediff/BUILD.gn           |  4 +---
 ui/gfx/BUILD.gn                    |  2 +-
 6 files changed, 18 insertions(+), 42 deletions(-)

diff --git a/chrome/test/BUILD.gn b/chrome/test/BUILD.gn
index 11b17980ae54d..8796d789f929a 100644
--- a/chrome/test/BUILD.gn
+++ b/chrome/test/BUILD.gn
@@ -11191,7 +11191,7 @@ if (!is_android) {
         "//testing/gtest",
         "//third_party/hunspell",
         "//third_party/icu",
-        "//third_party/libpng:libpng_for_testonly",
+        "//third_party/libpng",
         "//ui/base:test_support",
         "//ui/events:test_support",
         "//ui/ozone",
@@ -11561,7 +11561,7 @@ if (!is_android && !is_chromeos_device) {
       "//testing/gtest",
       "//third_party/hunspell",
       "//third_party/icu",
-      "//third_party/libpng:libpng_for_testonly",
+      "//third_party/libpng",
       "//ui/base:base_interactive_ui_tests",
       "//ui/base:ozone_buildflags",
       "//ui/base:test_support",
@@ -12522,7 +12522,7 @@ if (!is_android) {
       "//testing/gtest",
       "//third_party/hunspell",
       "//third_party/icu",
-      "//third_party/libpng:libpng_for_testonly",
+      "//third_party/libpng",
       "//ui/base:test_support",
       "//ui/resources:ui_test_pak",
       "//ui/views",
diff --git a/testing/libfuzzer/fuzzers/BUILD.gn b/testing/libfuzzer/fuzzers/BUILD.gn
index 82401e505324f..cde10308ebfea 100644
--- a/testing/libfuzzer/fuzzers/BUILD.gn
+++ b/testing/libfuzzer/fuzzers/BUILD.gn
@@ -103,7 +103,7 @@ fuzzer_test("libpng_progressive_read_fuzzer") {
   sources = [ "libpng_read_fuzzer.cc" ]
   deps = [
     "//base",
-    "//third_party/libpng:libpng_for_testonly",
+    "//third_party/libpng",
   ]
   dict = "dicts/png.dict"
   seed_corpuses = libpng_seed_corpuses
diff --git a/third_party/libpng/BUILD.gn b/third_party/libpng/BUILD.gn
index 3e31348b94f00..d4bdea1e33ce2 100644
--- a/third_party/libpng/BUILD.gn
+++ b/third_party/libpng/BUILD.gn
@@ -130,14 +130,6 @@ if (is_win) {
   }
 }
 
-group("libpng_for_testonly") {
-  testonly = true
-  public_deps = [ ":libpng" ]
-
-  visibility = []
-  visibility = libpng_testonly_visibility
-}
-
 if (build_with_chromium) {
   libpng_ossfuzz_seed_corpuses = [
     "//components/test/data/viz",
diff --git a/third_party/libpng/visibility.gni b/third_party/libpng/visibility.gni
index 9c58928b1eb79..e0c61f794d191 100644
--- a/third_party/libpng/visibility.gni
+++ b/third_party/libpng/visibility.gni
@@ -1,6 +1,8 @@
 # This list tracks all current users of libpng.
 #
 # libpng is actively being migrated, and calls to libpng should instead go
+ # This list tracks all current users of libpng.
+ # libpng is actively being migrated, and calls to libpng should instead go
 # through Skia's `SkPngRustDecoder`. No new entries should be added to this
 # list.
 
@@ -8,18 +10,18 @@
 #
 # TODO(https://crbug.com/443128323): Stop exposing `libpng` to Chrome
 # (i.e. we should work on removing all entries on the list below).
-visibility = [
+ visibility = [
   # Chrome => Skia => libpng dependency.
   #
   # TODO(https://crbug.com/381900683): Remove once Skia supports being
   # built without `libpng`.
-  "//skia/*",
+   "//skia/*",
 
   # Chrome => ... => freetype => libpng dependency.
   #
   # TODO(https://crbug.com/42271123): Remove this once `freetype` has been
   # replaced with Fontations in PDFium and in other Chrome dependencies.
-  "//third_party/freetype:*",
+   "//third_party/freetype:*",
 
   # Chrome => PDFium => libpng dependency.
   #
@@ -27,38 +29,22 @@ visibility = [
   # dependency has been made optional.
   "//third_party:png",  # In standalone PDFium
   "//third_party/pdfium/third_party:png",  # In Chromium
-]
-
-# Dependencies that do not really flow into Chrome binaries.
-visibility += [
-  # `build/config/android/*.gni` =>
-  #     => `libwebp:cwebp` (`executable`)
-  #     => `libwebp:imagedec`
-  #     => `libpng` dependency.
-  # The `cwebp` `executable` is used during build process, but depending on it
-  # does not result in linking the `libpng` library into Chrome binary.  See
-  # also `cwebp_exe_allowed_visibility` in
-  # `//third_party/libwebp/visibility.gni`.
-  "//third_party/libwebp:imagedec",
 
-  # `weston` => `libpng` is a test-only dependency as described in
-  # `//third_party/weston/README.chromium`.  The `weston` targets are not
-  # marked as `testonly` but their `visibility` is restricted and (in build
-  # configurations meant for testing) the only dependency of product code is
-  # the `data_deps` edge from `//ui/ozone/platform/wayland` to the
-  # `//third_party/weston` target (the latter one is an `executable`).
-  "//third_party/weston:cairo_shared",
-]
+  # Other dependency edges that seem like Chrome => ... => libpng dependencies
+  # but really aren't.  TODO: Clarify this comment in follow-up CLs.
+   "//third_party/libwebp:*",
+   "//third_party/weston/*",
+ ]
 
 # Test/tool-only dependencies under `//third_party/angle`
 # (migrating these to `libpng_testonly_visibility` would require editing
 # ANGLE's `BUILD.gn` files to depend on the `libpng_for_testonly` target).
-visibility += [
+ visibility += [
   "//third_party/angle/src/tests:angle_deqp_framework_qphelper",
   "//third_party/angle/third_party/glmark2:glmark2_common_gl",
   "//third_party/angle/third_party/glmark2:glmark2_common_gles",
   "//third_party/angle/util:angle_png_utils",
-]
+ ]
 
 # Test/tool-only dependencies.
 libpng_testonly_visibility = [
diff --git a/tools/imagediff/BUILD.gn b/tools/imagediff/BUILD.gn
index 2b5f3d384881a..d56651bedc751 100644
--- a/tools/imagediff/BUILD.gn
+++ b/tools/imagediff/BUILD.gn
@@ -34,7 +34,6 @@ if (target_os == "win" && host_os != "win") {
 # If the current toolchain is the test host toolchain, build the tool.
 if (current_toolchain == imagediff_toolchain) {
   executable("imagediff") {
-    testonly = true
     output_name = "image_diff"  # Different than dir name for historical
                                 # reasons.
     sources = [
@@ -48,7 +47,7 @@ if (current_toolchain == imagediff_toolchain) {
     deps = [
       "//base",
       "//build/win:default_exe_manifest",
-      "//third_party/libpng:libpng_for_testonly",
+      "//third_party/libpng",
       "//third_party/zlib",
     ]
   }
@@ -61,7 +60,6 @@ if (current_toolchain == imagediff_toolchain) {
 } else if (current_toolchain == default_toolchain &&
            default_toolchain != imagediff_toolchain) {
   binary_symlink("imagediff") {
-    testonly = true
     binary_label = ":$target_name($imagediff_toolchain)"
     binary_output_name = "image_diff"
 
diff --git a/ui/gfx/BUILD.gn b/ui/gfx/BUILD.gn
index f29089286f484..95318abf2eddb 100644
--- a/ui/gfx/BUILD.gn
+++ b/ui/gfx/BUILD.gn
@@ -902,7 +902,7 @@ test("gfx_unittests") {
     "//skia:skcms",
     "//testing/gtest",
     "//third_party/icu:icuuc",
-    "//third_party/libpng:libpng_for_testonly",
+    "//third_party/libpng",
     "//third_party/zlib",
     "//ui/base",
     "//ui/gfx/animation",
-- 
2.51.0
