1 #!/bin/bash 2 3 # 4 # Copyright (C) 2016 The Android Open Source Project 5 # 6 # Licensed under the Apache License, Version 2.0 (the "License"); 7 # you may not use this file except in compliance with the License. 8 # You may obtain a copy of the License at 9 # 10 # http://www.apache.org/licenses/LICENSE-2.0 11 # 12 # Unless required by applicable law or agreed to in writing, software 13 # distributed under the License is distributed on an "AS IS" BASIS, 14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 # See the License for the specific language governing permissions and 16 # limitations under the License. 17 # 18 19 DBUS_GENERATOR=$(which dbus-binding-generator) 20 MY_DIR=$(dirname "$0") 21 22 if [[ -z "${ANDROID_HOST_OUT}" ]]; then 23 echo "You must run envsetup.sh and lunch first." >&2 24 exit 1 25 fi 26 27 if [[ -z "${DBUS_GENERATOR}" ]]; then 28 echo "DBus bindings generator not found." >&2 29 exit 1 30 fi 31 32 set -e 33 34 # generate <kind> <dir> <xml> [xml ...] 35 # Generate a DBus proxy and/or proxy mock in the passed |dir| for the provided 36 # |xml| service files. 37 # The parameter |kind| determines whether it should generate the mock only 38 # (mock), the proxy only (proxy) or both (both). 39 generate() { 40 local kind="$1" 41 local dir="$2" 42 local xmls=("${@:3}") 43 44 mkdir -p "${MY_DIR}/${dir}" 45 local outdir=$(realpath "${MY_DIR}/${dir}") 46 local proxyh="${outdir}/dbus-proxies.h" 47 local mockh="${outdir}/dbus-proxy-mocks.h" 48 49 ${DBUS_GENERATOR} "${xmls[@]}" --mock="${mockh}" --proxy="${proxyh}" 50 51 # Fix the include path to the dbus-proxies.h to include ${dir}. 52 sed "s,include \"dbus-proxies.h\",include \"${dir}/dbus-proxies.h\"," \ 53 -i "${mockh}" 54 55 # Fix the header guards to be independent from the checkout location. 56 local guard=$(realpath "${MY_DIR}/../.." | tr '[:lower:]/ ' '[:upper:]__') 57 for header in "${mockh}" "${proxyh}"; do 58 sed "s,___CHROMEOS_DBUS_BINDING__${guard},___CHROMEOS_DBUS_BINDING__," \ 59 -i "${header}" 60 done 61 62 # Remove the files not requested. 63 if [[ "${kind}" == "mock" ]]; then 64 rm -f "${proxyh}" 65 elif [[ "${kind}" == "proxy" ]]; then 66 rm -f "${mockh}" 67 fi 68 } 69 70 UE_DIR=$(realpath "${MY_DIR}/..") 71 SHILL_DIR=$(realpath "${UE_DIR}/../connectivity/shill") 72 73 generate mock "libcros" \ 74 "${UE_DIR}/dbus_bindings/org.chromium.LibCrosService.dbus-xml" 75 76 generate mock "shill" \ 77 "${SHILL_DIR}"/dbus_bindings/org.chromium.flimflam.{Manager,Service}.dbus-xml 78 79 echo "Done." 80