chromium/third_party/androidx/customizations.gni

# Copyright 2023 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/android/rules.gni")

template("_androidx_prebuilt") {
  target(invoker.target_type, target_name) {
    forward_variables_from(invoker, "*", [ "target_type" ])

    if (target_name == "androidx_annotation_annotation_java") {
      # Ensure this dep is the suggested one when targets are missing it.
      preferred_dep = true
    } else if (target_name == "androidx_annotation_annotation_jvm_java") {
      # https://crbug.com/989505
      jar_excluded_patterns = [ "META-INF/proguard/*" ]
      proguard_configs = [ "androidx_annotations.flags" ]
    } else if (target_name == "androidx_benchmark_benchmark_common_java") {
      ignore_native_libraries = true
    } else if (target_name == "androidx_benchmark_benchmark_macro_java") {
      # Manually add dep onto DISALLOWED_DEP androidx.profileinstaller.
      deps += [ ":androidx_profileinstaller_profileinstaller_java" ]
    } else if (target_name ==
               "androidx_coordinatorlayout_coordinatorlayout_java") {
      # Reduce binary size. https:crbug.com/954584
      ignore_proguard_configs = true
    } else if (target_name == "androidx_core_core_java") {
      # Target has AIDL, but we do not support it yet: http://crbug.com/644439
      ignore_aidl = true

      # Manifest and proguard config have just one entry: Adding (and -keep'ing
      # android:appComponentFactory="androidx.core.app.CoreComponentFactory"
      # Chrome does not use this feature and it causes a scary stack trace to be
      # shown when incremental_install=true.
      ignore_manifest = true
      ignore_proguard_configs = true

      # https://crbug.com/1414452
      jar_excluded_patterns = [ "androidx/core/os/BuildCompat*" ]
      public_deps = [ "//third_party/androidx/local_modifications/buildcompat:buildcompat_java" ]

      if (!enable_java_asserts) {
        # Omit the file since we use our own copy.
        jar_excluded_patterns += [ "androidx/core/util/Preconditions.class" ]
        deps += [ "//third_party/android_deps/local_modifications/preconditions:androidx_stub_preconditions_java" ]
      }
    } else if (target_name == "androidx_fragment_fragment_java") {
      deps += [ "//third_party/android_deps/utils:java" ]

      proguard_configs = [ "androidx_fragment.flags" ]
    } else if (target_name == "androidx_lifecycle_lifecycle_process_java") {
      # Only useful for very old SDKs.
      ignore_proguard_configs = true
    } else if (target_name == "androidx_graphics_graphics_path_java") {
      ignore_native_libraries = true
    } else if (target_name == "androidx_media_media_java") {
      # Target has AIDL, but we do not support it yet: http://crbug.com/644439
      ignore_aidl = true
    } else if (target_name == "androidx_mediarouter_mediarouter_java") {
      # https://crbug.com/1000382
      proguard_configs = [ "androidx_mediarouter.flags" ]
    } else if (target_name == "androidx_preference_preference_java") {
      proguard_configs = [ "androidx_preferences.flags" ]

      # Replace broad library -keep rules with a more limited set in
      # chrome/android/java/proguard.flags instead.
      ignore_proguard_configs = true
    } else if (target_name == "androidx_startup_startup_runtime_java") {
      # Keeps emoji2 code. See http://crbug.com/1205141
      ignore_proguard_configs = true
    } else if (target_name == "androidx_test_uiautomator_uiautomator_java") {
      deps += [ ":androidx_test_runner_java" ]
    } else if (target_name == "androidx_tracing_tracing_perfetto_java") {
      # b/280878596
      jar_excluded_patterns = [ "dalvik/*" ]
    } else if (target_name == "androidx_transition_transition_java") {
      # Not specified in the POM, compileOnly dependency not supposed to be used unless
      # the library is present: b/70887421
      deps += [ ":androidx_fragment_fragment_java" ]
    } else if (target_name == "androidx_tracing_tracing_perfetto_binary_java") {
      ignore_native_libraries = true
    } else if (target_name ==
               "androidx_versionedparcelable_versionedparcelable_java") {
      # Target has AIDL, but we do not support it yet: http://crbug.com/644439
      ignore_aidl = true
    } else if (target_name == "androidx_webkit_webkit_java") {
      visibility = [
        "//android_webview/tools/system_webview_shell:*",
        "//third_party/android_deps:*",
      ]
    } else if (target_name == "androidx_room_room_guava_java") {
      deps -= [ ":androidx_room_room_runtime_jvm_java" ]
      deps += [ ":androidx_room_room_runtime_android_java" ]
    } else if (target_name == "androidx_sqlite_sqlite_framework_android_java" ||
               target_name == "androidx_room_room_runtime_android_java") {
      deps -= [ ":androidx_sqlite_sqlite_jvm_java" ]
      deps += [ ":androidx_sqlite_sqlite_android_java" ]
    }
  }

  # Arbitrarily use this target to add new top-level GN targets.
  if (target_name == "androidx_annotation_annotation_jvm_java") {
    java_group("androidx_window_stubs_java") {
      deps = [ "//third_party/androidx/local_modifications/window:androidx_window_shims_java" ]
    }
  }
}


template("androidx_java_prebuilt") {
  _androidx_prebuilt(target_name) {
    forward_variables_from(invoker, "*")
    target_type = "java_prebuilt"

    # https://crbug.com/1412551
    requires_android = true
  }
}

template("androidx_android_aar_prebuilt") {
  _androidx_prebuilt(target_name) {
    forward_variables_from(invoker, "*")
    target_type = "android_aar_prebuilt"

    # The libraries have duplicate resources such as
    # "primary_text_default_material_dark".
    resource_overlay = true

    if (target_name == "androidx_pdf_pdf_viewer_java") {
      # Target has AIDL, but we do not support it yet: http://crbug.com/644439
      ignore_aidl = true
    }
  }
}

template("androidx_java_group") {
  _androidx_prebuilt(target_name) {
    forward_variables_from(invoker, "*")
    target_type = "java_group"
  }
}