Android編譯執行envsetup.sh,產生工具命令m、mm、mmm、mmma、tapas 、croot、cgrep、jgrep、 resgrep、godir


一般來說編譯一個sdk或者一個比較大的工程項目,第一步都是執行 envsetup.sh這個腳本,比如編譯android,qt源碼以及其他一些嵌入式的sdk。

而且執行的時候需要特別注意使用

source build/envsetup.sh

或者

. ./build/envsetup.sh

特別注意兩個點之間是有空格的,這個作用相當於source。

==========================================補課開始=====================================================================

一般執行shell腳本時直接用./來執行,此時是系統啟動一個子shell進程來執行命令,執行完后返回最后一條指令的結果(可以用echo $?來獲取執行結果值(0-255)),其結果並不會對當前的BASH產生影響。

source命令的用法:

source FileName

他的作用是在當前bash環境下讀取並執行FileName中的指令,這個命令執行完之后會把FileName執行過程中的一些輸出設置到當前的BASH中,也就設置環境變量。

需要注意的是用source執行新產生的這些變量的作用范圍(作用域)只是在當前終端有用,如果你關閉當前終端了,或者在其他終端是無法使用這些新增的變量的。

==========================================補課結束=====================================================================

當我們用source命令執行完encsetup.sh的時候,里面設置的一些變量(方法)就會輸出到當前的BASH環境中,在后續的過程中我們就可以在當前終端使用這些變量,比如用android的envsetup.sh來說,執行完后會增加一些shell cmd及環境變量可以使用

輸入hmm可以看到以下幫助信息

Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
- lunch: lunch <product_name>-<build_variant>
- tapas: tapas [<App1> <App2> ...] [arm|x86|mips|armv5] [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. - 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. - jgrep: Greps on all local Java files. - resgrep: Greps on all local res/*.xml files. - godir: Go to the directory containing a file. Look at the source to view more functions. The complete list is: addcompletions add_lunch_combo cgrep check_product check_variant choosecombo chooseproduct choosetype choosevariant cproj croot findmakefile gdbclient gdbwrapper get_abs_build_var getbugreports get_build_var getlastscreenshot getprebuilt getscreenshotpath getsdcardpath gettargetarch gettop godir hmm isviewserverstarted jgrep key_back key_home key_menu lunch _lunch m mangrep 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 smoketest stacks startviewserver stopviewserver systemstack tapas tracedmdump
liuxueneng@airfly-dev:~/workCode/allwinner_h2_2018-0907/android$ source build/envsetup.sh 
find Makefile
including device/generic/mips/vendorsetup.sh
including device/generic/armv7-a-neon/vendorsetup.sh
including device/generic/x86/vendorsetup.sh
including device/softwinner/common/vendorsetup.sh
including device/softwinner/dolphin-fvd-p1/vendorsetup.sh
liuxueneng@airfly-dev:~/workCode/allwinner_h2_2018-0907/android$ hmm 
Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
- lunch:   lunch <product_name>-<build_variant>
- tapas:   tapas [<App1> <App2> ...] [arm|x86|mips|armv5] [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.
- 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.
- jgrep:   Greps on all local Java files.
- resgrep: Greps on all local res/*.xml files.
- godir:   Go to the directory containing a file.

Look at the source to view more functions. The complete list is:
addcompletions add_lunch_combo cgrep check_product check_variant choosecombo chooseproduct choosetype choosevariant cproj croot findmakefile gdbclient gdbwrapper get_abs_build_var getbugreports get_build_var getlastscreenshot getprebuilt getscreenshotpath getsdcardpath gettargetarch gettop godir hmm isviewserverstarted jgrep key_back key_home key_menu lunch _lunch m mangrep 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 smoketest stacks startviewserver stopviewserver systemstack tapas tracedmdump
liuxueneng@airfly-dev:~/workCode/allwinner_h2_2018-0907/android$ 

這些命令都是在android/build/envsetup.sh中定義輸出的,可以打開看下

export ROOT_DIR=${PWD}
MAKEFILE=$ROOT_DIR/Makefile
if [ -f $MAKEFILE ]; then
    echo "find Makefile"
else
    echo "copy Makefile"
    cp $ROOT_DIR/build/core/root.mk $ROOT_DIR/Makefile
fi
function hmm() {
cat <<EOF
Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
- lunch:   lunch <product_name>-<build_variant>
- tapas:   tapas [<App1> <App2> ...] [arm|x86|mips|armv5] [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.
- 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.
- jgrep:   Greps on all local Java files.
- resgrep: Greps on all local res/*.xml files.
- godir:   Go to the directory containing a file.

Look at the source to view more functions. The complete list is:
EOF
    T=$(gettop)
    local A
    A=""
    for i in `cat $T/build/envsetup.sh | sed -n "/^function /s/function \([a-z_]*\).*/\1/p" | sort`; do
      A="$A $i"
    done
    echo  $A
}

