chromium/build/config/android/linker_version_script.gni

# Copyright 2018 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/config.gni")
import("//build/config/python.gni")
if (build_with_chromium) {
  import("//third_party/jni_zero/jni_zero.gni")
}

# Generate a custom linker version script that can later be used with
# "-Wl,--version-script=<path>" ldflags.
#
# Variables:
#    export_java_symbols: Optional. If true, also export all Java_* symbols
#      exported for JNI.
#    export_symbol_allowlist_files: Optional. List of paths to input files containing
#      lists of symbols to export.
#    linker_script: Path to output linker version script.
#
template("generate_linker_version_script") {
  action_with_pydeps(target_name) {
    forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
    script = "//build/android/gyp/generate_linker_version_script.py"
    outputs = [ invoker.linker_script ]
    inputs = []
    args = [ "--output=" + rebase_path(invoker.linker_script, root_build_dir) ]

    if (defined(invoker.testonly) && invoker.testonly) {
      args += [ "--export-fortesting-java-symbols" ]
    }
    if (enable_jni_multiplexing) {
      args += [ "--jni-multiplexing" ]
    }

    if (defined(invoker.export_feature_registrations) &&
        invoker.export_feature_registrations) {
      args += [ "--export-feature-registrations" ]
    }

    if (defined(invoker.export_symbol_allowlist_files)) {
      foreach(file_, invoker.export_symbol_allowlist_files) {
        inputs += [ file_ ]
        args += [
          "--export-symbol-allowlist-file",
          rebase_path(file_, root_build_dir),
        ]
      }
    }
  }
}