blob: 5a94d096af414142d9c597963e2d85197705254c [file] [log] [blame]
# Copyright 2019 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/config/clang/clang.gni")
import("//build/zircon/c_utils.gni")
# Extracts the list of imported symbols from a prebuilt library or
# a library generated by another target.
#
# IMPORTANT: Building a shared library with an instrumented build
# variant (e.g. "asan") typically introduces extra ibstrumentation
# specific symbols (e.g. `__asan_init`) which will fail a later
# comparison with verify_imported_symbols().
#
# Due to this, callers of this template should ensure that the
# 'library_target' passed here as argument is never built with
# an instrumented variant (a simple way to do that is to use
# `exclude_toolchain_tags = [ "instrumented" ]`).
#
# Parameters
#
# library (optional)
# Location of the prebuilt library.
#
# library_target (optional)
# GN label of the target that generates the library.
# Note that either one of 'library' or 'library_target' is required.
#
# symbols
# Location of the output symbol list. It should fall within the output
# directory for the build.
template("extract_imported_symbols") {
assert(defined(invoker.symbols), "symbols must be specified")
assert(
!(defined(invoker.library) && defined(invoker.library_target)),
"Only one of 'library' or 'library_target' can be set when calling extract_imported_symbols().")
if (defined(invoker.library)) {
# Nothing here.
} else if (defined(invoker.library_target)) {
# Generate a response file that will contain the path to the library file.
_library_rsp_target = "${target_name}_library.rsp"
_library_rsp_file = "$target_gen_dir/${target_name}_library.rsp"
link_output_rspfile(_library_rsp_target) {
deps = [ invoker.library_target ]
outputs = [ _library_rsp_file ]
}
} else {
assert(
false,
"Either 'library' or 'library_target' must be set when calling extract_imported_symbols().")
}
action(target_name) {
script = "//build/cpp/extract_imported_symbols.sh"
forward_variables_from(invoker,
[
"deps",
"testonly",
"visibility",
])
outputs = [ invoker.symbols ]
inputs = [ "$clang_prefix/llvm-nm" ]
if (defined(invoker.library)) {
inputs += [ invoker.library ]
args = [
"$rebased_clang_prefix/llvm-nm",
rebase_path(invoker.library, root_build_dir),
rebase_path(invoker.symbols, root_build_dir),
]
} else {
depfile = "$target_gen_dir/${target_name}.d"
inputs += [ _library_rsp_file ]
args = [
"$rebased_clang_prefix/llvm-nm",
"@" + rebase_path(_library_rsp_file, root_build_dir),
rebase_path(invoker.symbols, root_build_dir),
rebase_path(depfile, root_build_dir),
]
if (!defined(deps)) {
deps = []
}
deps += [ ":${_library_rsp_target}" ]
}
}
}