Commit 8803d94e authored by Michael Spang's avatar Michael Spang Committed by Commit Bot

[Fuchsia] Place built libraries in ${root_out_dir}/lib

Fuchsia has a platform requirement that libraries be placed in in the
/lib directory in order to be located by the loader. We used to have a
shlib_subdir variable to satisfy such a requirement.  Bring this variable
back and set it to "/lib" on Fuchsia.

This allows us to reduce special handling of libraries during the
packaging phase. Ideally all package artifacts would be placed correctly
by the build system so that the packager doesn't have to rearrange.

Don't use abspath() in the script, either. Using absolute paths in the
build can be harmful (leaks data, causes cache misses) and is rarely
necessary.

BUG=925040
TBR=mef@chromium.org

Change-Id: Idb2d8d4a0fa493904000244332ed242790698b8b

Reviewed-on: https://chromium-review.googlesource.com/c/1434221Reviewed-by: default avatarMichael Spang <spang@chromium.org>
Reviewed-by: default avatarScott Graham <scottmg@chromium.org>
Reviewed-by: default avatarKevin Marshall <kmarshall@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Commit-Queue: Michael Spang <spang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#626877}
parent 68fc110e
...@@ -17,11 +17,9 @@ def MakePackagePath(file_path, roots): ...@@ -17,11 +17,9 @@ 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|.
file_path: The absolute file path to relativize. file_path: The file path to relativize.
roots: A list of absolute directory paths which may serve as a relative root roots: A list of directory paths which may serve as a relative root
for |file_path|. At least one path must contain |file_path|. for |file_path|.
Overlapping roots are permitted; the deepest matching root will be
chosen.
Examples: Examples:
...@@ -46,28 +44,17 @@ def MakePackagePath(file_path, roots): ...@@ -46,28 +44,17 @@ def MakePackagePath(file_path, roots):
if file_path.startswith(next_root): if file_path.startswith(next_root):
relative_path = file_path[len(next_root):] relative_path = file_path[len(next_root):]
# Move all dynamic libraries (ending in .so or .so.<number>) to lib/.
if re.search('.*\.so(\.\d+)?$', file_path):
relative_path = 'lib/' + os.path.basename(relative_path)
return relative_path return relative_path
raise Exception('Error: no matching root paths found for \'%s\'.' % file_path) return file_path
def _GetStrippedPath(bin_path): def _GetStrippedPath(bin_path):
"""Finds the stripped version of the binary |bin_path| in the build """Finds the stripped version of the binary |bin_path| in the build
output directory.""" output directory."""
# Skip the resolution step for binaries that don't have stripped counterparts, return bin_path.replace('lib.unstripped/', 'lib/').replace(
# like system libraries or other libraries built outside the Chromium build. 'exe.unstripped/', '')
if not '.unstripped' in bin_path:
return bin_path
return os.path.normpath(os.path.join(bin_path,
os.path.pardir,
os.path.pardir,
os.path.basename(bin_path)))
def _IsBinary(path): def _IsBinary(path):
...@@ -83,9 +70,9 @@ def BuildManifest(args): ...@@ -83,9 +70,9 @@ def BuildManifest(args):
with open(args.output_path, 'w') as manifest, \ with open(args.output_path, 'w') as manifest, \
open(args.depfile_path, 'w') as depfile: open(args.depfile_path, 'w') as depfile:
# Process the runtime deps file for file paths, recursively walking # Process the runtime deps file for file paths, recursively walking
# directories as needed. File paths are stored in absolute form, # directories as needed.
# so that MakePackagePath() may relativize to either the source root or # MakePackagePath() may relativize to either the source root or output
# output directory. # directory.
# runtime_deps may contain duplicate paths, so use a set for # runtime_deps may contain duplicate paths, so use a set for
# de-duplication. # de-duplication.
expanded_files = set() expanded_files = set()
...@@ -96,21 +83,20 @@ def BuildManifest(args): ...@@ -96,21 +83,20 @@ def BuildManifest(args):
for current_file in files: for current_file in files:
if current_file.startswith('.'): if current_file.startswith('.'):
continue continue
expanded_files.add(os.path.abspath( expanded_files.add(
os.path.join(root, current_file))) os.path.join(root, current_file))
else: else:
expanded_files.add(os.path.abspath(next_path)) expanded_files.add(next_path)
# 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.normpath(os.path.join(args.out_dir, "gen"))
app_found = False app_found = False
excluded_files_set = set(args.exclude_file) excluded_files_set = set(args.exclude_file)
for current_file in expanded_files: for current_file in expanded_files:
if _IsBinary(current_file): if _IsBinary(current_file):
current_file = _GetStrippedPath(current_file) current_file = _GetStrippedPath(current_file)
absolute_file_path = os.path.join(args.out_dir, current_file) in_package_path = MakePackagePath(current_file,
in_package_path = MakePackagePath(absolute_file_path,
[gen_dir, args.root_dir, args.out_dir]) [gen_dir, args.root_dir, args.out_dir])
if in_package_path == args.app_filename: if in_package_path == args.app_filename:
app_found = True app_found = True
...@@ -119,11 +105,7 @@ def BuildManifest(args): ...@@ -119,11 +105,7 @@ def BuildManifest(args):
excluded_files_set.remove(in_package_path) excluded_files_set.remove(in_package_path)
continue continue
# The source path is relativized so that it can be used on multiple manifest.write('%s=%s\n' % (in_package_path, current_file))
# environments with differing parent directory structures,
# e.g. builder bots and swarming clients.
manifest.write('%s=%s\n' % (in_package_path,
os.path.relpath(current_file, args.out_dir)))
if len(excluded_files_set) > 0: if len(excluded_files_set) > 0:
raise Exception('Some files were excluded with --exclude-file, but ' raise Exception('Some files were excluded with --exclude-file, but '
......
...@@ -11,9 +11,9 @@ declare_args() { ...@@ -11,9 +11,9 @@ declare_args() {
# Compute the arch-specific path to packages' dynamic library dependencies. # Compute the arch-specific path to packages' dynamic library dependencies.
if (current_cpu == "arm64") { if (current_cpu == "arm64") {
dist_libroot = fuchsia_sdk + "/arch/arm64/dist/" dist_libroot = fuchsia_sdk + "/arch/arm64/dist"
} else if (current_cpu == "x64") { } else if (current_cpu == "x64") {
dist_libroot = fuchsia_sdk + "/arch/x64/dist/" dist_libroot = fuchsia_sdk + "/arch/x64/dist"
} else { } else {
assert(false, "No libraries available for architecture: $current_cpu") assert(false, "No libraries available for architecture: $current_cpu")
} }
......
...@@ -85,21 +85,21 @@ template("fuchsia_package") { ...@@ -85,21 +85,21 @@ template("fuchsia_package") {
args = [ args = [
"--root-dir", "--root-dir",
rebase_path("//"), rebase_path("//", root_build_dir),
"--out-dir", "--out-dir",
rebase_path(root_out_dir), rebase_path(root_out_dir, root_build_dir),
"--app-name", "--app-name",
pkg.package_name, pkg.package_name,
"--app-filename", "--app-filename",
get_label_info(pkg.binary, "name"), get_label_info(pkg.binary, "name"),
"--sandbox-policy-path", "--sandbox-policy-path",
rebase_path(pkg.sandbox_policy), rebase_path(pkg.sandbox_policy, root_build_dir),
"--runtime-deps-file", "--runtime-deps-file",
rebase_path(_runtime_deps_file), rebase_path(_runtime_deps_file, root_build_dir),
"--depfile-path", "--depfile-path",
rebase_path(_depfile), rebase_path(_depfile, root_build_dir),
"--output-path", "--output-path",
rebase_path(_archive_manifest), rebase_path(_archive_manifest, root_build_dir),
] ]
if (defined(pkg.excluded_files)) { if (defined(pkg.excluded_files)) {
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
import("//build/toolchain/gcc_toolchain.gni")
import("//build/config/fuchsia/config.gni") import("//build/config/fuchsia/config.gni")
import("//build/toolchain/gcc_toolchain.gni")
# Fuchsia builds using the Clang toolchain, with most parameters common across # Fuchsia builds using the Clang toolchain, with most parameters common across
# the different target architectures. # the different target architectures.
...@@ -21,6 +21,8 @@ template("fuchsia_clang_toolchain") { ...@@ -21,6 +21,8 @@ template("fuchsia_clang_toolchain") {
use_unstripped_as_runtime_outputs = true use_unstripped_as_runtime_outputs = true
} }
default_shlib_subdir = "/lib"
toolchain_args = invoker.toolchain_args toolchain_args = invoker.toolchain_args
toolchain_args.current_os = "fuchsia" toolchain_args.current_os = "fuchsia"
} }
......
...@@ -241,6 +241,12 @@ template("gcc_toolchain") { ...@@ -241,6 +241,12 @@ template("gcc_toolchain") {
default_shlib_extension = shlib_extension default_shlib_extension = shlib_extension
} }
if (defined(invoker.default_shlib_subdir)) {
default_shlib_subdir = invoker.default_shlib_subdir
} else {
default_shlib_subdir = ""
}
if (defined(invoker.executable_extension)) { if (defined(invoker.executable_extension)) {
default_executable_extension = invoker.executable_extension default_executable_extension = invoker.executable_extension
} else { } else {
...@@ -434,7 +440,7 @@ template("gcc_toolchain") { ...@@ -434,7 +440,7 @@ template("gcc_toolchain") {
# specifies). # specifies).
default_output_extension = default_shlib_extension default_output_extension = default_shlib_extension
default_output_dir = "{{root_out_dir}}" default_output_dir = "{{root_out_dir}}${default_shlib_subdir}"
output_prefix = "lib" output_prefix = "lib"
...@@ -494,7 +500,7 @@ template("gcc_toolchain") { ...@@ -494,7 +500,7 @@ template("gcc_toolchain") {
default_output_extension = default_shlib_extension default_output_extension = default_shlib_extension
} }
default_output_dir = "{{root_out_dir}}" default_output_dir = "{{root_out_dir}}${default_shlib_subdir}"
output_prefix = "lib" output_prefix = "lib"
...@@ -622,6 +628,7 @@ template("clang_toolchain") { ...@@ -622,6 +628,7 @@ template("clang_toolchain") {
[ [
"strip", "strip",
"is_clang_analysis_supported", "is_clang_analysis_supported",
"default_shlib_subdir",
"enable_linker_map", "enable_linker_map",
"use_unstripped_as_runtime_outputs", "use_unstripped_as_runtime_outputs",
]) ])
......
...@@ -78,6 +78,13 @@ if (is_posix || is_fuchsia) { ...@@ -78,6 +78,13 @@ if (is_posix || is_fuchsia) {
shlib_prefix = "" shlib_prefix = ""
} }
# Directory for shared library files.
if (is_fuchsia) {
shlib_subdir = "/lib"
} else {
shlib_subdir = ""
}
# While other "tool"s in a toolchain are specific to the target of that # While other "tool"s in a toolchain are specific to the target of that
# toolchain, the "stamp" and "copy" tools are really generic to the host; # toolchain, the "stamp" and "copy" tools are really generic to the host;
# but each toolchain must define them separately. GN doesn't allow a # but each toolchain must define them separately. GN doesn't allow a
......
...@@ -217,7 +217,7 @@ if (!is_ios && !is_android) { ...@@ -217,7 +217,7 @@ if (!is_ios && !is_android) {
# Copy boiler-plate files into the package. # Copy boiler-plate files into the package.
copy("cronet_package_copy") { copy("cronet_package_copy") {
sources = [ sources = [
"$root_out_dir/$_cronet_shared_lib_file_name", "${root_out_dir}${shlib_subdir}/${_cronet_shared_lib_file_name}",
"//AUTHORS", "//AUTHORS",
"//chrome/VERSION", "//chrome/VERSION",
] ]
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
assert(is_fuchsia) assert(is_fuchsia)
import("//build/toolchain/toolchain.gni")
import("fuchsia_sdk_pkg.gni") import("fuchsia_sdk_pkg.gni")
config("sdk_lib_dirs_config") { config("sdk_lib_dirs_config") {
...@@ -18,7 +19,7 @@ copy("sysroot_dist_libs") { ...@@ -18,7 +19,7 @@ copy("sysroot_dist_libs") {
] ]
outputs = [ outputs = [
"${root_out_dir}/{{source_file_part}}", "${root_out_dir}${shlib_subdir}/{{source_file_part}}",
] ]
} }
...@@ -29,7 +30,7 @@ group("runtime_library") { ...@@ -29,7 +30,7 @@ group("runtime_library") {
":sysroot_dist_libs", ":sysroot_dist_libs",
# This is used directly from //build/config/fuchsia:compiler and thus # This is used directly from //build/config/fuchsia:compiler and thus
# needs to be included by default. # also needs to be included by default.
"sdk:fdio_dist_libs", "sdk:fdio_dist_libs",
] ]
} }
...@@ -50,7 +51,7 @@ copy("vulkan_image_pipe") { ...@@ -50,7 +51,7 @@ copy("vulkan_image_pipe") {
] ]
outputs = [ outputs = [
"${root_out_dir}/{{source_file_part}}", "${root_out_dir}${shlib_subdir}/{{source_file_part}}",
] ]
} }
...@@ -87,7 +88,7 @@ copy("vulkan_validation_libs") { ...@@ -87,7 +88,7 @@ copy("vulkan_validation_libs") {
] ]
outputs = [ outputs = [
"${root_out_dir}/{{source_file_part}}", "${root_out_dir}${shlib_subdir}/{{source_file_part}}",
] ]
} }
......
...@@ -71,7 +71,7 @@ template("fuchsia_sdk_pkg") { ...@@ -71,7 +71,7 @@ template("fuchsia_sdk_pkg") {
} }
outputs = [ outputs = [
"${root_out_dir}/{{source_file_part}}", "${root_out_dir}${shlib_subdir}/{{source_file_part}}",
] ]
} }
} }
......
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