【Android】android编译之source build/envsetup.sh简单用法

envsetup.sh内容:

xxxx@rmxx07:/work/buildfarm/smxxxx_vnd$ head -50 build/envsetup.sh
function hmm() {
cat <<EOF

Run "m help" for help with the build system itself.

Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
- lunch:      lunch <product_name>-<build_variant>
              Selects <product_name> as the product to build, and <build_variant> as the variant to
              build, and stores those selections in the environment to be read by subsequent
              invocations of 'm' etc.
- tapas:      tapas [<App1> <App2> ...] [arm|x86|arm64|x86_64] [eng|userdebug|user]
              Sets up the build environment for building unbundled apps (APKs).
- banchan:    banchan <module1> [<module2> ...] [arm|x86|arm64|x86_64] [eng|userdebug|user]
              Sets up the build environment for building unbundled modules (APEXes).
- croot:      Changes directory to the top of the tree, or a subdirectory thereof.
- m:          Makes from the top of the tree.
- mm:         Builds and installs all of the modules in the current directory, and their
              dependencies.
- mmm:        Builds and installs all of the modules in the supplied directories, and their
              dependencies.
              To limit the modules being built use the syntax: mmm dir/:target1,target2.
- mma:        Same as 'mm'
- mmma:       Same as 'mmm'
- provision:  Flash device with all required partitions. Options will be passed on to fastboot.
- cgrep:      Greps on all local C/C++ files.
- ggrep:      Greps on all local Gradle files.
- gogrep:     Greps on all local Go files.
- jgrep:      Greps on all local Java files.
- ktgrep:     Greps on all local Kotlin files.
- resgrep:    Greps on all local res/*.xml files.
- mangrep:    Greps on all local AndroidManifest.xml files.
- mgrep:      Greps on all local Makefiles and *.bp files.
- owngrep:    Greps on all local OWNERS files.
- rsgrep:     Greps on all local Rust files.
- sepgrep:    Greps on all local sepolicy files.
- sgrep:      Greps on all local source files.
- godir:      Go to the directory containing a file.
- allmod:     List all modules.
- gomod:      Go to the directory containing a module.
- pathmod:    Get the directory containing a module.
- outmod:     Gets the location of a module's installed outputs with a certain extension.
- dirmods:    Gets the modules defined in a given directory.
- installmod: Adb installs a module's built APK.
- refreshmod: Refresh list of modules for allmod/gomod/pathmod/outmod/installmod.
- syswrite:   Remount partitions (e.g. system.img) as writable, rebooting if necessary.

Environment options:
- SANITIZE_HOST: Set to 'address' to use ASAN for all host modules.
- ANDROID_QUIET_BUILD: set to 'true' to display only the essential messages.

使用Demo:

- croot:      Changes directory to the top of the tree, or a subdirectory thereof.
- godir:      Go to the directory containing a file. #就是字面意思 

xxx@rmxx07:/work/xxx/smxxx_vnd/frameworks/base/core/java/android/app$ croot
xxx@rmxx07:/work/xxx/smxxx_vnd$ godir DownloadManager.java
   [1] ./external/exoplayer/tree_15dc86382f17a24a3e881e52e31a810c1ea44b49/library/core/src/main/java/com/google/android/exoplayer2/offline
   [2] ./external/exoplayer/tree_410ddf458c4daebcf3f997084891c82f2dbd6805/library/core/src/main/java/com/google/android/exoplayer2/offline
   [3] ./external/exoplayer/tree/library/core/src/main/java/com/google/android/exoplayer2/offline
   [4] ./external/libtextclassifier/java/src/com/android/textclassifier/downloader
   [5] ./external/robolectric-shadows/shadows/framework/src/main/java/org/robolectric/shadows
   [6] ./frameworks/base/core/java/android/app
   [7] ./frameworks/opt/telephony/src/java/com/android/internal/telephony
   [8] ./vendor/codeaurora/commonsys/packages/apps/Mms/src/com/android/mms/util

Select one: 6
buildfarm@rmbj07:/work/buildfarm/sm8550_vnd/frameworks/base/core/java/android/app$ ll DownloadManager.java
-rw-rw-r-- 1 buildfarm buildfarm 77258 Jun  2 11:12 DownloadManager.java
buildfarm@rmbj07:/work/buildfarm/sm8550_vnd/frameworks/base/core/java/android/app$

godir方法函数实现:

function godir () {
    if [[ -z "$1" ]]; then
        echo "Usage: godir <regex>"
        return
    fi
    local T=$(gettop)
    local FILELIST
    if [ ! "$OUT_DIR" = "" ]; then
        mkdir -p $OUT_DIR
        FILELIST=$OUT_DIR/filelist
    else
        FILELIST=$T/filelist
    fi
    if [[ ! -f $FILELIST ]]; then
        echo -n "Creating index..."
        (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > $FILELIST)
        echo " Done"
        echo ""
    fi
    local lines
    lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq))
    if [[ ${#lines[@]} = 0 ]]; then
        echo "Not found"
        return
    fi
    local pathname
    local choice
    if [[ ${#lines[@]} > 1 ]]; then
        while [[ -z "$pathname" ]]; do
            local index=1
            local line
            for line in ${lines[@]}; do
                printf "%6s %s\n" "[$index]" $line
                index=$(($index + 1))
            done
            echo
            echo -n "Select one: "
            unset choice
            read choice
            if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
                echo "Invalid choice"
                continue
            fi
            pathname=${lines[@]:$(($choice-1)):1}
        done
    else
        pathname=${lines[@]:0:1}
    fi
    \cd $T/$pathname
}
posted @ 2022-06-08 21:41  爱啦啦  阅读(435)  评论(0编辑  收藏  举报