2021年9月

转自: https://blog.csdn.net/u011913612/article/details/52415948

Android编译系统分析系列文章:

android编译系统分析一<source build/envsetup.sh与lunch> Android编译系统<二>-mm编译单个模块 android编译系统分析(三)-make android编译系统(四)-实战:新增一个产品 Android编译系统分析(五)-system.img的生成过程

因为Android的编译系统不同于Linux Kernel的递归式的编译系统,它的编译系统是一种称之为independent的模式,每个模块基本独立(它有可能依赖其他模块),每个模块都可以单独编译,这是Android independent编译系统模式的好处。但这并不意味着它是完美的,普通电脑编译android系统需要8个小时甚至更多(以本人的电脑为例),而编译linux kernel只需要半个小时,代码量是一回事,由independent模式造成的编译时间长应该是可以肯定的。正因为每个模块可以单独编译,所以android系统的编译就是依次编译每个模块,然后把所有编译好的模块和其他一些文件一起打包成镜像文件。因此,只要理解了每个模块的编译,理解android系统的编译就轻松多了。(以上均是个人观点,欢迎拍砖)

- 阅读剩余部分 -

出现这个报错,是因为子文件夹下面也有 .git,有两种方法解决:

  • 直接删除子文件夹的 .git,如果使用 find . -name ".git" 发现要删除的比较少,就手动删除,如果要删除的比较多,就使用 find . -name ".git" | xargs rm -Rf 批量删除。
  • 把子文件夹作为模块来进行管理,这个比较麻烦,如果是大型多人合作工程,可以考虑使用 repo 这样专门的管理模式。如果是小团队,就不如第一种加上复制粘贴来的快捷。

参考

fatal: 'git status --porcelain'
https://blog.csdn.net/qq_40028324/article/details/82770466
删除文件夹下所有的.git文件
https://blog.csdn.net/wuyanyanstrong/article/details/52766293
git submodule 的使用
https://www.jianshu.com/p/e27a978ddb88
https://blog.justwe.site/post/git-submodule/

本文是参考 http://www.ramlife.org/2021/09/08/407.html 在 android 10 源码上面对 envsetup.sh 进行初步分析。

envsetup.sh

envsetup.sh 链接位置在 build/envsetup.sh,真实位置是 build/make/envsetup.sh。 在脚本中,能够看到有很多函数,最下面直接调用的只有三个函数:

validate_current_shell
source_vendorsetup
addcompletions

validate_current_shell

validate_current_shell 中功能很简单,函数名称也能够看出来,检测当前的 shell 是哪种,通过 local current_sh="$(ps -o command -p $$)" 获取当前的 bash 程序,我使用的是 bash,所以这个变量获取到的是 COMMAND -bash , 所以执行 function check_type() { type -t "$1"; }.

type 命令属于 bash 内建命令,-t选项显示参数指定类型信息。会打印字符串:alias, keyword, function, builtin, or file

# type -t gcc
file
#type -t cd
builtin
 #type -t ll
alias

# type -t if
keyword
#type -t print

参考: bash内建命令type简介
https://blog.csdn.net/hanzhen1135/article/details/48340097

source_vendorsetup

看函数名称,应该是执行厂商的配置。

    allowed=
    for f in $(find -L device vendor product -maxdepth 4 -name 'allowed-vendorsetup_sh-files' 2>/dev/null | sort); do
        if [ -n "$allowed" ]; then
            echo "More than one 'allowed_vendorsetup_sh-files' file found, not including any vendorsetup.sh files:"
            echo "  $allowed"
            echo "  $f"
            return
        fi
        allowed="$f"
    done

上面在 device, vendor, product 三个文件夹中,向下找 4层路径,找名字是 'allowed-vendorsetup_sh-files' 的文件, -L 表示是链接的时候,去源文件那边去找,而不是链接本身。我们实际运行的时候,allowed 为空。

参考: Linux基础:文件查找find命令详细讲解
http://www.manongjc.com/article/19084.html

    allowed_files=
    [ -n "$allowed" ] && allowed_files=$(cat "$allowed")
    for dir in device vendor product; do
        for f in $(test -d $dir && \
            find -L $dir -maxdepth 4 -name 'vendorsetup.sh' 2>/dev/null | sort); do

            if [[ -z "$allowed" || "$allowed_files" =~ $f ]]; then
                echo "including $f"; . "$f"
            else
                echo "ignoring $f, not in $allowed"
            fi
        done
    done

上面这段代码是在 device, vendor, product 三个文件夹下面,找四层,找 'vendorsetup.sh',找到之后,先判断 allowed 是零,或者 allowed_files 符合 $f 这个正则的模型,然后就会 include进去,在运行 . $f 意思是再 source $f。 最终输出就是:

including vendor/qcom/opensource/core-utils/vendorsetup.sh
including vendor/qcom/proprietary/common/vendorsetup.sh
including vendor/qcom/proprietary/prebuilt_HY11/vendorsetup.sh
*****Could not create symlink*******
sdk/current/androidx-README.md::frameworks/support/README.md
vendor/qcom/opensource/core-utils/build.sh::build.sh
****************END******************
Created 85 symlinks out of 87 mapped links..
vendor/qcom/opensource/core-utils/vendorsetup.sh

这个脚本里面只有一句: export QTI_BUILDTOOLS_DIR=$(dirname ${BASH_SOURCE[0]}) BASH_SOURCE[0] 等价于 BASH_SOURCE ,取得当前执行的 shell 文件所在的路径及文件名。dirname 去除文件名中的非目录部分,仅显示与目录有关的部分。 所以这句的意思是 QTI_BUILDTOOLS_DIR 这个值就是 vendorsetup.sh 当前目录的值了。

参考: Shell中的BASH_SOURCE
https://blog.csdn.net/lizhiqiang1217/article/details/94737535

vendor/qcom/proprietary/common/vendorsetup.sh

这个脚本里面是:

export QCPATH="$(pwd)/vendor/qcom/proprietary"
export QCPATH_COMMONSYS="${QCPATH}/commonsys"
export SDCLANG_AE_CONFIG="${QCPATH}/common-noship/etc/sdclang.json"
export SDCLANG_CONFIG="${QCPATH}/common/config/sdclang.json"
export SDCLANG_CONFIG_AOSP="${QCPATH}/common/config/sdclang-pureAOSP.json"
if [ -f "${QCPATH}/qrsp/mpgen/mpgen.py" ]; then
export RTIC_MPGEN="python ${QCPATH}/qrsp/mpgen/mpgen.py"
fi

对这些变量进行赋值,并 export 出来。

vendor/qcom/proprietary/prebuilt_HY11/vendorsetup.sh

脚本内容:

links_dir="$(dirname $(readlink -e "${BASH_SOURCE[0]}"))"
links_path="$(dirname $(readlink -e "${BASH_SOURCE[0]}"))/links"
sys_links_path="$(dirname $(readlink -e "${BASH_SOURCE[0]}"))/system_links"
ven_links_path="$(dirname $(readlink -e "${BASH_SOURCE[0]}"))/vendor_links"
failed_links=""
count=0
if [[ -f "$links_path" || -f "$sys_links_path" || -f "$ven_links_path" ]];then
  total_links=$(cat $links_dir/*links| wc -l)
  for i in $(cat $links_dir/*links);do
    src=$(echo $i | awk -F:: '{print $1}')
    dest=$(echo $i | awk -F:: '{print $2}')
    if [ -e "$dest" ];then
      rm -rf $dest
    fi
    if [[ -e $src && ! -e $dest ]];then
      mkdir -p $(dirname $dest)
      ln -srf $src $dest
      count=$(($count + 1))
    else
      failed_links="$failed_links $i"
    fi
  done
  if [ ! -z "$failed_links" ];then
    echo "*****Could not create symlink*******"
    echo $failed_links | sed 's/[[:space:]]/\n/g'
    echo "****************END******************"
  fi
  echo "Created $count symlinks out of $total_links mapped links.."
fi

readlink 用于得出链接的真实路径,-e 是递归的读取. 就是为了获得真正的 vendorsetup.h 所在的文件夹。 cat $links_dir/*links | wc -l 指的是统计 links_dir文件夹下所有的 *links,看里面有多少个换行符,也就是有多少行。 然后就是简单的把源文件通过软连接链接到目的路径。ln -srf 意思是如果目的地有软连接就强制删除,并且这个软连接是相对位置的软连接,而不是绝对位置的软连接。

把这个文件中链接部分增加了打印信息,结果如下:

total links:  87
build/make/CleanSpec.mk::build/CleanSpec.mk
---> src:  build/make/CleanSpec.mk
<--- dest:  build/CleanSpec.mk
======
build/make/buildspec.mk.default::build/buildspec.mk.default
---> src:  build/make/buildspec.mk.default
<--- dest:  build/buildspec.mk.default
======
build/make/core::build/core
---> src:  build/make/core
<--- dest:  build/core
======
build/make/envsetup.sh::build/envsetup.sh
---> src:  build/make/envsetup.sh
<--- dest:  build/envsetup.sh
======
build/make/target::build/target
---> src:  build/make/target
<--- dest:  build/target
======
build/make/tools::build/tools
---> src:  build/make/tools
<--- dest:  build/tools
======
build/soong/root.bp::Android.bp
---> src:  build/soong/root.bp
<--- dest:  Android.bp
======
build/soong/bootstrap.bash::bootstrap.bash
---> src:  build/soong/bootstrap.bash
<--- dest:  bootstrap.bash
======
sdk/current/androidx-README.md::frameworks/support/README.md
---> src:  sdk/current/androidx-README.md
<--- dest:  frameworks/support/README.md
======
vendor/codeaurora/commonsys/packages/apps/SoundRecorder/app_qtiSoundRecorder_system_product.mk::vendor/qcom/defs/product-defs/system/app_qtiSoundRecorder_product.mk
---> src:  vendor/codeaurora/commonsys/packages/apps/SoundRecorder/app_qtiSoundRecorder_system_product.mk
<--- dest:  vendor/qcom/defs/product-defs/system/app_qtiSoundRecorder_product.mk
======
vendor/qcom/proprietary/qdssagent/qdssagent-ship-vendor-product.mk::vendor/qcom/defs/product-defs/legacy/qdssagent-ship-vendor-product.mk
---> src:  vendor/qcom/proprietary/qdssagent/qdssagent-ship-vendor-product.mk
<--- dest:  vendor/qcom/defs/product-defs/legacy/qdssagent-ship-vendor-product.mk
======
device/qcom/common/generate_extra_images.mk::vendor/qcom/build/tasks/generate_extra_images.mk
---> src:  device/qcom/common/generate_extra_images.mk
<--- dest:  vendor/qcom/build/tasks/generate_extra_images.mk
======
device/qcom/common/stop_scan.mk::kernel/Android.mk
---> src:  device/qcom/common/stop_scan.mk
<--- dest:  kernel/Android.mk
======
device/qcom/common/stop_scan.mk::disregard/Android.mk
---> src:  device/qcom/common/stop_scan.mk
<--- dest:  disregard/Android.mk
======
vendor/codeaurora/commonsys/packages/apps/Mms/app_mms_system_product.mk::vendor/qcom/defs/product-defs/system/app_mms_product.mk
---> src:  vendor/codeaurora/commonsys/packages/apps/Mms/app_mms_system_product.mk
<--- dest:  vendor/qcom/defs/product-defs/system/app_mms_product.mk
======
vendor/codeaurora/commonsys/packages/apps/SnapdragonMusic/app_snapMusic_system_product.mk::vendor/qcom/defs/product-defs/system/app_snapMusic_product.mk
---> src:  vendor/codeaurora/commonsys/packages/apps/SnapdragonMusic/app_snapMusic_system_product.mk
<--- dest:  vendor/qcom/defs/product-defs/system/app_snapMusic_product.mk
======
vendor/qcom/proprietary/commonsys/qrdplus/sva/app_sva_system_product.mk::vendor/qcom/defs/product-defs/system/app_sva_product.mk
---> src:  vendor/qcom/proprietary/commonsys/qrdplus/sva/app_sva_system_product.mk
<--- dest:  vendor/qcom/defs/product-defs/system/app_sva_product.mk
======
vendor/qcom/proprietary/commonsys/qrdplus/Extension/app_extension_system_product.mk::vendor/qcom/defs/product-defs/system/app_extension_product.mk
---> src:  vendor/qcom/proprietary/commonsys/qrdplus/Extension/app_extension_system_product.mk
<--- dest:  vendor/qcom/defs/product-defs/system/app_extension_product.mk
======
hardware/qcom/gps/gps_vendor_product.mk::vendor/qcom/defs/product-defs/vendor/gps-product-hal.mk
---> src:  hardware/qcom/gps/gps_vendor_product.mk
<--- dest:  vendor/qcom/defs/product-defs/vendor/gps-product-hal.mk
======
hardware/qcom/gps/gps_vendor_board.mk::vendor/qcom/defs/board-defs/vendor/gps-board.mk
---> src:  hardware/qcom/gps/gps_vendor_board.mk
<--- dest:  vendor/qcom/defs/board-defs/vendor/gps-board.mk
======
vendor/qcom/opensource/location/gps_vendor_product.mk::vendor/qcom/defs/product-defs/vendor/gps-product-opensource.mk
---> src:  vendor/qcom/opensource/location/gps_vendor_product.mk
<--- dest:  vendor/qcom/defs/product-defs/vendor/gps-product-opensource.mk
======
vendor/qcom/opensource/data-ipa-cfg-mgr/ipacm_vendor_product.mk::vendor/qcom/defs/product-defs/vendor/ipacm_vendor_product.mk
---> src:  vendor/qcom/opensource/data-ipa-cfg-mgr/ipacm_vendor_product.mk
<--- dest:  vendor/qcom/defs/product-defs/vendor/ipacm_vendor_product.mk
======
vendor/qcom/proprietary/cne/shipcne_vendor_product.mk::vendor/qcom/defs/product-defs/legacy/shipcne_vendor_product.mk
---> src:  vendor/qcom/proprietary/cne/shipcne_vendor_product.mk
<--- dest:  vendor/qcom/defs/product-defs/legacy/shipcne_vendor_product.mk
======
vendor/qcom/proprietary/cne/cne_vendor_product_noship.mk::vendor/qcom/defs/product-defs/legacy/cne_vendor_product_noship.mk
---> src:  vendor/qcom/proprietary/cne/cne_vendor_product_noship.mk
<--- dest:  vendor/qcom/defs/product-defs/legacy/cne_vendor_product_noship.mk
======
vendor/qcom/proprietary/cne/cne_vendor_board_noship.mk::vendor/qcom/defs/board-defs/legacy/cne_vendor_board_noship.mk
---> src:  vendor/qcom/proprietary/cne/cne_vendor_board_noship.mk
<--- dest:  vendor/qcom/defs/board-defs/legacy/cne_vendor_board_noship.mk
======
vendor/qcom/proprietary/cne/cne_wqe_vendor_product_noship.mk::vendor/qcom/defs/product-defs/legacy/cne_wqe_vendor_product_noship.mk
---> src:  vendor/qcom/proprietary/cne/cne_wqe_vendor_product_noship.mk
<--- dest:  vendor/qcom/defs/product-defs/legacy/cne_wqe_vendor_product_noship.mk
======
vendor/qcom/proprietary/cne/cne-test_vendor_product.mk::vendor/qcom/defs/product-defs/legacy/cne-test_vendor_product.mk
---> src:  vendor/qcom/proprietary/cne/cne-test_vendor_product.mk
<--- dest:  vendor/qcom/defs/product-defs/legacy/cne-test_vendor_product.mk
======
vendor/qcom/proprietary/data/data_prop_vendor_product.mk::vendor/qcom/defs/product-defs/vendor/data_prop_vendor_product.mk
---> src:  vendor/qcom/proprietary/data/data_prop_vendor_product.mk
<--- dest:  vendor/qcom/defs/product-defs/vendor/data_prop_vendor_product.mk
======
vendor/qcom/proprietary/qmi/qmi_data_vendor_product.mk::vendor/qcom/defs/product-defs/vendor/qmi_data_vendor_product.mk
---> src:  vendor/qcom/proprietary/qmi/qmi_data_vendor_product.mk
<--- dest:  vendor/qcom/defs/product-defs/vendor/qmi_data_vendor_product.mk
======
vendor/qcom/proprietary/qcril-data-hal/datamodule/module/qcril-data-product.mk::vendor/qcom/defs/product-defs/legacy/qcril-data-product.mk
---> src:  vendor/qcom/proprietary/qcril-data-hal/datamodule/module/qcril-data-product.mk
<--- dest:  vendor/qcom/defs/product-defs/legacy/qcril-data-product.mk
======
vendor/qcom/proprietary/nqnfc-firmware/nfc_proprietary_product.mk::vendor/qcom/defs/product-defs/legacy/nfc-proprietary-product.mk
---> src:  vendor/qcom/proprietary/nqnfc-firmware/nfc_proprietary_product.mk
<--- dest:  vendor/qcom/defs/product-defs/legacy/nfc-proprietary-product.mk
======
vendor/nxp/opensource/commonsys/packages/apps/Nfc/nfc_system_product.mk::vendor/qcom/defs/product-defs/legacy/nfc-system-product.mk
---> src:  vendor/nxp/opensource/commonsys/packages/apps/Nfc/nfc_system_product.mk
<--- dest:  vendor/qcom/defs/product-defs/legacy/nfc-system-product.mk
======
vendor/nxp/opensource/halimpl/nfc_vendor_product.mk::vendor/qcom/defs/product-defs/legacy/nfc-vendor-product.mk
---> src:  vendor/nxp/opensource/halimpl/nfc_vendor_product.mk
<--- dest:  vendor/qcom/defs/product-defs/legacy/nfc-vendor-product.mk
======
vendor/qcom/proprietary/ims-ship/ims_vendor_product_noship.mk::vendor/qcom/defs/product-defs/legacy/ims_vendor_product_noship.mk
---> src:  vendor/qcom/proprietary/ims-ship/ims_vendor_product_noship.mk
<--- dest:  vendor/qcom/defs/product-defs/legacy/ims_vendor_product_noship.mk
======
vendor/qcom/proprietary/commonsys-intf/adsprpc_ship/adsprpc_system_product.mk::vendor/qcom/defs/product-defs/system/adsprpc_system_product.mk
---> src:  vendor/qcom/proprietary/commonsys-intf/adsprpc_ship/adsprpc_system_product.mk
<--- dest:  vendor/qcom/defs/product-defs/system/adsprpc_system_product.mk
======
vendor/qcom/proprietary/commonsys-intf/adsprpc_ship/adsprpc_vendor_product.mk::vendor/qcom/defs/product-defs/vendor/adsprpc_vendor_product.mk
---> src:  vendor/qcom/proprietary/commonsys-intf/adsprpc_ship/adsprpc_vendor_product.mk
<--- dest:  vendor/qcom/defs/product-defs/vendor/adsprpc_vendor_product.mk
======
vendor/qcom/proprietary/dspservices_ship/contexthub_system_product.mk::vendor/qcom/defs/product-defs/system/contexthub_system_product.mk
---> src:  vendor/qcom/proprietary/dspservices_ship/contexthub_system_product.mk
<--- dest:  vendor/qcom/defs/product-defs/system/contexthub_system_product.mk
======
vendor/qcom/proprietary/dspservices_ship/chre_system_product.mk::vendor/qcom/defs/product-defs/vendor/chre_system_product.mk
---> src:  vendor/qcom/proprietary/dspservices_ship/chre_system_product.mk
<--- dest:  vendor/qcom/defs/product-defs/vendor/chre_system_product.mk
======
vendor/qcom/proprietary/dspservices_ship/remote_debug_agent_vendor_board.mk::vendor/qcom/defs/board-defs/vendor/remote_debug_agent_vendor_board.mk
---> src:  vendor/qcom/proprietary/dspservices_ship/remote_debug_agent_vendor_board.mk
<--- dest:  vendor/qcom/defs/board-defs/vendor/remote_debug_agent_vendor_board.mk
======
vendor/qcom/proprietary/cv/fastcv/cv_vendor_product.mk::vendor/qcom/defs/product-defs/legacy/cv_vendor_product.mk
---> src:  vendor/qcom/proprietary/cv/fastcv/cv_vendor_product.mk
<--- dest:  vendor/qcom/defs/product-defs/legacy/cv_vendor_product.mk
======
vendor/qcom/proprietary/cv/fastcv/cv_vendor_board.mk::vendor/qcom/defs/board-defs/legacy/cv_vendor_board.mk
---> src:  vendor/qcom/proprietary/cv/fastcv/cv_vendor_board.mk
<--- dest:  vendor/qcom/defs/board-defs/legacy/cv_vendor_board.mk
======
vendor/qcom/proprietary/cv/fastcv/cv_system_product.mk::vendor/qcom/defs/product-defs/legacy/cv_system_product.mk
---> src:  vendor/qcom/proprietary/cv/fastcv/cv_system_product.mk
<--- dest:  vendor/qcom/defs/product-defs/legacy/cv_system_product.mk
======
vendor/qcom/proprietary/securemsm/config/smcinvoke_vendor_proprietary_product.mk::vendor/qcom/defs/product-defs/vendor/smcinvoke_vendor_proprietary_product.mk
---> src:  vendor/qcom/proprietary/securemsm/config/smcinvoke_vendor_proprietary_product.mk
<--- dest:  vendor/qcom/defs/product-defs/vendor/smcinvoke_vendor_proprietary_product.mk
======
vendor/qcom/proprietary/securemsm/config/qseecomd_vendor_proprietary_product.mk::vendor/qcom/defs/product-defs/vendor/qseecomd_vendor_proprietary_product.mk
---> src:  vendor/qcom/proprietary/securemsm/config/qseecomd_vendor_proprietary_product.mk
<--- dest:  vendor/qcom/defs/product-defs/vendor/qseecomd_vendor_proprietary_product.mk
======
vendor/qcom/proprietary/securemsm/config/cpz_vendor_proprietary_board.mk::vendor/qcom/defs/board-defs/vendor/cpz_vendor_proprietary_board.mk
---> src:  vendor/qcom/proprietary/securemsm/config/cpz_vendor_proprietary_board.mk
<--- dest:  vendor/qcom/defs/board-defs/vendor/cpz_vendor_proprietary_board.mk
======
vendor/qcom/proprietary/securemsm/config/cpz_vendor_proprietary_product.mk::vendor/qcom/defs/product-defs/vendor/cpz_vendor_proprietary_product.mk
---> src:  vendor/qcom/proprietary/securemsm/config/cpz_vendor_proprietary_product.mk
<--- dest:  vendor/qcom/defs/product-defs/vendor/cpz_vendor_proprietary_product.mk
======
vendor/qcom/proprietary/securemsm/config/keymaster_vendor_proprietary_board.mk::vendor/qcom/defs/board-defs/vendor/keymaster_vendor_proprietary_board.mk
---> src:  vendor/qcom/proprietary/securemsm/config/keymaster_vendor_proprietary_board.mk
<--- dest:  vendor/qcom/defs/board-defs/vendor/keymaster_vendor_proprietary_board.mk
======
vendor/qcom/proprietary/securemsm/config/keymaster_vendor_proprietary_product.mk::vendor/qcom/defs/product-defs/vendor/keymaster_vendor_proprietary_product.mk
---> src:  vendor/qcom/proprietary/securemsm/config/keymaster_vendor_proprietary_product.mk
<--- dest:  vendor/qcom/defs/product-defs/vendor/keymaster_vendor_proprietary_product.mk
======
vendor/qcom/proprietary/securemsm/config/gp_vendor_proprietary_product.mk::vendor/qcom/defs/product-defs/vendor/gp_vendor_proprietary_product.mk
---> src:  vendor/qcom/proprietary/securemsm/config/gp_vendor_proprietary_product.mk
<--- dest:  vendor/qcom/defs/product-defs/vendor/gp_vendor_proprietary_product.mk
======
vendor/qcom/proprietary/securemsm/config/tloc_vendor_proprietary_product.mk::vendor/qcom/defs/product-defs/vendor/tloc_vendor_proprietary_product.mk
---> src:  vendor/qcom/proprietary/securemsm/config/tloc_vendor_proprietary_product.mk
<--- dest:  vendor/qcom/defs/product-defs/vendor/tloc_vendor_proprietary_product.mk
======
vendor/qcom/proprietary/securemsm/config/qseecom_hal_vendor_proprietary_product.mk::vendor/qcom/defs/product-defs/vendor/qseecom_hal_vendor_proprietary_product.mk
---> src:  vendor/qcom/proprietary/securemsm/config/qseecom_hal_vendor_proprietary_product.mk
<--- dest:  vendor/qcom/defs/product-defs/vendor/qseecom_hal_vendor_proprietary_product.mk
======
vendor/qcom/proprietary/commonsys/securemsm/securemsm_system_product.mk::vendor/qcom/defs/product-defs/system/securemsm_product.mk
---> src:  vendor/qcom/proprietary/commonsys/securemsm/securemsm_system_product.mk
<--- dest:  vendor/qcom/defs/product-defs/system/securemsm_product.mk
======
vendor/qcom/proprietary/commonsys/securemsm/config/gp_system_proprietary_product.mk::vendor/qcom/defs/product-defs/system/gp_system_proprietary_product.mk
---> src:  vendor/qcom/proprietary/commonsys/securemsm/config/gp_system_proprietary_product.mk
<--- dest:  vendor/qcom/defs/product-defs/system/gp_system_proprietary_product.mk
======
vendor/qcom/proprietary/commonsys/securemsm/config/qseecom_lib_system_product.mk::vendor/qcom/defs/product-defs/system/qseecom_lib_system_product.mk
---> src:  vendor/qcom/proprietary/commonsys/securemsm/config/qseecom_lib_system_product.mk
<--- dest:  vendor/qcom/defs/product-defs/system/qseecom_lib_system_product.mk
======
vendor/qcom/proprietary/gps-release/gps_system_product.mk::vendor/qcom/defs/product-defs/system/gps-product.mk
---> src:  vendor/qcom/proprietary/gps-release/gps_system_product.mk
<--- dest:  vendor/qcom/defs/product-defs/system/gps-product.mk
======
vendor/qcom/proprietary/gps-release/gps_system_board.mk::vendor/qcom/defs/board-defs/system/gps-board.mk
---> src:  vendor/qcom/proprietary/gps-release/gps_system_board.mk
<--- dest:  vendor/qcom/defs/board-defs/system/gps-board.mk
======
vendor/qcom/proprietary/gps-release/gps_vendor_product.mk::vendor/qcom/defs/product-defs/vendor/gps-product.mk
---> src:  vendor/qcom/proprietary/gps-release/gps_vendor_product.mk
<--- dest:  vendor/qcom/defs/product-defs/vendor/gps-product.mk
======
vendor/qcom/proprietary/commonsys-intf/bluetooth/bt-vendor-proprietary-board.mk::vendor/qcom/defs/board-defs/legacy/bt-vendor-proprietary-board.mk
---> src:  vendor/qcom/proprietary/commonsys-intf/bluetooth/bt-vendor-proprietary-board.mk
<--- dest:  vendor/qcom/defs/board-defs/legacy/bt-vendor-proprietary-board.mk
======
vendor/qcom/proprietary/commonsys-intf/bluetooth/bt-vendor-proprietary-product.mk::vendor/qcom/defs/product-defs/legacy/bt-vendor-proprietary-product.mk
---> src:  vendor/qcom/proprietary/commonsys-intf/bluetooth/bt-vendor-proprietary-product.mk
<--- dest:  vendor/qcom/defs/product-defs/legacy/bt-vendor-proprietary-product.mk
======
vendor/qcom/proprietary/commonsys-intf/bluetooth/bt-system-proprietary-product.mk::vendor/qcom/defs/product-defs/legacy/bt-system-proprietary-product.mk
---> src:  vendor/qcom/proprietary/commonsys-intf/bluetooth/bt-system-proprietary-product.mk
<--- dest:  vendor/qcom/defs/product-defs/legacy/bt-system-proprietary-product.mk
======
vendor/qcom/opensource/commonsys-intf/bluetooth/bt-commonsys-intf-legacy-board.mk::vendor/qcom/defs/board-defs/legacy/bt-commonsys-intf-legacy-board.mk
---> src:  vendor/qcom/opensource/commonsys-intf/bluetooth/bt-commonsys-intf-legacy-board.mk
<--- dest:  vendor/qcom/defs/board-defs/legacy/bt-commonsys-intf-legacy-board.mk
======
vendor/qcom/opensource/commonsys-intf/bluetooth/bt-system-opensource-product.mk::vendor/qcom/defs/product-defs/legacy/bt-system-opensource-product.mk
---> src:  vendor/qcom/opensource/commonsys-intf/bluetooth/bt-system-opensource-product.mk
<--- dest:  vendor/qcom/defs/product-defs/legacy/bt-system-opensource-product.mk
======
vendor/qcom/proprietary/commonsys/voiceui/app_voiceui_system_product.mk::vendor/qcom/defs/product-defs/system/app_voiceui_product.mk
---> src:  vendor/qcom/proprietary/commonsys/voiceui/app_voiceui_system_product.mk
<--- dest:  vendor/qcom/defs/product-defs/system/app_voiceui_product.mk
======
vendor/qcom/opensource/core-utils/build/QSSI_violators.mk::vendor/qcom/build/tasks/QSSI_violators.mk
---> src:  vendor/qcom/opensource/core-utils/build/QSSI_violators.mk
<--- dest:  vendor/qcom/build/tasks/QSSI_violators.mk
======
vendor/qcom/opensource/core-utils/build.sh::build.sh
---> src:  vendor/qcom/opensource/core-utils/build.sh
<--- dest:  build.sh
======
vendor/qcom/proprietary/qrdplus/PowerOffAlarm/app_poweroffalarm_vendor_product.mk::vendor/qcom/defs/product-defs/vendor/app_poweroffalarm_product.mk
---> src:  vendor/qcom/proprietary/qrdplus/PowerOffAlarm/app_poweroffalarm_vendor_product.mk
<--- dest:  vendor/qcom/defs/product-defs/vendor/app_poweroffalarm_product.mk
======
vendor/qcom/proprietary/commonsys-intf/telephony/build/telephony_vendor_product.mk::vendor/qcom/defs/product-defs/vendor/telephony-product.mk
---> src:  vendor/qcom/proprietary/commonsys-intf/telephony/build/telephony_vendor_product.mk
<--- dest:  vendor/qcom/defs/product-defs/vendor/telephony-product.mk
======
vendor/qcom/proprietary/commonsys-intf/telephony/build/telephony-noship_system_product.mk::vendor/qcom/defs/product-defs/system/telephony-noship-product.mk
---> src:  vendor/qcom/proprietary/commonsys-intf/telephony/build/telephony-noship_system_product.mk
<--- dest:  vendor/qcom/defs/product-defs/system/telephony-noship-product.mk
======
vendor/qcom/proprietary/commonsys-intf/telephony/build/telephony_system_product.mk::vendor/qcom/defs/product-defs/system/telephony-product.mk
---> src:  vendor/qcom/proprietary/commonsys-intf/telephony/build/telephony_system_product.mk
<--- dest:  vendor/qcom/defs/product-defs/system/telephony-product.mk
======
vendor/qcom/proprietary/commonsys-intf/telephony/build/telephony-intf_system_product.mk::vendor/qcom/defs/product-defs/system/telephony-intf-product.mk
---> src:  vendor/qcom/proprietary/commonsys-intf/telephony/build/telephony-intf_system_product.mk
<--- dest:  vendor/qcom/defs/product-defs/system/telephony-intf-product.mk
======
vendor/qcom/proprietary/commonsys-intf/telephony/build/telephony-intf_vendor_product.mk::vendor/qcom/defs/product-defs/vendor/telephony-intf-product.mk
---> src:  vendor/qcom/proprietary/commonsys-intf/telephony/build/telephony-intf_vendor_product.mk
<--- dest:  vendor/qcom/defs/product-defs/vendor/telephony-intf-product.mk
======
vendor/qcom/proprietary/commonsys/cne/cne_commonsys_system_product.mk::vendor/qcom/defs/product-defs/legacy/cne_commonsys_system_product.mk
---> src:  vendor/qcom/proprietary/commonsys/cne/cne_commonsys_system_product.mk
<--- dest:  vendor/qcom/defs/product-defs/legacy/cne_commonsys_system_product.mk
======
vendor/qcom/proprietary/commonsys/cne/cne_system_product_noship.mk::vendor/qcom/defs/product-defs/legacy/cne_system_product_noship.mk
---> src:  vendor/qcom/proprietary/commonsys/cne/cne_system_product_noship.mk
<--- dest:  vendor/qcom/defs/product-defs/legacy/cne_system_product_noship.mk
======
vendor/qcom/proprietary/commonsys/ims-ship/ims_commonsys_system_product.mk::vendor/qcom/defs/product-defs/legacy/ims_commonsys_system_product.mk
---> src:  vendor/qcom/proprietary/commonsys/ims-ship/ims_commonsys_system_product.mk
<--- dest:  vendor/qcom/defs/product-defs/legacy/ims_commonsys_system_product.mk
======
vendor/qcom/proprietary/commonsys/ims-ship/ims-internal_system_product_noship.mk::vendor/qcom/defs/product-defs/legacy/ims-internal_system_product_noship.mk
---> src:  vendor/qcom/proprietary/commonsys/ims-ship/ims-internal_system_product_noship.mk
<--- dest:  vendor/qcom/defs/product-defs/legacy/ims-internal_system_product_noship.mk
======
vendor/qcom/proprietary/commonsys/ims-ship/ims_system_product_noship.mk::vendor/qcom/defs/product-defs/legacy/ims_system_product_noship.mk
---> src:  vendor/qcom/proprietary/commonsys/ims-ship/ims_system_product_noship.mk
<--- dest:  vendor/qcom/defs/product-defs/legacy/ims_system_product_noship.mk
======
vendor/qcom/proprietary/commonsys-intf/data/data_commonsys-intf_board.mk::vendor/qcom/defs/board-defs/legacy/data_commonsys-intf_board.mk
---> src:  vendor/qcom/proprietary/commonsys-intf/data/data_commonsys-intf_board.mk
<--- dest:  vendor/qcom/defs/board-defs/legacy/data_commonsys-intf_board.mk
======
vendor/qcom/proprietary/commonsys-intf/data/data_commonsys-intf_vendor_product.mk::vendor/qcom/defs/product-defs/legacy/data_commonsys-intf_vendor_product.mk
---> src:  vendor/qcom/proprietary/commonsys-intf/data/data_commonsys-intf_vendor_product.mk
<--- dest:  vendor/qcom/defs/product-defs/legacy/data_commonsys-intf_vendor_product.mk
======
vendor/qcom/proprietary/commonsys-intf/data/data_commonsys-intf_system_product.mk::vendor/qcom/defs/product-defs/legacy/data_commonsys-intf_system_product.mk
---> src:  vendor/qcom/proprietary/commonsys-intf/data/data_commonsys-intf_system_product.mk
<--- dest:  vendor/qcom/defs/product-defs/legacy/data_commonsys-intf_system_product.mk
======
vendor/qcom/proprietary/commonsys-intf/data/data_commonsys-intf_system_product_noship.mk::vendor/qcom/defs/product-defs/legacy/data_commonsys-intf_system_product_noship.mk
---> src:  vendor/qcom/proprietary/commonsys-intf/data/data_commonsys-intf_system_product_noship.mk
<--- dest:  vendor/qcom/defs/product-defs/legacy/data_commonsys-intf_system_product_noship.mk
======
vendor/qcom/proprietary/commonsys-intf/data/data_commonsys-intf_vendor_product_noship.mk::vendor/qcom/defs/product-defs/legacy/data_commonsys-intf_vendor_product_noship.mk
---> src:  vendor/qcom/proprietary/commonsys-intf/data/data_commonsys-intf_vendor_product_noship.mk
<--- dest:  vendor/qcom/defs/product-defs/legacy/data_commonsys-intf_vendor_product_noship.mk
======
vendor/qcom/proprietary/mm-camera/mm-camera2/configs/camera_vendor_product.mk::vendor/qcom/defs/product-defs/vendor/camera_vendor_product.mk
---> src:  vendor/qcom/proprietary/mm-camera/mm-camera2/configs/camera_vendor_product.mk
<--- dest:  vendor/qcom/defs/product-defs/vendor/camera_vendor_product.mk
======
vendor/qcom/proprietary/vpp/config/vpp-vendor-board.mk::vendor/qcom/defs/board-defs/legacy/vpp-board.mk
---> src:  vendor/qcom/proprietary/vpp/config/vpp-vendor-board.mk
<--- dest:  vendor/qcom/defs/board-defs/legacy/vpp-board.mk
======
vendor/qcom/proprietary/vpp/config/vpp-vendor-product.mk::vendor/qcom/defs/product-defs/legacy/vpp-product.mk
---> src:  vendor/qcom/proprietary/vpp/config/vpp-vendor-product.mk
<--- dest:  vendor/qcom/defs/product-defs/legacy/vpp-product.mk
======
vendor/qcom/proprietary/configstore/configstore-product.mk::vendor/qcom/defs/product-defs/legacy/configstore-product.mk
---> src:  vendor/qcom/proprietary/configstore/configstore-product.mk
<--- dest:  vendor/qcom/defs/product-defs/legacy/configstore-product.mk
======
vendor/qcom/proprietary/coretech-config-vendor/thermal-engine/thermal-engine_product.mk::vendor/qcom/defs/product-defs/vendor/thermal-engine_product.mk
---> src:  vendor/qcom/proprietary/coretech-config-vendor/thermal-engine/thermal-engine_product.mk
<--- dest:  vendor/qcom/defs/product-defs/vendor/thermal-engine_product.mk
======
vendor/qcom/proprietary/coretech-config-vendor/thermal-hal/thermal-hal_product.mk::vendor/qcom/defs/product-defs/vendor/thermal-hal_product.mk
---> src:  vendor/qcom/proprietary/coretech-config-vendor/thermal-hal/thermal-hal_product.mk
<--- dest:  vendor/qcom/defs/product-defs/vendor/thermal-hal_product.mk
======

参考: linux shell readlink 获取当前脚本文件绝对路径
https://www.it610.com/article/1304474769474752512.htm
linux shell 指令 诸如-d, -f, -e之类的判断表达式简介
https://www.cnblogs.com/zrmw/p/9625727.html
shell 命令之 wc -l
https://www.cnblogs.com/drjava/p/10533649.html
ln 链接文件
https://www.codesocang.com/jquerymobile/linux/2/11.html

addcompletions

    local completion_files=(
      system/core/adb/adb.bash
      system/core/fastboot/fastboot.bash
      tools/asuite/asuite.sh
    )
    # Completion can be disabled selectively to allow users to use non-standard completion.
    # e.g.
    # ENVSETUP_NO_COMPLETION=adb # -> disable adb completion
    # ENVSETUP_NO_COMPLETION=adb:bit # -> disable adb and bit completion
    for f in ${completion_files[*]}; do
        if [ -f "$f" ] && should_add_completion "$f"; then
            . $f
        fi
    done

判断是否有这个文件,或者是否文件属于 ENVSETUP_NO_COMPLETION 中需要进行补全的,然后执行 adb.bash, fastboot.bash, asuite.sh 这些脚本文件。 在tools/asuite/asuite.sh 这个脚本文件中,包含 tradefederation/core/atest/atest_completion.sh,这个文件也会被执行一下。

增加打印,可以看到输出结果:

complete f:  system/core/adb/adb.bash
should add completion:  system/core/adb/adb.bash
0
complete f:  system/core/fastboot/fastboot.bash
should add completion:  system/core/fastboot/fastboot.bash
0
complete f:  tools/asuite/asuite.sh
should add completion:  tools/asuite/asuite.sh
0
should add completion:  /home/ptz/sc200r/SC200R_Android10.0_R04_r023/tools/tradefederation/core/atest/atest_completion.sh
0
should add completion:  bit
0
    complete -F _lunch lunch

    complete -F _complete_android_module_names gomod
    complete -F _complete_android_module_names m

上面是针对 lunch这个命令 使用 _lunch 这个函数进行补全, gomod, m 也是这样。

参考: shell 中 basename 的简单使用
https://blog.51cto.com/sdsca/1903822
使用bash内置命令complete来实现参数补全
https://www.cnblogs.com/lyg-blog/p/14760145.html
使用Bash中Complete自动补全命令
https://blog.csdn.net/chen_fly2011/article/details/56830892

转自: https://blog.csdn.net/u011913612/article/details/51878356

Android编译系统分析系列文章:

android编译系统分析一<source build/envsetup.sh与lunch> Android编译系统<二>-mm编译单个模块 android编译系统分析(三)-make android编译系统(四)-实战:新增一个产品 Android编译系统分析(五)-system.img的生成过程

虽然已经有很多人分析过android的编译系统的代码了,我也看过他们的博客,也学到了不少知识,但单纯的看别人分析,终究还是理解的不深入,所以,我还是要自己再认真的分析一遍。

想想我们编译android系统的过程:

首先:source build/envsetup.sh

其次:lunch ---选择一个特定的类型

最后:make

按着这个顺序,追踪这看似简单的几步,到底有哪些背后的秘密?

- 阅读剩余部分 -

  1. 根据引脚和初始化参数,以及规格书,制作类似于 panel_ili9881c_720p_video.xml 的文件。
  2. 安装必要的软件
    #sudo apt-get install libxml-libxml-perl 
    #sudo apt-get install libxml-perl 
  3. 把 xml 文件放入 device/qcom/common/display/tools 文件夹里面。
  4. perl parser.pl panel_ ili9881c_720p_video.xml panel 生成 dsi-panel-ili9881c-720p-video.dtsipanel_ili9881c_720p_video.h
  5. cp device/qcom/common/display/tools/dsi-panel-ili9881c-720p-video.dtsi kernel/msm-4.9/arch/arm64/boot/dts/qcom cp device/qcom/common/display/tools/panel_ili9881c_720p_video.h bootable/bootloader/lk/dev/gcdb/display/include/
  6. 修改 bootable/bootloader/lk/target/msm8952/oem_panel.c, lk 中的配置用于刚开机后对屏幕的驱动。
  7. 修改 kernel/msm-4.9/arch/arm64/boot/dts/qcom/msm8937-mdss-panels.dtsi kernel/msm-4.9/arch/arm64/boot/dts/qcom/qm215-qrd.dtsi 等文件,用于 kernel 对于 sleep 和 wakeup 时对屏幕的驱动。
  8. 全部修改完后,编译一下,拿到新的 boot.img
    source build/envsetup.sh 
    lunch msm8937_32-userdebug 
    make aboot 
    make kernel 
  9. 根据修改的内容决定具体烧录哪些 img, 正常修改屏幕驱动,只要更新 emmc_appsboot.mbn, boot.img
    adb reboot bootloader
    fastboot flash boot boot.img
    fastboot flash aboot emmc_appsboot.mbn
    fastboot flash dtbo dtbo.img
    fastboot flash dtbobak dtbo.img
    fastboot reboot

  1. 下载 qcom llvm, https://developer.qualcomm.com/software/snapdragon-llvm-compiler-android/tools
  2. 把解压出来的文件复制到asop 内。 类似于 cp $(LLVM_DIR)/toolchains/llvm-Snapdragon_LLVM_for_Android_8.0/prebuilt/linux-x86_64/* $(TOP_DIR)/prebuilts/clang/host/linux-x86/sdclang-8/
  3. 在 BoardConfig.mk 中增加
    # SDClang Config
    ifneq ($(HOST_OS),darwin)
    SDCLANG := true 
    SDCLANG_PATH := prebuilts/clang/host/linux-x86/sdclang-8/bin
    SDCLANG_PATH_2 := prebuilts/clang/host/linux-x86/sdclang-8/bin
    SDCLANG_LTO_DEFS := device/qcom/common/sdllvm-lto-defs.mk
    endif
  4. export 变量
    # export SDCLANG_PATH=prebuilts/clang/host/linux-x86/sdclang-8/bin
    # export SDCLANG_PATH_2=prebuilts/clang/host/linux-x86/sdclang-8/bin

参考

https://developer.qualcomm.com/forum/qdn-forums/software/snapdragon-llvm-compiler-android/68403
https://blog.csdn.net/love_xiaozhao/article/details/89684756
http://bbs.raindi.net/thread-26209-1-1.html
https://blog.csdn.net/qq_23129309/article/details/85225017
https://discuss.96boards.org/t/build-fails-sdclang-path-can-not-be-empty/6669

生成 patch

  • 针对文件的生成 patch

    #只想 patch Test.java 文件
    git diff Test.java > test.patch
    # 把所有的修改文件打成 patch
    git diff > test.patch
  • 针对 commit 生成 patch
    $ git format-patch HEAD^       #生成最近的1次commit的patch
    $ git format-patch HEAD^^      #生成最近的2次commit的patch
    $ git format-patch HEAD^^^     #生成最近的3次commit的patch
    $ git format-patch HEAD^^^^    #生成最近的4次commit的patch
    $ git format-patch <r1>..<r2>  #生成两个commit间的修改的patch(包含两个commit. <r1>和<r2>都是具体的commit号)
    $ git format-patch -1 <r1>     #生成单个commit的patch
    $ git format-patch <r1>        #生成某commit以来的修改patch(不包含该commit)
    $ git format-patch --root <r1> #生成从根到r1提交的所有patch

应用patch

git am 会直接以原 patch 的作者生成 commit, git apply 则需要自己去 commit.

  • 检查 patch

    $ git apply --stat 0001-limit-log-function.patch  # 查看patch的情况
    $ git apply --check 0001-limit-log-function.patch # 检查patch是否能够打上,如果没有任何输出,则说明无冲突,可以打上
  • 应用 patch
    $ git apply xxx.patch
    $ git am 0001-limit-log-function.patch           # 将名字为0001-limit-log-function.patch的patch打上
    $ git am --signoff 0001-limit-log-function.patch # 添加-s或者--signoff,还可以把自己的名字添加为signed off by信息,作用是注明打patch的人是谁,因为有时打patch的人并不是patch的作者
    $ git am ~/patch-set/*.patch                     # 将路径~/patch-set/*.patch 按照先后顺序打上
    $ git am --abort                                 # 当git am失败时,用以将已经在am过程中打上的patch废弃掉(比如有三个patch,打到第三个patch时有冲突,那么这条命令会把打上的前两个patch丢弃掉,返回没有打patch的状态)
    $ git am --resolved                              # 当git am失败,解决完冲突后,这条命令会接着打patch

参考

https://blog.csdn.net/u013318019/article/details/114860407
https://blog.csdn.net/liuhaomatou/article/details/54410361

如果没有正确加载第三方 so 库,编译可以通过,但是一旦运行,就报错,无法找到对应的 so 库。

经过测试,最简单加载第三方 so 库的方法如下,不需要修改 build.gradle:

  • 把 so 库直接放到 app\src\main\jniLibs\armeabi-v7a 目录下面,如果没有目录就创建。

类似如下:

project/
├──libs/
|  └── *.jar       <-- if your library has jar files, they go here
├──src/
   └── main/
       ├── AndroidManifest.xml
       ├── java/
       └── jniLibs/ 
           ├── arm64-v8a/                       <-- ARM 64bit
           │   └── yourlib.so
           ├── armeabi-v7a/                     <-- ARM 32bit
           │   └── yourlib.so
           └── x86/                             <-- Intel 32bit
               └── yourlib.so
  • 重新编译后,验证的方法是把 app\build\outputs\apk\debug 下面的 apk 直接解压,确认 lib 文件夹里面是否有 so 库。

参考

https://stackoverflow.com/questions/24357687/how-to-include-so-library-in-android-studio
https://stackoverflow.com/questions/16683775/include-so-library-in-apk-in-android-studio?rq=1
https://blog.csdn.net/sinat_22657459/article/details/53420047