# Get the value of a build variable as an absolute path.
function get_abs_build_var()
{
    T=$(gettop)
    if [ ! "$T" ]; then
        echo "Couldn't locate the top of the tree.  Try setting TOP." >&2
        return
    fi
    (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
      make --no-print-directory -C "$T" -f build/core/config.mk dumpvar-abs-$1)
}

這些方法還有一些變量都會輸出到當前的BASH環境中,輸入env指令就可以打印出當前BASH下的所有環境變量

liuxueneng@airfly-dev:~/workCode/allwinner_h2_2018-0907/android$ env
XDG_SESSION_ID=13509
TERM=xterm
SHELL=/bin/bash
SSH_CLIENT=192.168.11.102 1097 22
OLDPWD=/home/liuxueneng
SSH_TTY=/dev/pts/26
USER=liuxueneng
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:
ROOT_DIR=/home/liuxueneng/workCode/allwinner_h2_2018-0907/android
MAIL=/var/mail/liuxueneng
PATH=/home/liuxueneng/bin:/home/liuxueneng/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
PWD=/home/liuxueneng/workCode/allwinner_h2_2018-0907/android
LANG=en_HK.UTF-8
SHLVL=1
HOME=/home/liuxueneng
LANGUAGE=en_HK:en
LOGNAME=liuxueneng
XDG_DATA_DIRS=/usr/local/share:/usr/share:/var/lib/snapd/desktop
SSH_CONNECTION=192.168.11.102 1097 192.168.11.111 22
LESSOPEN=| /usr/bin/lesspipe %s
XDG_RUNTIME_DIR=/run/user/1006
LESSCLOSE=/usr/bin/lesspipe %s %s
_=/usr/bin/env

其中我們可以看到至少以下兩個變量是執行剛才的envsetup.sh輸出來的

ROOT_DIR=/home/liuxueneng/workCode/allwinner_h2_2018-0907/android

聯系以上的的croot指令就是改變當前工作目錄的哦ROOT_DIR中。

另外還可以查看輸出到當前BASH環境中的臨時shell方法,輸入set指令來查看(小心會有一大堆東西噴出來)

tracedmdump () 
{ 
    T=$(gettop);
    if [ ! "$T" ]; then
        echo "Couldn't locate the top of the tree.  Try setting TOP.";
        return;
    fi;
    local prebuiltdir=$(getprebuilt);
    local arch=$(gettargetarch);
    local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu;
    local TRACE=$1;
    if [ ! "$TRACE" ]; then
        echo "usage:  tracedmdump  tracename";
        return;
    fi;
    if [ ! -r "$KERNEL" ]; then
        echo "Error: cannot find kernel: '$KERNEL'";
        return;
    fi;
    local BASETRACE=$(basename $TRACE);
    if [ "$BASETRACE" = "$TRACE" ]; then
        TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE;
    fi;
    echo "post-processing traces...";
    rm -f $TRACE/qtrace.dexlist;
    post_trace $TRACE;
    if [ $? -ne 0 ]; then
        echo "***";
        echo "*** Error: malformed trace.  Did you remember to exit the emulator?";
        echo "***";
        return;
    fi;
    echo "generating dexlist output...";
    /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;
    echo "generating dmtrace data...";
    q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return;
    echo "generating html file...";
    dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return;
    echo "done, see $TRACE/dmtrace.html for details";
    echo "or run:";
    echo "    traceview $TRACE/dmtrace"
}
treegrep () 
{ 
    find . -name .repo -prune -o -name .git -prune -o -regextype posix-egrep -iregex '.*\.(c|h|cpp|S|java|xml)' -type f -print0 | xargs -0 grep --color -n -i "$@"
}
verity_file_init () 
{ 
    echo "verity_file_init";
    cp -rf $DEVICE/verity ${OUT};
    $DEVICE/verity/gen_file_verify_block.sh ${OUT}/system;
    cp -f ${OUT}/verity/verity_block ${OUT}/verity_block.img
}
verity_key_init () 
{ 
    $DEVICE/verity/gen_dm_verity_key.sh;
    cp -f $DEVICE/verity/rsa_key/verity_key $OUT/root
}

以上treegrep tracedmdump等shell方法都是從envsetup.sh輸出來的。

后續講解下輸出的m mm mmm mmma croot cgrep 等作用及用法。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM