AOSP常用命令

作者: 小村医 | 来源:发表于2019-06-29 17:42 被阅读5次

这里介绍的命令主要是build/envsetup.sh中定义的一些命令:


envsetup.sh.png

这些命令对应的都是envsetup.sh里面的一些函数

1.gettop:获取工作目录的绝对路径
当我们所处的目录层级较深是想切换到其他目录是可以使用这个目录,比如我们想切换到frameworks目录下可以使用cd $(gettop)/frameworks

  1. croot:直接切换到工作目录的根目录下
function croot()
{
    local T=$(gettop)
    if [ "$T" ]; then
        if [ "$1" ]; then
            \cd $(gettop)/$1
        else
            \cd $(gettop)
        fi
    else
        echo "Couldn't locate the top of the tree.  Try setting TOP."
    fi
}
  1. mm:编译当前目录下的模块
function mm()
{
    local T=$(gettop)
    # If we're sitting in the root of the build tree, just do a
    # normal build.
    if [ -f build/soong/soong_ui.bash ]; then
        _wrap_build $T/build/soong/soong_ui.bash --make-mode $@
    else
        # Find the closest Android.mk file.
        local M=$(findmakefile)
        .....
}
function findmakefile()
{
    local TOPFILE=build/make/core/envsetup.mk
    local HERE=$PWD
    local T=
    while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
        T=`PWD= /bin/pwd`
        if [ -f "$T/Android.mk" -o -f "$T/Android.bp" ]; then
            echo $T/Android.mk
            \cd $HERE
            return
        fi
        \cd ..
    done
    \cd $HERE
}

mm中主要是通过findmakefile查找Android.mk,然后根据配置进行编译

  1. cgrep:执行grep命令,但只匹配c/c++文件
function cgrep()
{
    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' \) \
        -exec grep --color -n "$@" {} +
}
  1. jgrep:执行grep命令,但只匹配java文件

  2. resgrep:执行grep命令,但只匹配res文件

  3. godir:去某一个目录,第一次执行会将AOSP的所有目录路径保存到filelist文件中
    如我想直接进入到ActivityManagerService.java的目录下,可以使用这个命令

$ godir ActivityManagerService.java
$ pwd
/Volumes/M1/aosp/android9.0/frameworks/base/services/core/java/com/android/server/am
$

相关文章

网友评论

    本文标题:AOSP常用命令

    本文链接:https://www.haomeiwen.com/subject/ogfpcctx.html