update_rs_prebuilts.sh 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. #!/bin/bash
  2. # We are currently in frameworks/rs, so compute our top-level directory.
  3. MY_ANDROID_DIR=$PWD/../../
  4. cd $MY_ANDROID_DIR
  5. if [[ $OSTYPE == darwin* ]];
  6. then
  7. DARWIN=1
  8. SHORT_OSNAME=darwin
  9. SONAME=dylib
  10. # Only build arm on darwin.
  11. TARGETS=(arm)
  12. SYS_NAMES=(generic)
  13. NUM_CORES=`sysctl -n hw.ncpu`
  14. else
  15. DARWIN=0
  16. SHORT_OSNAME=linux
  17. SONAME=so
  18. # Target architectures and their system library names.
  19. TARGETS=(arm x86 arm64 x86_64)
  20. SYS_NAMES=(generic generic_x86 generic_arm64 generic_x86_64)
  21. NUM_CORES=`cat /proc/cpuinfo | grep processor | tail -n 1 | cut -f 2 -d :`
  22. NUM_CORES=$(($NUM_CORES+1))
  23. fi
  24. # Make sure we build all of LLVM from scratch.
  25. export FORCE_BUILD_LLVM_COMPONENTS=true
  26. # Skip building LLVM and compiler-rt tests while updating prebuilts
  27. export SKIP_LLVM_TESTS=true
  28. # RENDERSCRIPT_V8_JAR is the generated JAVA static lib for RenderScript Support Lib.
  29. RENDERSCRIPT_V8_JAR=out/target/common/obj/JAVA_LIBRARIES/android-support-v8-renderscript_intermediates/classes.jar
  30. # ANDROID_HOST_OUT is where the new prebuilts will be constructed/copied from.
  31. ANDROID_HOST_OUT=$MY_ANDROID_DIR/out/host/$SHORT_OSNAME-x86/
  32. # HOST_LIB_DIR allows us to pick up the built librsrt_*.bc libraries.
  33. HOST_LIB_DIR=$ANDROID_HOST_OUT/lib
  34. # HOST_LIB64_DIR
  35. HOST_LIB64_DIR=$ANDROID_HOST_OUT/lib64
  36. # PREBUILTS_DIR is where we want to copy our new files to.
  37. PREBUILTS_DIR=$MY_ANDROID_DIR/prebuilts/sdk/
  38. print_usage() {
  39. echo "USAGE: $0 [-h|--help] [-j <num>] [-n|--no-build] [--no-start] [-x]"
  40. echo "OPTIONS:"
  41. echo " -j <num> : Specify parallelism for builds."
  42. echo " -h, --help : Display this help message."
  43. echo " -n, --no-build : Skip the build step and just copy files."
  44. echo " --no-start : Do not \"repo start\" a new branch for the copied files."
  45. echo " -x : Display commands before they are executed."
  46. }
  47. build_rs_libs() {
  48. echo Building for target $1
  49. lunch $1
  50. # Build the RS runtime libraries.
  51. cd $MY_ANDROID_DIR/frameworks/rs/driver/runtime && mma -j$NUM_CORES && cd - || exit 1
  52. # Build libRSSupport.so
  53. cd $MY_ANDROID_DIR/frameworks/rs/support && mma -j$NUM_CORES && cd - || exit 2
  54. # Build android-support-v8-renderscript.jar
  55. # We need to explicitly do so, since JACK won't generate a jar by default.
  56. cd $MY_ANDROID_DIR && make $RENDERSCRIPT_V8_JAR -j$NUM_CORES && cd - || exit 3
  57. # Build libcompiler-rt.a
  58. cd $MY_ANDROID_DIR/external/compiler-rt && mma -j$NUM_CORES && cd - || exit 4
  59. # Build the blas libraries.
  60. cd $MY_ANDROID_DIR/external/cblas && mma -j$NUM_CORES && cd - || exit 5
  61. }
  62. build_rstest_compatlib() {
  63. echo Building for target $1
  64. lunch $1
  65. # Build a sample support application to ensure that all the pieces are up to date.
  66. cd $MY_ANDROID_DIR/frameworks/rs/tests/java_api/RSTest_CompatLib/ && mma -j$NUM_CORES FORCE_BUILD_RS_COMPAT=true && cd - || exit 6
  67. }
  68. build_rs_host_tools() {
  69. echo "Building RS host tools (llvm-rs-cc and bcc_compat)"
  70. lunch aosp_arm64-userdebug
  71. cd $MY_ANDROID_DIR/frameworks/compile/slang && mma -j$NUM_CORES && cd - || exit 7
  72. cd $MY_ANDROID_DIR/frameworks/compile/libbcc && mma -j$NUM_CORES && cd - || exit 8
  73. }
  74. # Build everything by default
  75. build_rs=1
  76. # repo start by default
  77. repo_start=1
  78. while [ $# -gt 0 ]; do
  79. case "$1" in
  80. -h|--help)
  81. print_usage
  82. exit 0
  83. ;;
  84. -j)
  85. if [[ $# -gt 1 && "$2" =~ ^[0-9]+$ ]]; then
  86. NUM_CORES="$2"
  87. shift
  88. else
  89. echo Expected numeric argument after "$1"
  90. print_usage
  91. exit 99
  92. fi
  93. ;;
  94. -n|--no-build)
  95. build_rs=0
  96. ;;
  97. --no-start)
  98. repo_start=0
  99. ;;
  100. -x)
  101. # set lets us enable bash -x mode.
  102. set -x
  103. ;;
  104. *)
  105. echo Unknown argument: "$1"
  106. print_usage
  107. exit 99
  108. break
  109. ;;
  110. esac
  111. shift
  112. done
  113. if [ $build_rs -eq 1 ]; then
  114. echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  115. echo !!! BUILDING RS PREBUILTS !!!
  116. echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  117. echo "Using $NUM_CORES cores"
  118. source build/envsetup.sh
  119. build_rs_host_tools
  120. for t in ${TARGETS[@]}; do
  121. build_rs_libs aosp_${t}-userdebug
  122. done
  123. echo DONE BUILDING RS PREBUILTS
  124. else
  125. echo SKIPPING BUILD OF RS PREBUILTS
  126. fi
  127. cd $PREBUILTS_DIR || exit 3
  128. # Verify that project is "clean"
  129. if [ `git status --short --untracked-files=no | wc -l` -ne 0 ]; then
  130. echo $PREBUILTS_DIR contains modified files -- aborting.
  131. git status --untracked-files=no
  132. exit 1
  133. fi
  134. if [ $repo_start -eq 1 ]; then
  135. DATE=`date +%Y%m%d`
  136. repo start pb_$DATE .
  137. if [ $? -ne 0 ]; then
  138. echo repo start failed -- aborting.
  139. exit 1
  140. fi
  141. fi
  142. # Don't copy device prebuilts on Darwin. We don't need/use them.
  143. if [ $DARWIN -eq 0 ]; then
  144. for i in $(seq 0 $((${#TARGETS[@]} - 1))); do
  145. t=${TARGETS[$i]}
  146. sys_name=${SYS_NAMES[$i]}
  147. case "$sys_name" in
  148. *64)
  149. sys_lib_dir=$MY_ANDROID_DIR/out/target/product/$sys_name/system/lib64
  150. ;;
  151. *)
  152. sys_lib_dir=$MY_ANDROID_DIR/out/target/product/$sys_name/system/lib
  153. ;;
  154. esac
  155. obj_lib_dir=$MY_ANDROID_DIR/out/target/product/$sys_name/obj/SHARED_LIBRARIES
  156. obj_static_lib_dir=$MY_ANDROID_DIR/out/target/product/$sys_name/obj/STATIC_LIBRARIES
  157. for a in `find renderscript/lib/$t -name \*.so`; do
  158. file=`basename $a`
  159. name="${file%.*}"
  160. cp $obj_lib_dir/${name}_intermediates/$file $a || exit 4
  161. done
  162. for a in `find renderscript/lib/$t -name \*.bc`; do
  163. file=`basename $a`
  164. cp `find $HOST_LIB_DIR $HOST_LIB64_DIR $sys_lib_dir $obj_lib_dir -name $file | head -1` $a || exit 5
  165. done
  166. for a in `find renderscript/lib/$t -name \*.a`; do
  167. file=`basename $a`
  168. name="${file%.*}"
  169. cp $obj_static_lib_dir/${name}_intermediates/$file $a || exit 4
  170. done
  171. done
  172. # javalib.jar
  173. cp $MY_ANDROID_DIR/$RENDERSCRIPT_V8_JAR renderscript/lib/javalib.jar
  174. fi
  175. # Copy header files for compilers
  176. cp $MY_ANDROID_DIR/external/clang/lib/Headers/*.h renderscript/clang-include
  177. cp $MY_ANDROID_DIR/frameworks/rs/script_api/include/* renderscript/include
  178. # Host-specific tools (bin/ and lib/)
  179. TOOLS_BIN="
  180. bcc_compat
  181. llvm-rs-cc
  182. "
  183. TOOLS_LIB="
  184. libbcc.$SONAME
  185. libbcinfo.$SONAME
  186. libclang_android.$SONAME
  187. libc++.$SONAME
  188. libLLVM_android.$SONAME
  189. "
  190. TOOLS_LIB32="libc++.$SONAME"
  191. for a in $TOOLS_BIN; do
  192. cp $ANDROID_HOST_OUT/bin/$a tools/$SHORT_OSNAME/bin
  193. strip tools/$SHORT_OSNAME/bin/$a
  194. done
  195. for a in $TOOLS_LIB; do
  196. cp $HOST_LIB64_DIR/$a tools/$SHORT_OSNAME/lib64
  197. strip tools/$SHORT_OSNAME/lib64/$a
  198. done
  199. for a in $TOOLS_LIB32; do
  200. cp $HOST_LIB_DIR/$a tools/$SHORT_OSNAME/lib
  201. strip tools/$SHORT_OSNAME/lib/$a
  202. done
  203. if [ $build_rs -eq 1 ]; then
  204. echo BUILDING RSTest_CompatLib with the new prebuilts
  205. echo "Using $NUM_CORES cores"
  206. source $MY_ANDROID_DIR/build/envsetup.sh
  207. for t in ${TARGETS[@]}; do
  208. build_rstest_compatlib aosp_${t}-userdebug
  209. done
  210. echo DONE BUILDING RSTest_CompatLib
  211. else
  212. echo SKIPPING BUILD OF RSTest_CompatLib
  213. fi
  214. if [ $DARWIN -eq 0 ]; then
  215. echo "DON'T FORGET TO UPDATE THE DARWIN COMPILER PREBUILTS!!!"
  216. fi