1#!/bin/bash 2 3set -e 4 5if [ "$#" != "1" ]; then 6echo "Pass the path to the gRPC checkout as the argument." 7exit 1 8fi 9 10traperr() { 11 STATUS=$? 12 echo "Line $BASH_LINENO: Command $BASH_COMMAND failed with status $STATUS" >&2 13 exit $STATUS 14} 15trap traperr ERR 16 17GRPC_PATH="$1" 18pushd "$GRPC_PATH" 19 20# Settings for Bazel queries 21CONFIGS="--define=grpc_no_ares=true" 22TEMP=/tmp/grpc_android_bp 23mkdir -p $TEMP 24 25# Query the list of source files with Bazel 26# We must use the system version of Bazel, not the Android version 27/usr/bin/bazel cquery $CONFIGS 'kind("source file", deps("//:grpc++_unsecure"))' > $TEMP/grpc_unsecure_deps.txt 28/usr/bin/bazel cquery $CONFIGS 'kind("source file", deps("//:grpc++"))' > $TEMP/grpc_secure_deps.txt 29 30# Remove irrelevant content from the list and clean it up 31sed -i -e '\@\.h @d; \@\.proto @d; \@\.upb\.c@d; \@\.upbdefs\.c@d; \@\.inc @d; \@third_party@d; \@wrap_memcpy\.cc@d; \@ndk_binder\.cc@d; /^@/d; s@ \(.*\)@@; s@:@/@; s@/\+@/@g; s@^/@@; s@^.*$@"\0",@' $TEMP/grpc_unsecure_deps.txt $TEMP/grpc_secure_deps.txt 32# Use diff to annotate the file lists with + and - 33# This way we detect which files are only in the secure/unsecure target. 34# Diff has exit status 1 when the files are different, hence the "|| true". 35sort -o $TEMP/grpc_secure_deps.txt $TEMP/grpc_secure_deps.txt 36sort -o $TEMP/grpc_unsecure_deps.txt $TEMP/grpc_unsecure_deps.txt 37diff -U10000 $TEMP/grpc_unsecure_deps.txt $TEMP/grpc_secure_deps.txt > $TEMP/grpc_deps_diff.txt || true 38 39# Pull out each category to its own file 40sed -n '/^ "/s/ / /p' $TEMP/grpc_deps_diff.txt > $TEMP/grpc_common_srcs.txt 41sed -n '/^+"/s/+/ /p' $TEMP/grpc_deps_diff.txt > $TEMP/grpc_secure_srcs.txt 42sed -n '/^-"/s/-/ /p' $TEMP/grpc_deps_diff.txt > $TEMP/grpc_unsecure_srcs.txt 43 44# Construct the Android.bp fragment 45OUT=$TEMP/grpc_android_bp.txt 46echo '// Autogenerated by update_android_bp.sh, do not modify.' > $OUT 47echo 'GRPC_COMMON_SRCS = [' >> $OUT 48cat $TEMP/grpc_common_srcs.txt >> $OUT 49echo ']' >> $OUT 50echo >> $OUT 51echo '// Autogenerated by update_android_bp.sh, do not modify.' >> $OUT 52echo 'GRPC_SECURE_SRCS = [' >> $OUT 53cat $TEMP/grpc_secure_srcs.txt >> $OUT 54echo ']' >> $OUT 55echo >> $OUT 56echo '// Autogenerated by update_android_bp.sh, do not modify.' >> $OUT 57echo 'GRPC_UNSECURE_SRCS = [' >> $OUT 58cat $TEMP/grpc_unsecure_srcs.txt >> $OUT 59echo ']' >> $OUT 60 61popd 62 63BPOUT=Android.bp 64if [ ! -z "$ANDROID_BUILD_TOP" ]; then 65BPOUT="$ANDROID_BUILD_TOP/external/grpc-grpc/Android.bp" 66fi 67 68# Paste the computed content into the Android.bp file 69LIST_START='^// file_lists_start$' 70LIST_END='^// file_lists_end$' 71sed -i -e "\@$LIST_START@,\@$LIST_END@{ \@$LIST_START@{p; r $OUT 72 }; \@$LIST_END@p; d }" $BPOUT 73 74echo "Android.bp file lists updated." 75