当前位置:   article > 正文

Android 编译脚本 envsetup.sh_warning: cannot display lunch menu.

warning: cannot display lunch menu.

版本: android-12.0.0_r3

目录: build/envsetup.sh

  1. function hmm() {
  2. cat <<EOF
  3. Run "m help" for help with the build system itself.
  4. 运行“m help”以获取有关构建系统本身的帮助
  5. Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
  6. 从您的 shell 中调用“.build/envsetup.sh”以将以下函数添加到您的环境中:
  7. - lunch: lunch <product_name>-<build_variant>
  8. 选择编译的目标
  9. Selects <product_name> as the product to build, and <build_variant> as the
  10. variant to build, and stores those selections in the environment to be read
  11. by subsequent invocations of 'm' etc.
  12. 选择 <product_name> 作为要构建的产品,选择 <build_variant> 作为要构建的变体构
  13. 建,并将这些选择存储在环境中以供后续读取调用 'm' 等。
  14. - tapas: tapas [<App1> <App2> ...] [arm|x86|arm64|x86_64] [eng|userdebug|user]
  15. Sets up the build environment for building unbundled apps (APKs).
  16. 设置用于构建非捆绑应用 (APK) 的构建环境
  17. - banchan: banchan <module1> [<module2> ...] [arm|x86|arm64|x86_64]
  18. [eng|userdebug|user]
  19. Sets up the build environment for building unbundled modules (APEXes).
  20. 设置用于构建非捆绑模块 (APEX) 的构建环境。
  21. - croot: Changes directory to the top of the tree, or a subdirectory thereof.
  22. 将目录更改为树的顶部或其子目录。
  23. 改变当前路径到Android源码的根目录
  24. - m: Makes from the top of the tree.
  25. 编译整个Android项目
  26. - mm: Builds and installs all of the modules in the current directory, and their
  27. dependencies.
  28. 生成并安装当前目录中的所有模块及其依赖项。
  29. 编译当前目录下所有的模块
  30. - mmm: Builds and installs all of the modules in the supplied directories, and
  31. their dependencies.
  32. 在提供的目录中构建并安装所有模块,以及他们的依赖关系
  33. 编译通过参数指定的模块,例如mmm dalvik/dexdump
  34. To limit the modules being built use the syntax: mmm dir/:target1,target2.
  35. 要限制正在构建的模块,请使用以下语法:mmm dir/:target1、target2
  36. - mma: Same as 'mm' 跟 mm 一样
  37. - mmma: Same as 'mmm' 跟 mmm 一样
  38. - provision: Flash device with all required partitions. Options will be passed on to
  39. fastboot.
  40. 具有所有必需分区的闪存设备。选项将传递给 fastboot。
  41. - cgrep: Greps on all local C/C++ files.
  42. 对所有本地 C/C++ 文件进行 Greps
  43. 查询当前目录及子目录下所有符合查询条件的C文件(*.c, *.cc, *.cpp, *.h)
  44. - ggrep: Greps on all local Gradle files.
  45. 对所有本地 Gradle 文件进行 Greps。
  46. - gogrep: Greps on all local Go files.
  47. 对所有本地 Go 文件进行 Greps。
  48. - jgrep: Greps on all local Java files.
  49. 对所有本地 Java 文件进行 Greps。
  50. 查询当前目录及子目录下所有符合查询条件的JAVA文件(*.java)
  51. - ktgrep: Greps on all local Kotlin files.
  52. 对所有本地 kotlin 文件进行 Greps。
  53. - resgrep: Greps on all local res/*.xml files.
  54. 对所有本地 res/*.xml 文件进行 Greps。
  55. 查询当前目录及子目录下所有资源相关的文件(*.xml)
  56. - mangrep: Greps on all local AndroidManifest.xml files.
  57. 对所有本地AndroidManifest.xml 文件进行 Greps。
  58. - mgrep: Greps on all local Makefiles and *.bp files.
  59. 对所有本地 Makefile 和 *.bp 文件进行 Greps。
  60. - owngrep: Greps on all local OWNERS files.
  61. 对所有本地 OWNERS 文件进行 Greps。
  62. - rsgrep: Greps on all local Rust files.
  63. 对所有本地 Rust 文件进行 Greps。
  64. - sepgrep: Greps on all local sepolicy files.
  65. 对所有本地 sepolicy 文件进行 Greps。
  66. - sgrep: Greps on all local source files.
  67. 对所有本地源文件进行 Greps。
  68. - godir: Go to the directory containing a file.
  69. 转到包含文件的目录。
  70. - allmod: List all modules.
  71. 列出所有模块
  72. - gomod: Go to the directory containing a module.
  73. 转到包含模块的目录。
  74. - pathmod: Get the directory containing a module.
  75. 获取包含模块的目录。
  76. - outmod: Gets the location of a module's installed outputs with a certain extension.
  77. 获取具有特定扩展名的模块已安装输出的位置。
  78. - dirmods: Gets the modules defined in a given directory.
  79. 获取给定目录中定义的模块。
  80. - installmod: Adb installs a module's built APK.
  81. Adb 安装模块的构建 APK。
  82. - refreshmod: Refresh list of modules for allmod/gomod/pathmod/outmod/installmod.
  83. 刷新 allmod/gomod/pathmod/outmod/installmod 的模块列表。
  84. - syswrite: Remount partitions (e.g. system.img) as writable, rebooting if necessary.
  85. 将分区(例如 system.img)重新挂载为可写,必要时重新启动。
  86. Environment options:
  87. 环境选项
  88. - SANITIZE_HOST: Set to 'address' to use ASAN for all host modules.
  89. SANITIZE_HOST:设置为“地址”以对所有主机模块使用 ASAN。
  90. - ANDROID_QUIET_BUILD: set to 'true' to display only the essential messages.
  91. ANDROID_QUIET_BUILD:设置为“true”以仅显示基本消息。
  92. Look at the source to view more functions. The complete list is:
  93. 查看源代码以查看更多功能。完整列表是
  94. EOF
  95. local T=$(gettop)
  96. local A=""
  97. local i
  98. for i in `cat $T/build/envsetup.sh | sed -n "/^[[:blank:]]*function /s/function \([a-z_]*\).*/\1/p" | sort | uniq`; do
  99. A="$A $i"
  100. done
  101. echo $A
  102. }
  103. # Get all the build variables needed by this script in a single call to the build system.
  104. # 在对构建系统的一次调用中获取此脚本所需的所有构建变量。
  105. function build_build_var_cache()
  106. {
  107. local T=$(gettop)
  108. # Grep out the variable names from the script.
  109. # 从脚本中找出变量名
  110. cached_vars=(`cat $T/build/envsetup.sh | tr '()' ' ' | awk '{for(i=1;i<=NF;i++) if($i~/get_build_var/) print $(i+1)}' | sort -u | tr '\n' ' '`)
  111. cached_abs_vars=(`cat $T/build/envsetup.sh | tr '()' ' ' | awk '{for(i=1;i<=NF;i++) if($i~/get_abs_build_var/) print $(i+1)}' | sort -u | tr '\n' ' '`)
  112. # Call the build system to dump the "<val>=<value>" pairs as a shell script.
  113. # 调用构建系统将“<val>=<value>”对转储为 shell 脚本。
  114. build_dicts_script=`\builtin cd $T; build/soong/soong_ui.bash --dumpvars-mode \
  115. --vars="${cached_vars[*]}" \
  116. --abs-vars="${cached_abs_vars[*]}" \
  117. --var-prefix=var_cache_ \
  118. --abs-var-prefix=abs_var_cache_`
  119. local ret=$?
  120. if [ $ret -ne 0 ]
  121. then
  122. unset build_dicts_script
  123. return $ret
  124. fi
  125. # Execute the script to store the "<val>=<value>" pairs as shell variables.
  126. # 执行脚本以将“<val>=<value>”对存储为 shell 变量。
  127. eval "$build_dicts_script"
  128. ret=$?
  129. unset build_dicts_script
  130. if [ $ret -ne 0 ]
  131. then
  132. return $ret
  133. fi
  134. BUILD_VAR_CACHE_READY="true"
  135. }
  136. # Delete the build var cache, so that we can still call into the build system
  137. # to get build variables not listed in this script.
  138. # 删除build var缓存,这样我们仍然可以调用build系统来获取这个脚本中没有列出的构建变量。
  139. function destroy_build_var_cache()
  140. {
  141. unset BUILD_VAR_CACHE_READY
  142. local v
  143. for v in $cached_vars; do
  144. unset var_cache_$v
  145. done
  146. unset cached_vars
  147. for v in $cached_abs_vars; do
  148. unset abs_var_cache_$v
  149. done
  150. unset cached_abs_vars
  151. }
  152. # Get the value of a build variable as an absolute path.
  153. # 获取构建变量的值作为绝对路径。
  154. function get_abs_build_var()
  155. {
  156. if [ "$BUILD_VAR_CACHE_READY" = "true" ]
  157. then
  158. eval "echo \"\${abs_var_cache_$1}\""
  159. return
  160. fi
  161. local T=$(gettop)
  162. if [ ! "$T" ]; then
  163. echo "Couldn't locate the top of the tree. Try setting TOP." >&2
  164. return
  165. fi
  166. (\cd $T; build/soong/soong_ui.bash --dumpvar-mode --abs $1)
  167. }
  168. # Get the exact value of a build variable.
  169. # 获取构建变量的确切值。
  170. function get_build_var()
  171. {
  172. if [ "$BUILD_VAR_CACHE_READY" = "true" ]
  173. then
  174. eval "echo \"\${var_cache_$1}\""
  175. return 0
  176. fi
  177. local T=$(gettop)
  178. if [ ! "$T" ]; then
  179. echo "Couldn't locate the top of the tree. Try setting TOP." >&2
  180. return 1
  181. fi
  182. (\cd $T; build/soong/soong_ui.bash --dumpvar-mode $1)
  183. }
  184. # check to see if the supplied product is one we can build
  185. # 检查提供的产品是否是我们可以build
  186. function check_product()
  187. {
  188. local T=$(gettop)
  189. if [ ! "$T" ]; then
  190. echo "Couldn't locate the top of the tree. Try setting TOP." >&2
  191. return
  192. fi
  193. TARGET_PRODUCT=$1 \
  194. TARGET_BUILD_VARIANT= \
  195. TARGET_BUILD_TYPE= \
  196. TARGET_BUILD_APPS= \
  197. get_build_var TARGET_DEVICE > /dev/null
  198. # hide successful answers, but allow the errors to show
  199. }
  200. VARIANT_CHOICES=(user userdebug eng)
  201. # check to see if the supplied variant is valid
  202. # 检查提供的变体是否有效
  203. function check_variant()
  204. {
  205. local v
  206. for v in ${VARIANT_CHOICES[@]}
  207. do
  208. if [ "$v" = "$1" ]
  209. then
  210. return 0
  211. fi
  212. done
  213. return 1
  214. }
  215. function setpaths()
  216. {
  217. local T=$(gettop)
  218. if [ ! "$T" ]; then
  219. echo "Couldn't locate the top of the tree. Try setting TOP."
  220. return
  221. fi
  222. ##################################################################
  223. # #
  224. # Read me before you modify this code #
  225. # #
  226. # This function sets ANDROID_BUILD_PATHS to what it is adding #
  227. # to PATH, and the next time it is run, it removes that from #
  228. # PATH. This is required so lunch can be run more than once #
  229. # and still have working paths. #
  230. # #
  231. ##################################################################
  232. # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
  233. # due to "C:\Program Files" being in the path.
  234. # out with the old
  235. if [ -n "$ANDROID_BUILD_PATHS" ] ; then
  236. export PATH=${PATH/$ANDROID_BUILD_PATHS/}
  237. fi
  238. if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
  239. export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
  240. # strip leading ':', if any
  241. export PATH=${PATH/:%/}
  242. fi
  243. # and in with the new
  244. local prebuiltdir=$(getprebuilt)
  245. local gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
  246. # defined in core/config.mk
  247. local targetgccversion=$(get_build_var TARGET_GCC_VERSION)
  248. local targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
  249. export TARGET_GCC_VERSION=$targetgccversion
  250. # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
  251. export ANDROID_TOOLCHAIN=
  252. export ANDROID_TOOLCHAIN_2ND_ARCH=
  253. local ARCH=$(get_build_var TARGET_ARCH)
  254. local toolchaindir toolchaindir2=
  255. case $ARCH in
  256. x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
  257. ;;
  258. x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
  259. ;;
  260. arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
  261. ;;
  262. arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
  263. toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
  264. ;;
  265. *)
  266. echo "Can't find toolchain for unknown architecture: $ARCH"
  267. toolchaindir=xxxxxxxxx
  268. ;;
  269. esac
  270. if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
  271. export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
  272. fi
  273. if [ "$toolchaindir2" -a -d "$gccprebuiltdir/$toolchaindir2" ]; then
  274. export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
  275. fi
  276. export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin
  277. # add kernel specific binaries
  278. case $(uname -s) in
  279. Linux)
  280. export ANDROID_DEV_SCRIPTS=$ANDROID_DEV_SCRIPTS:$T/prebuilts/misc/linux-x86/dtc:$T/prebuilts/misc/linux-x86/libufdt
  281. ;;
  282. *)
  283. ;;
  284. esac
  285. ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_TOOLCHAIN
  286. if [ -n "$ANDROID_TOOLCHAIN_2ND_ARCH" ]; then
  287. ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_TOOLCHAIN_2ND_ARCH
  288. fi
  289. ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_DEV_SCRIPTS
  290. # Append llvm binutils prebuilts path to ANDROID_BUILD_PATHS.
  291. local ANDROID_LLVM_BINUTILS=$(get_abs_build_var ANDROID_CLANG_PREBUILTS)/llvm-binutils-stable
  292. ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_LLVM_BINUTILS
  293. # Set up ASAN_SYMBOLIZER_PATH for SANITIZE_HOST=address builds.
  294. export ASAN_SYMBOLIZER_PATH=$ANDROID_LLVM_BINUTILS/llvm-symbolizer
  295. # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
  296. # to ensure that the corresponding 'emulator' binaries are used.
  297. case $(uname -s) in
  298. Darwin)
  299. ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
  300. ;;
  301. Linux)
  302. ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
  303. ;;
  304. *)
  305. ANDROID_EMULATOR_PREBUILTS=
  306. ;;
  307. esac
  308. if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
  309. ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_EMULATOR_PREBUILTS
  310. export ANDROID_EMULATOR_PREBUILTS
  311. fi
  312. # Append asuite prebuilts path to ANDROID_BUILD_PATHS.
  313. local os_arch=$(get_build_var HOST_PREBUILT_TAG)
  314. local ACLOUD_PATH="$T/prebuilts/asuite/acloud/$os_arch"
  315. local AIDEGEN_PATH="$T/prebuilts/asuite/aidegen/$os_arch"
  316. local ATEST_PATH="$T/prebuilts/asuite/atest/$os_arch"
  317. export ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ACLOUD_PATH:$AIDEGEN_PATH:$ATEST_PATH:
  318. export PATH=$ANDROID_BUILD_PATHS$PATH
  319. # out with the duplicate old
  320. if [ -n $ANDROID_PYTHONPATH ]; then
  321. export PYTHONPATH=${PYTHONPATH//$ANDROID_PYTHONPATH/}
  322. fi
  323. # and in with the new
  324. export ANDROID_PYTHONPATH=$T/development/python-packages:
  325. if [ -n $VENDOR_PYTHONPATH ]; then
  326. ANDROID_PYTHONPATH=$ANDROID_PYTHONPATH$VENDOR_PYTHONPATH
  327. fi
  328. export PYTHONPATH=$ANDROID_PYTHONPATH$PYTHONPATH
  329. export ANDROID_JAVA_HOME=$(get_abs_build_var ANDROID_JAVA_HOME)
  330. export JAVA_HOME=$ANDROID_JAVA_HOME
  331. export ANDROID_JAVA_TOOLCHAIN=$(get_abs_build_var ANDROID_JAVA_TOOLCHAIN)
  332. export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
  333. export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
  334. unset ANDROID_PRODUCT_OUT
  335. export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
  336. export OUT=$ANDROID_PRODUCT_OUT
  337. unset ANDROID_HOST_OUT
  338. export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
  339. unset ANDROID_SOONG_HOST_OUT
  340. export ANDROID_SOONG_HOST_OUT=$(get_abs_build_var SOONG_HOST_OUT)
  341. unset ANDROID_HOST_OUT_TESTCASES
  342. export ANDROID_HOST_OUT_TESTCASES=$(get_abs_build_var HOST_OUT_TESTCASES)
  343. unset ANDROID_TARGET_OUT_TESTCASES
  344. export ANDROID_TARGET_OUT_TESTCASES=$(get_abs_build_var TARGET_OUT_TESTCASES)
  345. # needed for building linux on MacOS
  346. # TODO: fix the path
  347. #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
  348. }
  349. function bazel()
  350. {
  351. local T="$(gettop)"
  352. if [ ! "$T" ]; then
  353. echo "Couldn't locate the top of the tree. Try setting TOP."
  354. return
  355. fi
  356. if which bazel &>/dev/null; then
  357. >&2 echo "NOTE: bazel() function sourced from envsetup.sh is being used instead of $(which bazel)"
  358. >&2 echo
  359. fi
  360. "$T/tools/bazel" "$@"
  361. }
  362. function printconfig()
  363. {
  364. local T=$(gettop)
  365. if [ ! "$T" ]; then
  366. echo "Couldn't locate the top of the tree. Try setting TOP." >&2
  367. return
  368. fi
  369. get_build_var report_config
  370. }
  371. function set_stuff_for_environment()
  372. {
  373. setpaths
  374. set_sequence_number
  375. export ANDROID_BUILD_TOP=$(gettop)
  376. # With this environment variable new GCC can apply colors to warnings/errors
  377. export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
  378. }
  379. function set_sequence_number()
  380. {
  381. export BUILD_ENV_SEQUENCE_NUMBER=13
  382. }
  383. # Takes a command name, and check if it's in ENVSETUP_NO_COMPLETION or not.
  384. function should_add_completion() {
  385. local cmd="$(basename $1| sed 's/_completion//' |sed 's/\.\(.*\)*sh$//')"
  386. case :"$ENVSETUP_NO_COMPLETION": in
  387. *:"$cmd":*)
  388. return 1
  389. ;;
  390. esac
  391. return 0
  392. }
  393. function addcompletions()
  394. {
  395. local f=
  396. # Keep us from trying to run in something that's neither bash nor zsh.
  397. if [ -z "$BASH_VERSION" -a -z "$ZSH_VERSION" ]; then
  398. return
  399. fi
  400. # Keep us from trying to run in bash that's too old.
  401. if [ -n "$BASH_VERSION" -a ${BASH_VERSINFO[0]} -lt 3 ]; then
  402. return
  403. fi
  404. local completion_files=(
  405. system/core/adb/adb.bash
  406. system/core/fastboot/fastboot.bash
  407. tools/asuite/asuite.sh
  408. )
  409. # Completion can be disabled selectively to allow users to use non-standard completion.
  410. # e.g.
  411. # ENVSETUP_NO_COMPLETION=adb # -> disable adb completion
  412. # ENVSETUP_NO_COMPLETION=adb:bit # -> disable adb and bit completion
  413. for f in ${completion_files[*]}; do
  414. if [ -f "$f" ] && should_add_completion "$f"; then
  415. . $f
  416. fi
  417. done
  418. if should_add_completion bit ; then
  419. complete -C "bit --tab" bit
  420. fi
  421. if [ -z "$ZSH_VERSION" ]; then
  422. # Doesn't work in zsh.
  423. complete -o nospace -F _croot croot
  424. fi
  425. complete -F _lunch lunch
  426. complete -F _complete_android_module_names pathmod
  427. complete -F _complete_android_module_names gomod
  428. complete -F _complete_android_module_names outmod
  429. complete -F _complete_android_module_names installmod
  430. complete -F _complete_android_module_names m
  431. }
  432. function choosetype()
  433. {
  434. echo "Build type choices are:"
  435. echo " 1. release"
  436. echo " 2. debug"
  437. echo
  438. local DEFAULT_NUM DEFAULT_VALUE
  439. DEFAULT_NUM=1
  440. DEFAULT_VALUE=release
  441. export TARGET_BUILD_TYPE=
  442. local ANSWER
  443. while [ -z $TARGET_BUILD_TYPE ]
  444. do
  445. echo -n "Which would you like? ["$DEFAULT_NUM"] "
  446. if [ -z "$1" ] ; then
  447. read ANSWER
  448. else
  449. echo $1
  450. ANSWER=$1
  451. fi
  452. case $ANSWER in
  453. "")
  454. export TARGET_BUILD_TYPE=$DEFAULT_VALUE
  455. ;;
  456. 1)
  457. export TARGET_BUILD_TYPE=release
  458. ;;
  459. release)
  460. export TARGET_BUILD_TYPE=release
  461. ;;
  462. 2)
  463. export TARGET_BUILD_TYPE=debug
  464. ;;
  465. debug)
  466. export TARGET_BUILD_TYPE=debug
  467. ;;
  468. *)
  469. echo
  470. echo "I didn't understand your response. Please try again."
  471. echo
  472. ;;
  473. esac
  474. if [ -n "$1" ] ; then
  475. break
  476. fi
  477. done
  478. build_build_var_cache
  479. set_stuff_for_environment
  480. destroy_build_var_cache
  481. }
  482. #
  483. # This function isn't really right: It chooses a TARGET_PRODUCT
  484. # based on the list of boards. Usually, that gets you something
  485. # that kinda works with a generic product, but really, you should
  486. # pick a product by name.
  487. #
  488. function chooseproduct()
  489. {
  490. local default_value
  491. if [ "x$TARGET_PRODUCT" != x ] ; then
  492. default_value=$TARGET_PRODUCT
  493. else
  494. default_value=aosp_arm
  495. fi
  496. export TARGET_BUILD_APPS=
  497. export TARGET_PRODUCT=
  498. local ANSWER
  499. while [ -z "$TARGET_PRODUCT" ]
  500. do
  501. echo -n "Which product would you like? [$default_value] "
  502. if [ -z "$1" ] ; then
  503. read ANSWER
  504. else
  505. echo $1
  506. ANSWER=$1
  507. fi
  508. if [ -z "$ANSWER" ] ; then
  509. export TARGET_PRODUCT=$default_value
  510. else
  511. if check_product $ANSWER
  512. then
  513. export TARGET_PRODUCT=$ANSWER
  514. else
  515. echo "** Not a valid product: $ANSWER"
  516. fi
  517. fi
  518. if [ -n "$1" ] ; then
  519. break
  520. fi
  521. done
  522. build_build_var_cache
  523. set_stuff_for_environment
  524. destroy_build_var_cache
  525. }
  526. function choosevariant()
  527. {
  528. echo "Variant choices are:"
  529. local index=1
  530. local v
  531. for v in ${VARIANT_CHOICES[@]}
  532. do
  533. # The product name is the name of the directory containing
  534. # the makefile we found, above.
  535. echo " $index. $v"
  536. index=$(($index+1))
  537. done
  538. local default_value=eng
  539. local ANSWER
  540. export TARGET_BUILD_VARIANT=
  541. while [ -z "$TARGET_BUILD_VARIANT" ]
  542. do
  543. echo -n "Which would you like? [$default_value] "
  544. if [ -z "$1" ] ; then
  545. read ANSWER
  546. else
  547. echo $1
  548. ANSWER=$1
  549. fi
  550. if [ -z "$ANSWER" ] ; then
  551. export TARGET_BUILD_VARIANT=$default_value
  552. elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
  553. if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
  554. export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[@]:$(($ANSWER-1)):1}
  555. fi
  556. else
  557. if check_variant $ANSWER
  558. then
  559. export TARGET_BUILD_VARIANT=$ANSWER
  560. else
  561. echo "** Not a valid variant: $ANSWER"
  562. fi
  563. fi
  564. if [ -n "$1" ] ; then
  565. break
  566. fi
  567. done
  568. }
  569. function choosecombo()
  570. {
  571. choosetype $1
  572. echo
  573. echo
  574. chooseproduct $2
  575. echo
  576. echo
  577. choosevariant $3
  578. echo
  579. build_build_var_cache
  580. set_stuff_for_environment
  581. printconfig
  582. destroy_build_var_cache
  583. }
  584. function add_lunch_combo()
  585. {
  586. if [ -n "$ZSH_VERSION" ]; then
  587. echo -n "${funcfiletrace[1]}: "
  588. else
  589. echo -n "${BASH_SOURCE[1]}:${BASH_LINENO[0]}: "
  590. fi
  591. echo "add_lunch_combo is obsolete. Use COMMON_LUNCH_CHOICES in your AndroidProducts.mk instead."
  592. }
  593. function print_lunch_menu()
  594. {
  595. local uname=$(uname)
  596. local choices
  597. choices=$(TARGET_BUILD_APPS= TARGET_PRODUCT= TARGET_BUILD_VARIANT= get_build_var COMMON_LUNCH_CHOICES 2>/dev/null)
  598. local ret=$?
  599. echo
  600. echo "You're building on" $uname
  601. echo
  602. if [ $ret -ne 0 ]
  603. then
  604. echo "Warning: Cannot display lunch menu."
  605. echo
  606. echo "Note: You can invoke lunch with an explicit target:"
  607. echo
  608. echo " usage: lunch [target]" >&2
  609. echo
  610. return
  611. fi
  612. echo "Lunch menu... pick a combo:"
  613. local i=1
  614. local choice
  615. for choice in $(echo $choices)
  616. do
  617. echo " $i. $choice"
  618. i=$(($i+1))
  619. done
  620. echo
  621. }
  622. function lunch()
  623. {
  624. local answer
  625. if [[ $# -gt 1 ]]; then
  626. echo "usage: lunch [target]" >&2
  627. return 1
  628. fi
  629. if [ "$1" ]; then
  630. answer=$1
  631. else
  632. print_lunch_menu
  633. echo -n "Which would you like? [aosp_arm-eng] "
  634. read answer
  635. fi
  636. local selection=
  637. if [ -z "$answer" ]
  638. then
  639. selection=aosp_arm-eng
  640. elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
  641. then
  642. local choices=($(TARGET_BUILD_APPS= get_build_var COMMON_LUNCH_CHOICES))
  643. if [ $answer -le ${#choices[@]} ]
  644. then
  645. # array in zsh starts from 1 instead of 0.
  646. if [ -n "$ZSH_VERSION" ]
  647. then
  648. selection=${choices[$(($answer))]}
  649. else
  650. selection=${choices[$(($answer-1))]}
  651. fi
  652. fi
  653. else
  654. selection=$answer
  655. fi
  656. export TARGET_BUILD_APPS=
  657. local product variant_and_version variant version
  658. product=${selection%%-*} # Trim everything after first dash
  659. variant_and_version=${selection#*-} # Trim everything up to first dash
  660. if [ "$variant_and_version" != "$selection" ]; then
  661. variant=${variant_and_version%%-*}
  662. if [ "$variant" != "$variant_and_version" ]; then
  663. version=${variant_and_version#*-}
  664. fi
  665. fi
  666. if [ -z "$product" ]
  667. then
  668. echo
  669. echo "Invalid lunch combo: $selection"
  670. return 1
  671. fi
  672. TARGET_PRODUCT=$product \
  673. TARGET_BUILD_VARIANT=$variant \
  674. TARGET_PLATFORM_VERSION=$version \
  675. build_build_var_cache
  676. if [ $? -ne 0 ]
  677. then
  678. return 1
  679. fi
  680. export TARGET_PRODUCT=$(get_build_var TARGET_PRODUCT)
  681. export TARGET_BUILD_VARIANT=$(get_build_var TARGET_BUILD_VARIANT)
  682. if [ -n "$version" ]; then
  683. export TARGET_PLATFORM_VERSION=$(get_build_var TARGET_PLATFORM_VERSION)
  684. else
  685. unset TARGET_PLATFORM_VERSION
  686. fi
  687. export TARGET_BUILD_TYPE=release
  688. [[ -n "${ANDROID_QUIET_BUILD:-}" ]] || echo
  689. set_stuff_for_environment
  690. [[ -n "${ANDROID_QUIET_BUILD:-}" ]] || printconfig
  691. destroy_build_var_cache
  692. }
  693. unset COMMON_LUNCH_CHOICES_CACHE
  694. # Tab completion for lunch.
  695. function _lunch()
  696. {
  697. local cur prev opts
  698. COMPREPLY=()
  699. cur="${COMP_WORDS[COMP_CWORD]}"
  700. prev="${COMP_WORDS[COMP_CWORD-1]}"
  701. if [ -z "$COMMON_LUNCH_CHOICES_CACHE" ]; then
  702. COMMON_LUNCH_CHOICES_CACHE=$(TARGET_BUILD_APPS= get_build_var COMMON_LUNCH_CHOICES)
  703. fi
  704. COMPREPLY=( $(compgen -W "${COMMON_LUNCH_CHOICES_CACHE}" -- ${cur}) )
  705. return 0
  706. }
  707. # Configures the build to build unbundled apps.
  708. # Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
  709. function tapas()
  710. {
  711. local showHelp="$(echo $* | xargs -n 1 echo | \grep -E '^(help)$' | xargs)"
  712. local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|arm64|x86_64)$' | xargs)"
  713. local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
  714. local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
  715. local apps="$(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|arm64|x86_64|ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
  716. if [ "$showHelp" != "" ]; then
  717. $(gettop)/build/make/tapasHelp.sh
  718. return
  719. fi
  720. if [ $(echo $arch | wc -w) -gt 1 ]; then
  721. echo "tapas: Error: Multiple build archs supplied: $arch"
  722. return
  723. fi
  724. if [ $(echo $variant | wc -w) -gt 1 ]; then
  725. echo "tapas: Error: Multiple build variants supplied: $variant"
  726. return
  727. fi
  728. if [ $(echo $density | wc -w) -gt 1 ]; then
  729. echo "tapas: Error: Multiple densities supplied: $density"
  730. return
  731. fi
  732. local product=aosp_arm
  733. case $arch in
  734. x86) product=aosp_x86;;
  735. arm64) product=aosp_arm64;;
  736. x86_64) product=aosp_x86_64;;
  737. esac
  738. if [ -z "$variant" ]; then
  739. variant=eng
  740. fi
  741. if [ -z "$apps" ]; then
  742. apps=all
  743. fi
  744. if [ -z "$density" ]; then
  745. density=alldpi
  746. fi
  747. export TARGET_PRODUCT=$product
  748. export TARGET_BUILD_VARIANT=$variant
  749. export TARGET_BUILD_DENSITY=$density
  750. export TARGET_BUILD_TYPE=release
  751. export TARGET_BUILD_APPS=$apps
  752. build_build_var_cache
  753. set_stuff_for_environment
  754. printconfig
  755. destroy_build_var_cache
  756. }
  757. # Configures the build to build unbundled Android modules (APEXes).
  758. # Run banchan with one or more module names (from apex{} modules).
  759. function banchan()
  760. {
  761. local showHelp="$(echo $* | xargs -n 1 echo | \grep -E '^(help)$' | xargs)"
  762. local product="$(echo $* | xargs -n 1 echo | \grep -E '^(.*_)?(arm|x86|arm64|x86_64)$' | xargs)"
  763. local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
  764. local apps="$(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|(.*_)?(arm|x86|arm64|x86_64))$' | xargs)"
  765. if [ "$showHelp" != "" ]; then
  766. $(gettop)/build/make/banchanHelp.sh
  767. return
  768. fi
  769. if [ -z "$product" ]; then
  770. product=arm
  771. elif [ $(echo $product | wc -w) -gt 1 ]; then
  772. echo "banchan: Error: Multiple build archs or products supplied: $products"
  773. return
  774. fi
  775. if [ $(echo $variant | wc -w) -gt 1 ]; then
  776. echo "banchan: Error: Multiple build variants supplied: $variant"
  777. return
  778. fi
  779. if [ -z "$apps" ]; then
  780. echo "banchan: Error: No modules supplied"
  781. return
  782. fi
  783. case $product in
  784. arm) product=module_arm;;
  785. x86) product=module_x86;;
  786. arm64) product=module_arm64;;
  787. x86_64) product=module_x86_64;;
  788. esac
  789. if [ -z "$variant" ]; then
  790. variant=eng
  791. fi
  792. export TARGET_PRODUCT=$product
  793. export TARGET_BUILD_VARIANT=$variant
  794. export TARGET_BUILD_DENSITY=alldpi
  795. export TARGET_BUILD_TYPE=release
  796. # This setup currently uses TARGET_BUILD_APPS just like tapas, but the use
  797. # case is different and it may diverge in the future.
  798. export TARGET_BUILD_APPS=$apps
  799. build_build_var_cache
  800. set_stuff_for_environment
  801. printconfig
  802. destroy_build_var_cache
  803. }
  804. function gettop
  805. {
  806. local TOPFILE=build/make/core/envsetup.mk
  807. if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
  808. # The following circumlocution ensures we remove symlinks from TOP.
  809. (cd "$TOP"; PWD= /bin/pwd)
  810. else
  811. if [ -f $TOPFILE ] ; then
  812. # The following circumlocution (repeated below as well) ensures
  813. # that we record the true directory name and not one that is
  814. # faked up with symlink names.
  815. PWD= /bin/pwd
  816. else
  817. local HERE=$PWD
  818. local T=
  819. while [ \( ! \( -f $TOPFILE \) \) -a \( "$PWD" != "/" \) ]; do
  820. \cd ..
  821. T=`PWD= /bin/pwd -P`
  822. done
  823. \cd "$HERE"
  824. if [ -f "$T/$TOPFILE" ]; then
  825. echo "$T"
  826. fi
  827. fi
  828. fi
  829. }
  830. function croot()
  831. {
  832. local T=$(gettop)
  833. if [ "$T" ]; then
  834. if [ "$1" ]; then
  835. \cd $(gettop)/$1
  836. else
  837. \cd $(gettop)
  838. fi
  839. else
  840. echo "Couldn't locate the top of the tree. Try setting TOP."
  841. fi
  842. }
  843. function _croot()
  844. {
  845. local T=$(gettop)
  846. if [ "$T" ]; then
  847. local cur="${COMP_WORDS[COMP_CWORD]}"
  848. k=0
  849. for c in $(compgen -d ${T}/${cur}); do
  850. COMPREPLY[k++]=${c#${T}/}/
  851. done
  852. fi
  853. }
  854. function cproj()
  855. {
  856. local TOPFILE=build/make/core/envsetup.mk
  857. local HERE=$PWD
  858. local T=
  859. while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
  860. T=$PWD
  861. if [ -f "$T/Android.mk" ]; then
  862. \cd $T
  863. return
  864. fi
  865. \cd ..
  866. done
  867. \cd $HERE
  868. echo "can't find Android.mk"
  869. }
  870. # simplified version of ps; output in the form
  871. # <pid> <procname>
  872. function qpid() {
  873. local prepend=''
  874. local append=''
  875. if [ "$1" = "--exact" ]; then
  876. prepend=' '
  877. append='$'
  878. shift
  879. elif [ "$1" = "--help" -o "$1" = "-h" ]; then
  880. echo "usage: qpid [[--exact] <process name|pid>"
  881. return 255
  882. fi
  883. local EXE="$1"
  884. if [ "$EXE" ] ; then
  885. qpid | \grep "$prepend$EXE$append"
  886. else
  887. adb shell ps \
  888. | tr -d '\r' \
  889. | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
  890. fi
  891. }
  892. # syswrite - disable verity, reboot if needed, and remount image
  893. #
  894. # Easy way to make system.img/etc writable
  895. function syswrite() {
  896. adb wait-for-device && adb root || return 1
  897. if [[ $(adb disable-verity | grep "reboot") ]]; then
  898. echo "rebooting"
  899. adb reboot && adb wait-for-device && adb root || return 1
  900. fi
  901. adb wait-for-device && adb remount || return 1
  902. }
  903. # coredump_setup - enable core dumps globally for any process
  904. # that has the core-file-size limit set correctly
  905. #
  906. # NOTE: You must call also coredump_enable for a specific process
  907. # if its core-file-size limit is not set already.
  908. # NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
  909. function coredump_setup()
  910. {
  911. echo "Getting root...";
  912. adb root;
  913. adb wait-for-device;
  914. echo "Remounting root partition read-write...";
  915. adb shell mount -w -o remount -t rootfs rootfs;
  916. sleep 1;
  917. adb wait-for-device;
  918. adb shell mkdir -p /cores;
  919. adb shell mount -t tmpfs tmpfs /cores;
  920. adb shell chmod 0777 /cores;
  921. echo "Granting SELinux permission to dump in /cores...";
  922. adb shell restorecon -R /cores;
  923. echo "Set core pattern.";
  924. adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
  925. echo "Done."
  926. }
  927. # coredump_enable - enable core dumps for the specified process
  928. # $1 = PID of process (e.g., $(pid mediaserver))
  929. #
  930. # NOTE: coredump_setup must have been called as well for a core
  931. # dump to actually be generated.
  932. function coredump_enable()
  933. {
  934. local PID=$1;
  935. if [ -z "$PID" ]; then
  936. printf "Expecting a PID!\n";
  937. return;
  938. fi;
  939. echo "Setting core limit for $PID to infinite...";
  940. adb shell /system/bin/ulimit -p $PID -c unlimited
  941. }
  942. # core - send SIGV and pull the core for process
  943. # $1 = PID of process (e.g., $(pid mediaserver))
  944. #
  945. # NOTE: coredump_setup must be called once per boot for core dumps to be
  946. # enabled globally.
  947. function core()
  948. {
  949. local PID=$1;
  950. if [ -z "$PID" ]; then
  951. printf "Expecting a PID!\n";
  952. return;
  953. fi;
  954. local CORENAME=core.$PID;
  955. local COREPATH=/cores/$CORENAME;
  956. local SIG=SEGV;
  957. coredump_enable $1;
  958. local done=0;
  959. while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
  960. printf "\tSending SIG%s to %d...\n" $SIG $PID;
  961. adb shell kill -$SIG $PID;
  962. sleep 1;
  963. done;
  964. adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
  965. echo "Done: core is under $COREPATH on device.";
  966. }
  967. # systemstack - dump the current stack trace of all threads in the system process
  968. # to the usual ANR traces file
  969. function systemstack()
  970. {
  971. stacks system_server
  972. }
  973. # Read the ELF header from /proc/$PID/exe to determine if the process is
  974. # 64-bit.
  975. function is64bit()
  976. {
  977. local PID="$1"
  978. if [ "$PID" ] ; then
  979. if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -p)" -eq "02" ]] ; then
  980. echo "64"
  981. else
  982. echo ""
  983. fi
  984. else
  985. echo ""
  986. fi
  987. }
  988. case `uname -s` in
  989. Darwin)
  990. function sgrep()
  991. {
  992. find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cc|cpp|hpp|S|java|kt|xml|sh|mk|aidl|vts|proto)' \
  993. -exec grep --color -n "$@" {} +
  994. }
  995. ;;
  996. *)
  997. function sgrep()
  998. {
  999. find . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.\(c\|h\|cc\|cpp\|hpp\|S\|java\|kt\|xml\|sh\|mk\|aidl\|vts\|proto\)' \
  1000. -exec grep --color -n "$@" {} +
  1001. }
  1002. ;;
  1003. esac
  1004. function gettargetarch
  1005. {
  1006. get_build_var TARGET_ARCH
  1007. }
  1008. function ggrep()
  1009. {
  1010. find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" \
  1011. -exec grep --color -n "$@" {} +
  1012. }
  1013. function gogrep()
  1014. {
  1015. find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.go" \
  1016. -exec grep --color -n "$@" {} +
  1017. }
  1018. function jgrep()
  1019. {
  1020. find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" \
  1021. -exec grep --color -n "$@" {} +
  1022. }
  1023. function rsgrep()
  1024. {
  1025. find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rs" \
  1026. -exec grep --color -n "$@" {} +
  1027. }
  1028. function ktgrep()
  1029. {
  1030. find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.kt" \
  1031. -exec grep --color -n "$@" {} +
  1032. }
  1033. function cgrep()
  1034. {
  1035. find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' -o -name '*.hpp' \) \
  1036. -exec grep --color -n "$@" {} +
  1037. }
  1038. function resgrep()
  1039. {
  1040. local dir
  1041. for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do
  1042. find $dir -type f -name '*\.xml' -exec grep --color -n "$@" {} +
  1043. done
  1044. }
  1045. function mangrep()
  1046. {
  1047. find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' \
  1048. -exec grep --color -n "$@" {} +
  1049. }
  1050. function owngrep()
  1051. {
  1052. find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'OWNERS' \
  1053. -exec grep --color -n "$@" {} +
  1054. }
  1055. function sepgrep()
  1056. {
  1057. find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d \
  1058. -exec grep --color -n -r --exclude-dir=\.git "$@" {} +
  1059. }
  1060. function rcgrep()
  1061. {
  1062. find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" \
  1063. -exec grep --color -n "$@" {} +
  1064. }
  1065. case `uname -s` in
  1066. Darwin)
  1067. function mgrep()
  1068. {
  1069. find -E . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o \( -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk|.*\.bp)' -o -regex '(.*/)?(build|soong)/.*[^/]*\.go' \) -type f \
  1070. -exec grep --color -n "$@" {} +
  1071. }
  1072. function treegrep()
  1073. {
  1074. find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cpp|hpp|S|java|kt|xml)' \
  1075. -exec grep --color -n -i "$@" {} +
  1076. }
  1077. ;;
  1078. *)
  1079. function mgrep()
  1080. {
  1081. find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o \( -regextype posix-egrep -iregex '(.*\/Makefile|.*\/Makefile\..*|.*\.make|.*\.mak|.*\.mk|.*\.bp)' -o -regextype posix-extended -regex '(.*/)?(build|soong)/.*[^/]*\.go' \) -type f \
  1082. -exec grep --color -n "$@" {} +
  1083. }
  1084. function treegrep()
  1085. {
  1086. find . -name .repo -prune -o -name .git -prune -o -regextype posix-egrep -iregex '.*\.(c|h|cpp|hpp|S|java|kt|xml)' -type f \
  1087. -exec grep --color -n -i "$@" {} +
  1088. }
  1089. ;;
  1090. esac
  1091. function getprebuilt
  1092. {
  1093. get_abs_build_var ANDROID_PREBUILTS
  1094. }
  1095. function tracedmdump()
  1096. {
  1097. local T=$(gettop)
  1098. if [ ! "$T" ]; then
  1099. echo "Couldn't locate the top of the tree. Try setting TOP."
  1100. return
  1101. fi
  1102. local prebuiltdir=$(getprebuilt)
  1103. local arch=$(gettargetarch)
  1104. local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
  1105. local TRACE=$1
  1106. if [ ! "$TRACE" ] ; then
  1107. echo "usage: tracedmdump tracename"
  1108. return
  1109. fi
  1110. if [ ! -r "$KERNEL" ] ; then
  1111. echo "Error: cannot find kernel: '$KERNEL'"
  1112. return
  1113. fi
  1114. local BASETRACE=$(basename $TRACE)
  1115. if [ "$BASETRACE" = "$TRACE" ] ; then
  1116. TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
  1117. fi
  1118. echo "post-processing traces..."
  1119. rm -f $TRACE/qtrace.dexlist
  1120. post_trace $TRACE
  1121. if [ $? -ne 0 ]; then
  1122. echo "***"
  1123. echo "*** Error: malformed trace. Did you remember to exit the emulator?"
  1124. echo "***"
  1125. return
  1126. fi
  1127. echo "generating dexlist output..."
  1128. /bin/ls $ANDROID_PRODUCT_OUT/system/framework/*.jar $ANDROID_PRODUCT_OUT/system/app/*.apk $ANDROID_PRODUCT_OUT/data/app/*.apk 2>/dev/null | xargs dexlist > $TRACE/qtrace.dexlist
  1129. echo "generating dmtrace data..."
  1130. q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
  1131. echo "generating html file..."
  1132. dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
  1133. echo "done, see $TRACE/dmtrace.html for details"
  1134. echo "or run:"
  1135. echo " traceview $TRACE/dmtrace"
  1136. }
  1137. # communicate with a running device or emulator, set up necessary state,
  1138. # and run the hat command.
  1139. function runhat()
  1140. {
  1141. # process standard adb options
  1142. local adbTarget=""
  1143. if [ "$1" = "-d" -o "$1" = "-e" ]; then
  1144. adbTarget=$1
  1145. shift 1
  1146. elif [ "$1" = "-s" ]; then
  1147. adbTarget="$1 $2"
  1148. shift 2
  1149. fi
  1150. local adbOptions=${adbTarget}
  1151. #echo adbOptions = ${adbOptions}
  1152. # runhat options
  1153. local targetPid=$1
  1154. if [ "$targetPid" = "" ]; then
  1155. echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
  1156. return
  1157. fi
  1158. # confirm hat is available
  1159. if [ -z $(which hat) ]; then
  1160. echo "hat is not available in this configuration."
  1161. return
  1162. fi
  1163. # issue "am" command to cause the hprof dump
  1164. local devFile=/data/local/tmp/hprof-$targetPid
  1165. echo "Poking $targetPid and waiting for data..."
  1166. echo "Storing data at $devFile"
  1167. adb ${adbOptions} shell am dumpheap $targetPid $devFile
  1168. echo "Press enter when logcat shows \"hprof: heap dump completed\""
  1169. echo -n "> "
  1170. read
  1171. local localFile=/tmp/$$-hprof
  1172. echo "Retrieving file $devFile..."
  1173. adb ${adbOptions} pull $devFile $localFile
  1174. adb ${adbOptions} shell rm $devFile
  1175. echo "Running hat on $localFile"
  1176. echo "View the output by pointing your browser at http://localhost:7000/"
  1177. echo ""
  1178. hat -JXmx512m $localFile
  1179. }
  1180. function getbugreports()
  1181. {
  1182. local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
  1183. if [ ! "$reports" ]; then
  1184. echo "Could not locate any bugreports."
  1185. return
  1186. fi
  1187. local report
  1188. for report in ${reports[@]}
  1189. do
  1190. echo "/sdcard/bugreports/${report}"
  1191. adb pull /sdcard/bugreports/${report} ${report}
  1192. gunzip ${report}
  1193. done
  1194. }
  1195. function getsdcardpath()
  1196. {
  1197. adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
  1198. }
  1199. function getscreenshotpath()
  1200. {
  1201. echo "$(getsdcardpath)/Pictures/Screenshots"
  1202. }
  1203. function getlastscreenshot()
  1204. {
  1205. local screenshot_path=$(getscreenshotpath)
  1206. local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
  1207. if [ "$screenshot" = "" ]; then
  1208. echo "No screenshots found."
  1209. return
  1210. fi
  1211. echo "${screenshot}"
  1212. adb ${adbOptions} pull ${screenshot_path}/${screenshot}
  1213. }
  1214. function startviewserver()
  1215. {
  1216. local port=4939
  1217. if [ $# -gt 0 ]; then
  1218. port=$1
  1219. fi
  1220. adb shell service call window 1 i32 $port
  1221. }
  1222. function stopviewserver()
  1223. {
  1224. adb shell service call window 2
  1225. }
  1226. function isviewserverstarted()
  1227. {
  1228. adb shell service call window 3
  1229. }
  1230. function key_home()
  1231. {
  1232. adb shell input keyevent 3
  1233. }
  1234. function key_back()
  1235. {
  1236. adb shell input keyevent 4
  1237. }
  1238. function key_menu()
  1239. {
  1240. adb shell input keyevent 82
  1241. }
  1242. function smoketest()
  1243. {
  1244. if [ ! "$ANDROID_PRODUCT_OUT" ]; then
  1245. echo "Couldn't locate output files. Try running 'lunch' first." >&2
  1246. return
  1247. fi
  1248. local T=$(gettop)
  1249. if [ ! "$T" ]; then
  1250. echo "Couldn't locate the top of the tree. Try setting TOP." >&2
  1251. return
  1252. fi
  1253. (\cd "$T" && mmm tests/SmokeTest) &&
  1254. adb uninstall com.android.smoketest > /dev/null &&
  1255. adb uninstall com.android.smoketest.tests > /dev/null &&
  1256. adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
  1257. adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
  1258. adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
  1259. }
  1260. # simple shortcut to the runtest command
  1261. function runtest()
  1262. {
  1263. local T=$(gettop)
  1264. if [ ! "$T" ]; then
  1265. echo "Couldn't locate the top of the tree. Try setting TOP." >&2
  1266. return
  1267. fi
  1268. ("$T"/development/testrunner/runtest.py $@)
  1269. }
  1270. function godir () {
  1271. if [[ -z "$1" ]]; then
  1272. echo "Usage: godir <regex>"
  1273. return
  1274. fi
  1275. local T=$(gettop)
  1276. local FILELIST
  1277. if [ ! "$OUT_DIR" = "" ]; then
  1278. mkdir -p $OUT_DIR
  1279. FILELIST=$OUT_DIR/filelist
  1280. else
  1281. FILELIST=$T/filelist
  1282. fi
  1283. if [[ ! -f $FILELIST ]]; then
  1284. echo -n "Creating index..."
  1285. (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > $FILELIST)
  1286. echo " Done"
  1287. echo ""
  1288. fi
  1289. local lines
  1290. lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq))
  1291. if [[ ${#lines[@]} = 0 ]]; then
  1292. echo "Not found"
  1293. return
  1294. fi
  1295. local pathname
  1296. local choice
  1297. if [[ ${#lines[@]} > 1 ]]; then
  1298. while [[ -z "$pathname" ]]; do
  1299. local index=1
  1300. local line
  1301. for line in ${lines[@]}; do
  1302. printf "%6s %s\n" "[$index]" $line
  1303. index=$(($index + 1))
  1304. done
  1305. echo
  1306. echo -n "Select one: "
  1307. unset choice
  1308. read choice
  1309. if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
  1310. echo "Invalid choice"
  1311. continue
  1312. fi
  1313. pathname=${lines[@]:$(($choice-1)):1}
  1314. done
  1315. else
  1316. pathname=${lines[@]:0:1}
  1317. fi
  1318. \cd $T/$pathname
  1319. }
  1320. # Update module-info.json in out.
  1321. function refreshmod() {
  1322. if [ ! "$ANDROID_PRODUCT_OUT" ]; then
  1323. echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
  1324. return 1
  1325. fi
  1326. echo "Refreshing modules (building module-info.json). Log at $ANDROID_PRODUCT_OUT/module-info.json.build.log." >&2
  1327. # for the output of the next command
  1328. mkdir -p $ANDROID_PRODUCT_OUT || return 1
  1329. # Note, can't use absolute path because of the way make works.
  1330. m $(get_build_var PRODUCT_OUT)/module-info.json \
  1331. > $ANDROID_PRODUCT_OUT/module-info.json.build.log 2>&1
  1332. }
  1333. # Verifies that module-info.txt exists, creating it if it doesn't.
  1334. function verifymodinfo() {
  1335. if [ ! "$ANDROID_PRODUCT_OUT" ]; then
  1336. if [ "$QUIET_VERIFYMODINFO" != "true" ] ; then
  1337. echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
  1338. fi
  1339. return 1
  1340. fi
  1341. if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then
  1342. if [ "$QUIET_VERIFYMODINFO" != "true" ] ; then
  1343. echo "Could not find module-info.json. It will only be built once, and it can be updated with 'refreshmod'" >&2
  1344. fi
  1345. return 1
  1346. fi
  1347. }
  1348. # List all modules for the current device, as cached in module-info.json. If any build change is
  1349. # made and it should be reflected in the output, you should run 'refreshmod' first.
  1350. function allmod() {
  1351. verifymodinfo || return 1
  1352. python3 -c "import json; print('\n'.join(sorted(json.load(open('$ANDROID_PRODUCT_OUT/module-info.json')).keys())))"
  1353. }
  1354. # Get the path of a specific module in the android tree, as cached in module-info.json.
  1355. # If any build change is made, and it should be reflected in the output, you should run
  1356. # 'refreshmod' first. Note: This is the inverse of dirmods.
  1357. function pathmod() {
  1358. if [[ $# -ne 1 ]]; then
  1359. echo "usage: pathmod <module>" >&2
  1360. return 1
  1361. fi
  1362. verifymodinfo || return 1
  1363. local relpath=$(python3 -c "import json, os
  1364. module = '$1'
  1365. module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
  1366. if module not in module_info:
  1367. exit(1)
  1368. print(module_info[module]['path'][0])" 2>/dev/null)
  1369. if [ -z "$relpath" ]; then
  1370. echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)." >&2
  1371. return 1
  1372. else
  1373. echo "$ANDROID_BUILD_TOP/$relpath"
  1374. fi
  1375. }
  1376. # Get the path of a specific module in the android tree, as cached in module-info.json.
  1377. # If any build change is made, and it should be reflected in the output, you should run
  1378. # 'refreshmod' first. Note: This is the inverse of pathmod.
  1379. function dirmods() {
  1380. if [[ $# -ne 1 ]]; then
  1381. echo "usage: dirmods <path>" >&2
  1382. return 1
  1383. fi
  1384. verifymodinfo || return 1
  1385. python3 -c "import json, os
  1386. dir = '$1'
  1387. while dir.endswith('/'):
  1388. dir = dir[:-1]
  1389. prefix = dir + '/'
  1390. module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
  1391. results = set()
  1392. for m in module_info.values():
  1393. for path in m.get(u'path', []):
  1394. if path == dir or path.startswith(prefix):
  1395. name = m.get(u'module_name')
  1396. if name:
  1397. results.add(name)
  1398. for name in sorted(results):
  1399. print(name)
  1400. "
  1401. }
  1402. # Go to a specific module in the android tree, as cached in module-info.json. If any build change
  1403. # is made, and it should be reflected in the output, you should run 'refreshmod' first.
  1404. function gomod() {
  1405. if [[ $# -ne 1 ]]; then
  1406. echo "usage: gomod <module>" >&2
  1407. return 1
  1408. fi
  1409. local path="$(pathmod $@)"
  1410. if [ -z "$path" ]; then
  1411. return 1
  1412. fi
  1413. cd $path
  1414. }
  1415. # Gets the list of a module's installed outputs, as cached in module-info.json.
  1416. # If any build change is made, and it should be reflected in the output, you should run 'refreshmod' first.
  1417. function outmod() {
  1418. if [[ $# -ne 1 ]]; then
  1419. echo "usage: outmod <module>" >&2
  1420. return 1
  1421. fi
  1422. verifymodinfo || return 1
  1423. local relpath
  1424. relpath=$(python3 -c "import json, os
  1425. module = '$1'
  1426. module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
  1427. if module not in module_info:
  1428. exit(1)
  1429. for output in module_info[module]['installed']:
  1430. print(os.path.join('$ANDROID_BUILD_TOP', output))" 2>/dev/null)
  1431. if [ $? -ne 0 ]; then
  1432. echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)" >&2
  1433. return 1
  1434. elif [ ! -z "$relpath" ]; then
  1435. echo "$relpath"
  1436. fi
  1437. }
  1438. # adb install a module's apk, as cached in module-info.json. If any build change
  1439. # is made, and it should be reflected in the output, you should run 'refreshmod' first.
  1440. # Usage: installmod [adb install arguments] <module>
  1441. # For example: installmod -r Dialer -> adb install -r /path/to/Dialer.apk
  1442. function installmod() {
  1443. if [[ $# -eq 0 ]]; then
  1444. echo "usage: installmod [adb install arguments] <module>" >&2
  1445. return 1
  1446. fi
  1447. local _path
  1448. _path=$(outmod ${@:$#:1})
  1449. if [ $? -ne 0 ]; then
  1450. return 1
  1451. fi
  1452. _path=$(echo "$_path" | grep -E \\.apk$ | head -n 1)
  1453. if [ -z "$_path" ]; then
  1454. echo "Module '$1' does not produce a file ending with .apk (try 'refreshmod' if there have been build changes?)" >&2
  1455. return 1
  1456. fi
  1457. local length=$(( $# - 1 ))
  1458. echo adb install ${@:1:$length} $_path
  1459. adb install ${@:1:$length} $_path
  1460. }
  1461. function _complete_android_module_names() {
  1462. local word=${COMP_WORDS[COMP_CWORD]}
  1463. COMPREPLY=( $(QUIET_VERIFYMODINFO=true allmod | grep -E "^$word") )
  1464. }
  1465. # Print colored exit condition
  1466. function pez {
  1467. "$@"
  1468. local retval=$?
  1469. if [ $retval -ne 0 ]
  1470. then
  1471. echo $'\E'"[0;31mFAILURE\e[00m"
  1472. else
  1473. echo $'\E'"[0;32mSUCCESS\e[00m"
  1474. fi
  1475. return $retval
  1476. }
  1477. function get_make_command()
  1478. {
  1479. # If we're in the top of an Android tree, use soong_ui.bash instead of make
  1480. if [ -f build/soong/soong_ui.bash ]; then
  1481. # Always use the real make if -C is passed in
  1482. for arg in "$@"; do
  1483. if [[ $arg == -C* ]]; then
  1484. echo command make
  1485. return
  1486. fi
  1487. done
  1488. echo build/soong/soong_ui.bash --make-mode
  1489. else
  1490. echo command make
  1491. fi
  1492. }
  1493. function _wrap_build()
  1494. {
  1495. if [[ "${ANDROID_QUIET_BUILD:-}" == true ]]; then
  1496. "$@"
  1497. return $?
  1498. fi
  1499. local start_time=$(date +"%s")
  1500. "$@"
  1501. local ret=$?
  1502. local end_time=$(date +"%s")
  1503. local tdiff=$(($end_time-$start_time))
  1504. local hours=$(($tdiff / 3600 ))
  1505. local mins=$((($tdiff % 3600) / 60))
  1506. local secs=$(($tdiff % 60))
  1507. local ncolors=$(tput colors 2>/dev/null)
  1508. if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
  1509. color_failed=$'\E'"[0;31m"
  1510. color_success=$'\E'"[0;32m"
  1511. color_reset=$'\E'"[00m"
  1512. else
  1513. color_failed=""
  1514. color_success=""
  1515. color_reset=""
  1516. fi
  1517. echo
  1518. if [ $ret -eq 0 ] ; then
  1519. echo -n "${color_success}#### build completed successfully "
  1520. else
  1521. echo -n "${color_failed}#### failed to build some targets "
  1522. fi
  1523. if [ $hours -gt 0 ] ; then
  1524. printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
  1525. elif [ $mins -gt 0 ] ; then
  1526. printf "(%02g:%02g (mm:ss))" $mins $secs
  1527. elif [ $secs -gt 0 ] ; then
  1528. printf "(%s seconds)" $secs
  1529. fi
  1530. echo " ####${color_reset}"
  1531. echo
  1532. return $ret
  1533. }
  1534. function _trigger_build()
  1535. (
  1536. local -r bc="$1"; shift
  1537. if T="$(gettop)"; then
  1538. _wrap_build "$T/build/soong/soong_ui.bash" --build-mode --${bc} --dir="$(pwd)" "$@"
  1539. else
  1540. echo "Couldn't locate the top of the tree. Try setting TOP."
  1541. fi
  1542. )
  1543. function m()
  1544. (
  1545. _trigger_build "all-modules" "$@"
  1546. )
  1547. function mm()
  1548. (
  1549. _trigger_build "modules-in-a-dir-no-deps" "$@"
  1550. )
  1551. function mmm()
  1552. (
  1553. _trigger_build "modules-in-dirs-no-deps" "$@"
  1554. )
  1555. function mma()
  1556. (
  1557. _trigger_build "modules-in-a-dir" "$@"
  1558. )
  1559. function mmma()
  1560. (
  1561. _trigger_build "modules-in-dirs" "$@"
  1562. )
  1563. function make()
  1564. {
  1565. _wrap_build $(get_make_command "$@") "$@"
  1566. }
  1567. function provision()
  1568. {
  1569. if [ ! "$ANDROID_PRODUCT_OUT" ]; then
  1570. echo "Couldn't locate output files. Try running 'lunch' first." >&2
  1571. return 1
  1572. fi
  1573. if [ ! -e "$ANDROID_PRODUCT_OUT/provision-device" ]; then
  1574. echo "There is no provisioning script for the device." >&2
  1575. return 1
  1576. fi
  1577. # Check if user really wants to do this.
  1578. if [ "$1" = "--no-confirmation" ]; then
  1579. shift 1
  1580. else
  1581. echo "This action will reflash your device."
  1582. echo ""
  1583. echo "ALL DATA ON THE DEVICE WILL BE IRREVOCABLY ERASED."
  1584. echo ""
  1585. echo -n "Are you sure you want to do this (yes/no)? "
  1586. read
  1587. if [[ "${REPLY}" != "yes" ]] ; then
  1588. echo "Not taking any action. Exiting." >&2
  1589. return 1
  1590. fi
  1591. fi
  1592. "$ANDROID_PRODUCT_OUT/provision-device" "$@"
  1593. }
  1594. # Zsh needs bashcompinit called to support bash-style completion.
  1595. function enable_zsh_completion() {
  1596. # Don't override user's options if bash-style completion is already enabled.
  1597. if ! declare -f complete >/dev/null; then
  1598. autoload -U compinit && compinit
  1599. autoload -U bashcompinit && bashcompinit
  1600. fi
  1601. }
  1602. function validate_current_shell() {
  1603. local current_sh="$(ps -o command -p $$)"
  1604. case "$current_sh" in
  1605. *bash*)
  1606. function check_type() { type -t "$1"; }
  1607. ;;
  1608. *zsh*)
  1609. function check_type() { type "$1"; }
  1610. enable_zsh_completion ;;
  1611. *)
  1612. echo -e "WARNING: Only bash and zsh are supported.\nUse of other shell would lead to erroneous results."
  1613. ;;
  1614. esac
  1615. }
  1616. # Execute the contents of any vendorsetup.sh files we can find.
  1617. # Unless we find an allowed-vendorsetup_sh-files file, in which case we'll only
  1618. # load those.
  1619. #
  1620. # This allows loading only approved vendorsetup.sh files
  1621. function source_vendorsetup() {
  1622. unset VENDOR_PYTHONPATH
  1623. local T="$(gettop)"
  1624. allowed=
  1625. for f in $(cd "$T" && find -L device vendor product -maxdepth 4 -name 'allowed-vendorsetup_sh-files' 2>/dev/null | sort); do
  1626. if [ -n "$allowed" ]; then
  1627. echo "More than one 'allowed_vendorsetup_sh-files' file found, not including any vendorsetup.sh files:"
  1628. echo " $allowed"
  1629. echo " $f"
  1630. return
  1631. fi
  1632. allowed="$T/$f"
  1633. done
  1634. allowed_files=
  1635. [ -n "$allowed" ] && allowed_files=$(cat "$allowed")
  1636. for dir in device vendor product; do
  1637. for f in $(cd "$T" && test -d $dir && \
  1638. find -L $dir -maxdepth 4 -name 'vendorsetup.sh' 2>/dev/null | sort); do
  1639. if [[ -z "$allowed" || "$allowed_files" =~ $f ]]; then
  1640. echo "including $f"; . "$T/$f"
  1641. else
  1642. echo "ignoring $f, not in $allowed"
  1643. fi
  1644. done
  1645. done
  1646. }
  1647. function showcommands() {
  1648. local T=$(gettop)
  1649. if [[ -z "$TARGET_PRODUCT" ]]; then
  1650. >&2 echo "TARGET_PRODUCT not set. Run lunch."
  1651. return
  1652. fi
  1653. case $(uname -s) in
  1654. Darwin)
  1655. PREBUILT_NAME=darwin-x86
  1656. ;;
  1657. Linux)
  1658. PREBUILT_NAME=linux-x86
  1659. ;;
  1660. *)
  1661. >&2 echo Unknown host $(uname -s)
  1662. return
  1663. ;;
  1664. esac
  1665. if [[ -z "$OUT_DIR" ]]; then
  1666. if [[ -z "$OUT_DIR_COMMON_BASE" ]]; then
  1667. OUT_DIR=out
  1668. else
  1669. OUT_DIR=${OUT_DIR_COMMON_BASE}/${PWD##*/}
  1670. fi
  1671. fi
  1672. if [[ "$1" == "--regenerate" ]]; then
  1673. shift 1
  1674. NINJA_ARGS="-t commands $@" m
  1675. else
  1676. (cd $T && prebuilts/build-tools/$PREBUILT_NAME/bin/ninja \
  1677. -f $OUT_DIR/combined-${TARGET_PRODUCT}.ninja \
  1678. -t commands "$@")
  1679. fi
  1680. }
  1681. # 执行方法
  1682. validate_current_shell
  1683. source_vendorsetup
  1684. addcompletions

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/327286
推荐阅读
相关标签
  

闽ICP备14008679号