Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added small helper internal function to improve readability #808

Merged
merged 2 commits into from
Jun 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,24 @@ def _create_extra_input_args(ctx, file, build_info, dep_info):

return input_files, out_dir, build_env_file, build_flags_files

def _has_dylib_ext(file, dylib_ext):
"""Determines whether or not the file in question the platform dynamic library extension

Args:
file (File): The file to check
dylib_ext (str): The extension (eg `.so`).

Returns:
bool: Whether or not file ends with the requested extension
"""
if file.basename.endswith(dylib_ext):
return True
split = file.basename.split(".", 2)
if len(split) == 2:
if split[1] == dylib_ext[1:]:
return True
return False

def _compute_rpaths(toolchain, output_dir, dep_info):
"""Determine the artifact's rpaths relative to the bazel root for runtime linking of shared libraries.

Expand All @@ -730,7 +748,7 @@ def _compute_rpaths(toolchain, output_dir, dep_info):
# TODO(augie): I don't understand why this can't just be filtering on
# _is_dylib(lib), but doing that causes failures on darwin and windows
# examples that otherwise work.
dylibs = [lib for lib in preferreds if lib.basename.endswith(toolchain.dylib_ext) or lib.basename.split(".", 2)[1] == toolchain.dylib_ext[1:]]
dylibs = [lib for lib in preferreds if _has_dylib_ext(lib, toolchain.dylib_ext)]
if not dylibs:
return depset([])

Expand Down