三、soong_ui.bash脚本

一、android build system编译系统概述
二、envsetup.sh脚本(Android10)
三、soong_ui.bash脚本
四、soong_ui的main.go
五、kati中调用main.mk
六、make目录中的main.mk
七、AndroidProducts.mk
八、module-info.json
九、子模块的执行


soong_ui.bash调用地方

soong_ui.bash替代了make命令,作为编译开始的入口

这里只探讨soong_ui.bashbuild目录中引用的地方。

soong_ui.bash在envsetup.sh中的调用

soong_ui.bash在main.mk中的调用

这里调用更多是用来保证makefile通过kati执行的,而不是通过make命令执行。

soong_ui.bash在其他地方的调用

config.mksoong.bash\bootstrap.bash中没啥实际意义,作为字符串中的内容出现

soong_ui.bash分析

soong_ui的调用顺序

/build/soong/soong_ui.bash

经过省略的soong_ui.bash伪代码:

#!/bin/bash -eu
...
# Save the current PWD for use in soong_ui
export ORIGINAL_PWD=${PWD}
export TOP=$(gettop)
source ${TOP}/build/soong/scripts/microfactory.bash

soong_build_go soong_ui android/soong/cmd/soong_ui

cd ${TOP}
exec "$(getoutdir)/soong_ui" "$@"

可以看出soong_ui.bash主要逻辑是三部分

  • source ${TOP}/build/soong/scripts/microfactory.bash
  • soong_build_go soong_ui android/soong/cmd/soong_ui
  • exec "$(getoutdir)/soong_ui" "$@"
/build/soong/scripts/microfactory.bash

source ${TOP}/build/soong/scripts/microfactory.bash

主要是为shell函数soong_build_go调用做准备

具体逻辑如下:

# Bootstrap microfactory from source if necessary and use it to build the
# requested binary.
#
# Arguments:
#  $1: name of the requested binary
#  $2: package name
function soong_build_go
{
    BUILDDIR=$(getoutdir) \
      SRCDIR=${TOP} \
      BLUEPRINTDIR=${TOP}/build/blueprint \
      EXTRA_ARGS="-pkg-path android/soong=${TOP}/build/soong -pkg-path github.com/golang/protobuf=${TOP}/external/golang-protobuf" \
      build_go $@
}

source ${TOP}/build/blueprint/microfactory/microfactory.bash

从注释看看,第一参数是生产的bin文件的名字,第二个参数是包的名字

其中source ${TOP}/build/blueprint/microfactory/microfactory.bash是为了调用build_go这个shell函数做准备

/build/blueprint/microfactory/microfactory.bash

microfactory.bash中定义了build_go函数

代码如下:

# Set of utility functions to build and run go code with microfactory
#
# Inputs:
#  ${GOROOT}
#  ${BUILDDIR}
#  ${BLUEPRINTDIR}
#  ${SRCDIR}

# Bootstrap microfactory from source if necessary and use it to build the
# requested binary.
#
# Arguments:
#  $1: name of the requested binary
#  $2: package name
#  ${EXTRA_ARGS}: extra arguments to pass to microfactory (-pkg-path, etc)
function build_go
{
    # Increment when microfactory changes enough that it cannot rebuild itself.
    # For example, if we use a new command line argument that doesn't work on older versions.
    local mf_version=3

    local mf_src="${BLUEPRINTDIR}/microfactory"
    local mf_bin="${BUILDDIR}/microfactory_$(uname)"
    local mf_version_file="${BUILDDIR}/.microfactory_$(uname)_version"
    local built_bin="${BUILDDIR}/$1"
    local from_src=1

    if [ -f "${mf_bin}" ] && [ -f "${mf_version_file}" ]; then
        if [ "${mf_version}" -eq "$(cat "${mf_version_file}")" ]; then
            from_src=0
        fi
    fi

    local mf_cmd
    if [ $from_src -eq 1 ]; then
        # `go run` requires a single main package, so create one
        local gen_src_dir="${BUILDDIR}/.microfactory_$(uname)_intermediates/src"
        mkdir -p "${gen_src_dir}"
        sed "s/^package microfactory/package main/" "${mf_src}/microfactory.go" >"${gen_src_dir}/microfactory.go"

        mf_cmd="${GOROOT}/bin/go run ${gen_src_dir}/microfactory.go"
    else
        mf_cmd="${mf_bin}"
    fi

    rm -f "${BUILDDIR}/.$1.trace"
    # GOROOT must be absolute because `go run` changes the local directory
    GOROOT=$(cd $GOROOT; pwd) ${mf_cmd} -b "${mf_bin}" \
            -pkg-path "github.com/google/blueprint=${BLUEPRINTDIR}" \
            -trimpath "${SRCDIR}" \
            ${EXTRA_ARGS} \
            -o "${built_bin}" $2

    if [ $? -eq 0 ] && [ $from_src -eq 1 ]; then
        echo "${mf_version}" >"${mf_version_file}"
    fi
}

build_go结合上面提到的soong_build_go,我们就可以进行下一步:

展开soong_build_go soong_ui android/soong/cmd/soong_ui

展开soong_build_go soong_ui android/soong/cmd/soong_ui

结合上面的分析,我们可以得到如下展开结果:

$(cd prebuilts/go/linux-x86/;pwd) \
prebuilts/go/linux-x86/bin/go run \
out/.microfactory_Linux_intermediates/src/microfactory.go \
-b out/microfactory_Linux\
-pkg-path "github.com/google/blueprint=build/blueprint"
-trimpath "${TOP}" \
-pkg-path "android/soong=${TOP}/build/soong" \
-pkg-path "github.com/golang/protobuf=${TOP}/external/golang-protobuf" \
-o out/soong_ui \
android/soong/cmd/soong_ui

-pkg-path参数指定了对包的路径

比如-pkg-path "android/soong=${TOP}/build/soong会将最后一个参数android/soong/cmd/soong_ui变为${TOP}/build/soong/cmd/soong_ui

${TOP}/build/soong/cmd/soong_ui路径下的main.go即为soong入口

最后被调用的soong_ui命令

exec "$(getoutdir)/soong_ui" "$@"执行soong_ui命令

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值