Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

build/envsetup.sh 腳本概要學習

編輯:關於 Android 程式設計

在我們的 msm8909 + Android 5.1 環境中,編譯之前需要先執行以下兩個命令:

source build/envsetup.sh

source build/envsetup.sh 這個腳本主要用來定義一些基本函數、環境變量,以及配置編譯工具與路徑。其中 source 命令的作用是運行 shell 腳本,功能等同於「.」,所以這條命令也等價於 . build/envsetup.sh。envsetup.sh 裡聲明了當前會話終端可用的命令——請特別注意「當前會話終端」這個前提,也就是說每次新打開一個終端,都得重新執行一次這些指令。

輸入 source build/envsetup.sh 並回車後,會輸出如下信息:

 including device/lge/mako/vendorsetup.sh includingdevice/htc/flounder/vendorsetup.sh includingdevice/asus/grouper/vendorsetup.sh including device/asus/fugu/vendorsetup.sh includingdevice/asus/tilapia/vendorsetup.sh including device/asus/deb/vendorsetup.sh includingdevice/qcom/common/vendorsetup.sh including device/generic/mini-emulator-x86/vendorsetup.sh includingdevice/generic/mini-emulator-arm64/vendorsetup.sh includingdevice/generic/mini-emulator-mips/vendorsetup.sh includingdevice/generic/mini-emulator-armv7-a-neon/vendorsetup.sh including device/generic/mini-emulator-x86_64/vendorsetup.sh includingdevice/samsung/manta/vendorsetup.sh includingvendor/qcom/proprietary/common/vendorsetup.sh including sdk/bash_completion/adb.bash

這段輸出對應 envsetup.sh 中如下的內容:它會在 device 和 vendor 目錄下查找 vendorsetup.sh 文件,並加載、執行它們。

 # Execute the contents of anyvendorsetup.sh files we can find. for f in `test -d device && find -Ldevice -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null` \ `test -d vendor && find -L vendor -maxdepth 4 -name'vendorsetup.sh' 2> /dev/null` do echo "including $f" .$f//執行這些文件 done unset f

由於我們用的是 qcom 平台,只加載 qcom 相關的 vendorsetup.sh 也能正常編譯和運行:

including device/qcom/common/vendorsetup.sh

including vendor/qcom/proprietary/common/vendorsetup.sh

此外,sdk/bash_completion 目錄下的 adb.bash 文件也會被加載到當前終端。它用來實現 adb 命令的 bash completion 功能——加載之後,運行 adb 相關命令時,按 Tab 鍵就能自動補全命令輸入。關於 bash completion 的知識,可參考官方文檔:https://www.gnu.org/s/bash/manual/bash.html。

including sdk/bash_completion/adb.bash

1. Qcom 平台的 vendorsetup.sh

1.1 device/qcom/common/vendorsetup.sh

add_lunch_combo msm8909-userdebug
add_lunch_combo msm8909-user
add_lunch_combo msm8909-eng

通過調用 add_lunch_combo 函數來增加編譯選項。輸入命令行 lunch 後,輸出如下:

Lunch menu... pick a combo:

1. msm8909-userdebug

2. msm8909-user

3. msm8909-eng

add_lunch_combo 函數的定義如下:

 # Clear this variable. It will be built up again when thevendorsetup.sh # files are included at the end of thisfile. unset LUNCH_MENU_CHOICES function add_lunch_combo() { local new_combo=$1 #獲得add_lunch_combo被調用時的參數 local c # 遍歷LUNCH_MENU_CHOICES裡的值,該函數第一次調用時為空 for c in ${LUNCH_MENU_CHOICES[@]} ; do if [ "$new_combo" = "$c" ] ; then # 如果參數裡的值已經存在於LUNCH_MENU_CHOICES變量裡,則返回 return fi done # 如果參數的值不存在,則添加到LUNCH_MENU_CHOICES變量裡 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo) }

1.2 vendor/qcom/proprietary/common/vendorsetup.sh

export QCPATH="vendor/qcom/proprietary"

這個路徑會被下面的文件引用:

 device/qcom/common/base.mk:1058:#skip bootjars check if QCPATH not available device/qcom/common/base.mk:1059:ifeq($(strip $(QCPATH)),) device/qcom/common/common64.mk:6:$(callinherit-product-if-exists, $(QCPATH)/common/config/device-vendor.mk) device/qcom/common/common.mk:8:$(callinherit-product-if-exists, $(QCPATH)/common/config/device-vendor.mk) device/qcom/msm8909/BoardConfig.mk:30:-include$(QCPATH)/common/msm8909/BoardConfigVendor.mk device/qcom/msm8909/msm8909.mk:24:-include$(QCPATH)/common/config/qtic-config.mk device/qcom/msm8909/msm8909.mk:39:-include$(QCPATH)/common/config/rendering-engine.mk device/qcom/msm8909/msm8909.mk:185:PRODUCT_PACKAGE_OVERLAYS:= $(QCPATH)/qrdplus/Extension/res-overlay \ device/qcom/msm8909/msm8909.mk:186: $(QCPATH)/qrdplus/globalization/multi-language/res-overlay\

2. 環境變量、配置編譯工具與路徑

例如:

 #set openjdk7 exportJAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64 exportJRE_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre exportCLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH 

3. 支持的函數

envsetup.sh 文件開頭定義了 hmm 函數,執行 hmm 命令後會輸出:

Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:

- lunch: lunch <product_name>-<build_variant>
- tapas: tapas [...] [arm|x86|mips|armv5|arm64|x86_64|mips64][eng|userdebug|user]
- croot: Changes directory to the top of the tree.
- m: Makes from the top of the tree.
- mm: Builds all of the modules in the current directory, but not their dependencies.
- mmm: Builds all of the modules in the supplied directories, but not their dependencies. To limit the modules being built use the syntax: mmm dir/:target1,target2.
- mma: Builds all of the modules in the current directory, and their dependencies.
- mmma: Builds all of the modules in the supplied directories, and their dependencies.
- cgrep: Greps on all local C/C++ files.
- ggrep: Greps on all local Gradle files.
- jgrep: Greps on all local Java files.
- resgrep: Greps on all local res/*.xml files.
- sgrep: Greps on all local source files.
- godir: Go to the directory containing a file.

完整的函數列表為:adb_get_product_device、adb_get_traced_by、addcompletions、add_lunch_combo、cgrep、check_multisim、check_product、check_project、check_variant、choose、choosecombo、chooseproduct、chooseproject、choosetype、choosevariant、core、coredump_enable、coredump_setup、cproj、croot、findmakefile、gdbclient、gdbclient_old、gdbwrapper、get_abs_build_var、getbugreports、get_build_var、getdriver、getlastscreenshot、get_make_command、getprebuilt、getscreenshotpath、getsdcardpath、get_symbols_directory、gettargetarch、gettop、ggrep、godir、hmm、init、isviewserverstarted、jgrep、key_back、key_home、key_menu、lunch、_lunch、m、make、mangrep、mgrep、mm、mma、mmm、mmma、pez、pid、printconfig、print_lunch_menu、qpid、resgrep、runhat、runtest、sepgrep、set_java_home、setpaths、set_sequence_number、set_stuff_for_environment、settitle、sgrep、smoketest、stacks、startviewserver、stopviewserver、systemstack、tapas、tracedmdump、treegrep。

以上便是 envsetup.sh 所支持的全部函數集。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved