diff options
author | Vinh Tran <vinhdaitran@google.com> | 2023-07-21 19:38:23 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-07-21 19:38:23 +0000 |
commit | f0df148dbeb9b9ed3816aad328ebe7c65efaaa24 (patch) | |
tree | c75dabb560288e11786211bdc61ba40dde4b8674 /cc/private/toolchain/link_dynamic_library.sh | |
parent | 3544b5a539d9e51161befd2ac3fdc04525bced91 (diff) | |
parent | 9a4853f0327e0266818c8d6b4967e2e8f36b1a88 (diff) | |
download | bazelbuild-rules_cc-android-14.0.0_r29.tar.gz |
Merge remote-tracking branch 'aosp/upstream-main' into main am: 755aefef35 am: d7bf0d569f am: 59148a708a am: 13ca54997b am: 9a4853f032android-14.0.0_r51android-14.0.0_r50android-14.0.0_r37android-14.0.0_r36android-14.0.0_r35android-14.0.0_r34android-14.0.0_r33android-14.0.0_r32android-14.0.0_r31android-14.0.0_r30android-14.0.0_r29android-14.0.0_r28android14-qpr3-releaseandroid14-qpr2-s5-releaseandroid14-qpr2-s4-releaseandroid14-qpr2-s3-releaseandroid14-qpr2-s2-releaseandroid14-qpr2-s1-releaseandroid14-qpr2-release
Original change: https://android-review.googlesource.com/c/platform/external/bazelbuild-rules_cc/+/2663436
Change-Id: I450b9f32024fa1b0844cc21a825c26589feb3977
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Diffstat (limited to 'cc/private/toolchain/link_dynamic_library.sh')
-rwxr-xr-x | cc/private/toolchain/link_dynamic_library.sh | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/cc/private/toolchain/link_dynamic_library.sh b/cc/private/toolchain/link_dynamic_library.sh new file mode 100755 index 0000000..c71d498 --- /dev/null +++ b/cc/private/toolchain/link_dynamic_library.sh @@ -0,0 +1,113 @@ +#!/bin/bash +# +# Copyright 2016 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This script handles interface library generation for dynamic library +# link action. +# +# Bazel can be configured to generate external interface library script +# to generate interface libraries in CppLinkAction for dynamic libraries. +# This is not needed on Windows (as the "interface" libraries are +# generated by default). This script therefore handles the cases when +# external script is provided, or when no script should be used. + +set -eu + +E_LINKER_COMMAND_NOT_FOUND=12 +E_INTERFACE_BUILDER_NOT_FOUND=13 + + +SUFFIX=".rewritten" + +other_args="" + +if [[ "$#" -eq 1 ]]; then + if [[ "$1" != @* ]]; then + echo "Parameter file must start with @" 1>&2; + exit "$E_LINKER_COMMAND_NOT_FOUND" + fi + + filename=$(echo "$1" | cut -c2-) + first_five_lines=$(head -n 5 $filename) + + # Should generate interface library switch (<yes|no>); if the value is "no", + # following 3 args are ignored (but must be present) + GENERATE_INTERFACE_LIBRARY=$(echo "$first_five_lines" | head -n1 | tail -n1) + # Tool which can generate interface library from dynamic library file + INTERFACE_LIBRARY_BUILDER=$(echo "$first_five_lines" | head -n2 | tail -n1) + # Dynamic library from which we want to generate interface library + DYNAMIC_LIBRARY=$(echo "$first_five_lines" | head -n3 | tail -n1) + # Resulting interface library + INTERFACE_LIBRARY=$(echo "$first_five_lines" | head -n4 | tail -n1) + # The command used to generate the dynamic library + LINKER_COMMAND=$(echo "$first_five_lines" | head -n5 | tail -n1) + + rest_of_lines=$(tail -n +6 $filename) + new_param_file="${filename}${SUFFIX}" + echo "$rest_of_lines" > $new_param_file + other_args="@$new_param_file" + + if [[ ! -e "$LINKER_COMMAND" ]]; then + echo "Linker command ($LINKER_COMMAND) not found." 1>&2; + exit "$E_LINKER_COMMAND_NOT_FOUND" + fi + + if [[ "no" == "$GENERATE_INTERFACE_LIBRARY" ]]; then + INTERFACE_GENERATION=: + else + if [[ ! -e "$INTERFACE_LIBRARY_BUILDER" ]]; then + echo "Interface library builder ($INTERFACE_LIBRARY_BUILDER) + not found." 1>&2; + exit "$E_INTERFACE_BUILDER_NOT_FOUND" + fi + INTERFACE_GENERATION="${INTERFACE_LIBRARY_BUILDER} ${DYNAMIC_LIBRARY} + ${INTERFACE_LIBRARY}" + fi + + ${LINKER_COMMAND} "$other_args" && ${INTERFACE_GENERATION} +else + # TODO(b/113358321): Remove this branch once projects are migrated to not + # splitting the linking command line. + # Should generate interface library switch (<yes|no>); if the value is "no", + # following 3 args are ignored (but must be present) + GENERATE_INTERFACE_LIBRARY="$1" + # Tool which can generate interface library from dynamic library file + INTERFACE_LIBRARY_BUILDER="$2" + # Dynamic library from which we want to generate interface library + DYNAMIC_LIBRARY="$3" + # Resulting interface library + INTERFACE_LIBRARY="$4" + # The command used to generate the dynamic library + LINKER_COMMAND="$5" + shift 5 + if [[ ! -e "$LINKER_COMMAND" ]]; then + echo "Linker command ($LINKER_COMMAND) not found." 1>&2; + exit "$E_LINKER_COMMAND_NOT_FOUND" + fi + + if [[ "no" == "$GENERATE_INTERFACE_LIBRARY" ]]; then + INTERFACE_GENERATION=: + else + if [[ ! -e "$INTERFACE_LIBRARY_BUILDER" ]]; then + echo "Interface library builder ($INTERFACE_LIBRARY_BUILDER) + not found." 1>&2; + exit "$E_INTERFACE_BUILDER_NOT_FOUND" + fi + INTERFACE_GENERATION="${INTERFACE_LIBRARY_BUILDER} ${DYNAMIC_LIBRARY} + ${INTERFACE_LIBRARY}" + fi + + ${LINKER_COMMAND} "$@" && ${INTERFACE_GENERATION} +fi |