Commit 2e33fba9 authored by Michael Spang's avatar Michael Spang Committed by Commit Bot

[Fuchsia] Add SDK runtime libraries to runtime_deps

Add explicit runtime dependencies on runtime libraries so that they
don't need special handling at packaging time.

Bug: 925040

Change-Id: I520d4638a1bf9e00b75b0f83c1ea9c456665c01e
Reviewed-on: https://chromium-review.googlesource.com/c/1435535Reviewed-by: default avatarScott Graham <scottmg@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Reviewed-by: default avatarKevin Marshall <kmarshall@chromium.org>
Commit-Queue: Michael Spang <spang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#626815}
parent 279523e6
...@@ -293,6 +293,10 @@ group("common_deps") { ...@@ -293,6 +293,10 @@ group("common_deps") {
if (is_win && generate_order_files && !is_nacl) { if (is_win && generate_order_files && !is_nacl) {
public_deps += [ "//tools/cygprofile_win" ] public_deps += [ "//tools/cygprofile_win" ]
} }
if (is_fuchsia) {
public_deps += [ "//third_party/fuchsia-sdk:runtime_library" ]
}
} }
group("executable_deps") { group("executable_deps") {
......
...@@ -13,64 +13,6 @@ import sys ...@@ -13,64 +13,6 @@ import sys
import tempfile import tempfile
def ReadDynamicLibDeps(paths):
"""Returns a list of NEEDED libraries read from a binary's ELF header."""
LIBRARY_RE = re.compile(r'.*\(NEEDED\)\s+Shared library: \[(?P<lib>.*)\]')
elfinfo = subprocess.check_output(['readelf', '-d'] + paths,
stderr=open(os.devnull, 'w'))
libs = []
for line in elfinfo.split('\n'):
match = LIBRARY_RE.match(line.rstrip())
if match:
lib = match.group('lib')
# libc.so is an alias for ld.so.1 .
if lib == 'libc.so':
lib = 'ld.so.1'
# Skip libzircon.so, as it is supplied by the OS loader.
if lib != 'libzircon.so':
libs.append(lib)
return libs
def ComputeTransitiveLibDeps(executable_path, available_libs):
"""Returns a set representing the library dependencies of |executable_path|,
the dependencies of its dependencies, and so on.
A list of candidate library filesystem paths is passed using |available_libs|
to help with resolving full paths from the short ELF header filenames."""
# Stack of binaries (libraries, executables) awaiting traversal.
to_visit = [executable_path]
# The computed set of visited transitive dependencies.
deps = set()
while to_visit:
deps = deps.union(to_visit)
# Resolve the full paths for all of |cur_path|'s NEEDED libraries.
dep_paths = {available_libs[dep]
for dep in ReadDynamicLibDeps(list(to_visit))}
# Add newly discovered dependencies to the pending traversal stack.
to_visit = dep_paths.difference(deps)
return deps
def EnumerateDirectoryFiles(path):
"""Returns a flattened list of all files contained under |path|."""
output = set()
for dirname, _, files in os.walk(path):
output = output.union({os.path.join(dirname, f) for f in files})
return output
def MakePackagePath(file_path, roots): def MakePackagePath(file_path, roots):
"""Computes a path for |file_path| that is relative to one of the directory """Computes a path for |file_path| that is relative to one of the directory
paths in |roots|. paths in |roots|.
...@@ -159,22 +101,6 @@ def BuildManifest(args): ...@@ -159,22 +101,6 @@ def BuildManifest(args):
else: else:
expanded_files.add(os.path.abspath(next_path)) expanded_files.add(os.path.abspath(next_path))
# Get set of dist libraries available for dynamic linking.
dist_libs = set()
for next_dir in args.dynlib_path:
dist_libs = dist_libs.union(EnumerateDirectoryFiles(next_dir))
# Compute the set of dynamic libraries used by the application or its
# transitive dependencies (dist libs and components), and merge the result
# with |expanded_files| so that they are included in the manifest.
#
# TODO(crbug.com/861931): Make sure that deps of the files in data_deps
# (binaries and libraries) are included as well.
expanded_files = expanded_files.union(
ComputeTransitiveLibDeps(
args.app_filename,
{os.path.basename(f): f for f in expanded_files.union(dist_libs)}))
# Format and write out the manifest contents. # Format and write out the manifest contents.
gen_dir = os.path.join(args.out_dir, "gen") gen_dir = os.path.join(args.out_dir, "gen")
app_found = False app_found = False
...@@ -249,8 +175,6 @@ def main(): ...@@ -249,8 +175,6 @@ def main():
help='Path to write GN deps file.') help='Path to write GN deps file.')
parser.add_argument('--exclude-file', action='append', default=[], parser.add_argument('--exclude-file', action='append', default=[],
help='Package-relative file path to exclude from the package.') help='Package-relative file path to exclude from the package.')
parser.add_argument('--dynlib-path', action='append', default=[],
help='Paths for the dynamic libraries relative to the output dir.')
parser.add_argument('--output-path', required=True, help='Output file path.') parser.add_argument('--output-path', required=True, help='Output file path.')
args = parser.parse_args() args = parser.parse_args()
......
...@@ -98,10 +98,6 @@ template("fuchsia_package") { ...@@ -98,10 +98,6 @@ template("fuchsia_package") {
rebase_path(_runtime_deps_file), rebase_path(_runtime_deps_file),
"--depfile-path", "--depfile-path",
rebase_path(_depfile), rebase_path(_depfile),
"--dynlib-path",
rebase_path(dist_libroot),
"--dynlib-path",
rebase_path("${sysroot}/dist"),
"--output-path", "--output-path",
rebase_path(_archive_manifest), rebase_path(_archive_manifest),
] ]
......
...@@ -11,6 +11,29 @@ config("sdk_lib_dirs_config") { ...@@ -11,6 +11,29 @@ config("sdk_lib_dirs_config") {
lib_dirs = [ "sdk/arch/${target_cpu}/lib" ] lib_dirs = [ "sdk/arch/${target_cpu}/lib" ]
} }
# Copy the loader to place it at the expected path in the final package.
copy("sysroot_dist_libs") {
sources = [
"sdk/arch/${target_cpu}/sysroot/dist/lib/ld.so.1",
]
outputs = [
"${root_out_dir}/{{source_file_part}}",
]
}
# This adds the runtime deps for //build/config/compiler:runtime_library
# as that is a config target and thus cannot include data_deps.
group("runtime_library") {
data_deps = [
":sysroot_dist_libs",
# This is used directly from //build/config/fuchsia:compiler and thus
# needs to be included by default.
"sdk:fdio_dist_libs",
]
}
copy("vulkan_base_configs") { copy("vulkan_base_configs") {
sources = [ sources = [
"sdk/pkg/vulkan_layers/data/vulkan/explicit_layer.d/VkLayer_image_pipe_swapchain.json", "sdk/pkg/vulkan_layers/data/vulkan/explicit_layer.d/VkLayer_image_pipe_swapchain.json",
...@@ -21,10 +44,9 @@ copy("vulkan_base_configs") { ...@@ -21,10 +44,9 @@ copy("vulkan_base_configs") {
] ]
} }
copy("vulkan_base_libs") { copy("vulkan_image_pipe") {
sources = [ sources = [
"sdk/arch/${target_cpu}/dist/libVkLayer_image_pipe_swapchain.so", "sdk/arch/${target_cpu}/dist/libVkLayer_image_pipe_swapchain.so",
"sdk/arch/${target_cpu}/dist/libvulkan.so",
] ]
outputs = [ outputs = [
...@@ -35,7 +57,8 @@ copy("vulkan_base_libs") { ...@@ -35,7 +57,8 @@ copy("vulkan_base_libs") {
group("vulkan_base") { group("vulkan_base") {
data_deps = [ data_deps = [
":vulkan_base_configs", ":vulkan_base_configs",
":vulkan_base_libs", ":vulkan_image_pipe",
"sdk:vulkan_dist_libs",
] ]
} }
......
// Copyright 2019 The Fuchsia Authors. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
assert(is_fuchsia) assert(is_fuchsia)
import("//build/config/fuchsia/fidl_library.gni") import("//build/config/fuchsia/fidl_library.gni")
import("//build/toolchain/toolchain.gni")
# Templates for Fuchsia SDK packages. # Templates for Fuchsia SDK packages.
...@@ -48,19 +49,38 @@ template("fuchsia_sdk_fidl_pkg") { ...@@ -48,19 +49,38 @@ template("fuchsia_sdk_fidl_pkg") {
# is not specified explicitly. # is not specified explicitly.
# sources - List of sources relative to sdk/pkg/${name}. # sources - List of sources relative to sdk/pkg/${name}.
# deps - List of dependencies. # deps - List of dependencies.
# libs - List of precompiled libraries. # shared_libs - List of precompiled shared libraries.
# static_libs - List of precompiled static libraries.
template("fuchsia_sdk_pkg") { template("fuchsia_sdk_pkg") {
config("${target_name}_config") { config("${target_name}_config") {
forward_variables_from(invoker, [ "include_dirs" ]) forward_variables_from(invoker, [ "include_dirs" ])
visibility = [ ":${invoker.target_name}" ] visibility = [ ":${invoker.target_name}" ]
} }
if (defined(invoker.shared_libs)) {
if (defined(invoker.sdk_dist_dir)) {
sdk_dist_dir = invoker.sdk_dist_dir
} else {
sdk_dist_dir = "arch/${target_cpu}/dist"
}
copy("${target_name}_dist_libs") {
sources = []
foreach(lib, invoker.shared_libs) {
sources += [ "${sdk_dist_dir}/lib${lib}.so" ]
}
outputs = [
"${root_out_dir}/{{source_file_part}}",
]
}
}
static_library(target_name) { static_library(target_name) {
forward_variables_from(invoker, forward_variables_from(invoker,
[ [
"data", "data",
"deps", "deps",
"libs",
"public_deps", "public_deps",
"sources", "sources",
"testonly", "testonly",
...@@ -69,8 +89,14 @@ template("fuchsia_sdk_pkg") { ...@@ -69,8 +89,14 @@ template("fuchsia_sdk_pkg") {
public_configs = [ ":${invoker.target_name}_config" ] public_configs = [ ":${invoker.target_name}_config" ]
if (defined(libs)) { if (defined(invoker.shared_libs)) {
configs += [ "//third_party/fuchsia-sdk:sdk_lib_dirs_config" ] configs += [ "//third_party/fuchsia-sdk:sdk_lib_dirs_config" ]
libs = invoker.shared_libs
data_deps = [
":${target_name}_dist_libs",
]
} else if (defined(invoker.static_libs)) {
libs = invoker.static_libs
} }
} }
} }
...@@ -121,9 +121,13 @@ def ConvertCcPrebuiltLibrary(json): ...@@ -121,9 +121,13 @@ def ConvertCcPrebuiltLibrary(json):
converted = ConvertCommonFields(json) converted = ConvertCommonFields(json)
converted['type'] = 'fuchsia_sdk_pkg' converted['type'] = 'fuchsia_sdk_pkg'
converted['sources'] = json['headers'] converted['sources'] = json['headers']
converted['libs'] = [json['name']]
converted['include_dirs'] = [json['root'] + '/include'] converted['include_dirs'] = [json['root'] + '/include']
if json['format'] == 'shared':
converted['shared_libs'] = [json['name']]
else:
converted['static_libs'] = [json['name']]
return converted return converted
def ConvertCcSourceLibrary(json): def ConvertCcSourceLibrary(json):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment