android - AOSP项目是如何构建的?

标签 android go android-source android-soong

AOSP 的所有 git 项目都由 repo 工具克隆,该工具读取以下 xml:https://android.googlesource.com/platform/manifest/+/refs/heads/master/default.xml .
AOSP guide说为了构建,我们应该运行source build/envsetup.sh在 repo 克隆所有存储库的文件夹上。那么我们来看看platform/build在 list 存储库中的 default.xml 上。我们得到

  <project path="build/make" name="platform/build" groups="pdk" >
    <copyfile src="core/root.mk" dest="Makefile" />
    <linkfile src="CleanSpec.mk" dest="build/CleanSpec.mk" />
    <linkfile src="buildspec.mk.default" dest="build/buildspec.mk.default" />
    <linkfile src="core" dest="build/core" />
    <linkfile src="envsetup.sh" dest="build/envsetup.sh" />
    <linkfile src="target" dest="build/target" />
    <linkfile src="tools" dest="build/tools" />
  </project>
我们确认在哪里envsetup.sh is located. , 它在 platform/build .它定义了函数 m根据 AOSP 指南,构建整个 AOSP 项目:
function _trigger_build()
(
    local -r bc="$1"; shift
    if T="$(gettop)"; then
      _wrap_build "$T/build/soong/soong_ui.bash" --build-mode --${bc} --dir="$(pwd)" "$@"
    else
      echo "Couldn't locate the top of the tree. Try setting TOP."
    fi
)
function m()
(
    _trigger_build "all-modules" "$@"
)
好的,看起来像 build/soong/soong_ui.bash是我们运行 m 时调用的地方函数,所以这个脚本应该构建一切。
这里是 soong_ui.bash .来源 source ${TOP}/build/soong/scripts/microfactory.bash然后调用soong_build_go soong_ui android/soong/cmd/soong_ui这里是 microfactory.bash , 我们在哪里找到函数 soong_build_go
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 $@
}
我们找到 build_gomicrofactory.bash from build/blueprint :
看起来所有这些都是为了构建 microfactory.go项目。我认为这与宋构建系统有关。
我现在迷路了。构建 microfactory.go 后,会发生什么?实际的 Android 代码在哪里构建?
microfactory.sh 说 build_go 这样做:Bootstrap microfactory from source if necessary and use it to build the requested binary.请求的二进制文件是 android/soong/cmd/soong_ui我正在寻找 android/soong/cmd/soong_ui但我不知道它是什么/在哪里,但我猜是很快的构建系统,而不是 AOSP 项目。
更新:
soong_ui.bash ,我注意到它以
cd ${TOP}
exec "$(getoutdir)/soong_ui" "$@"
请记住,这称为表单 envsetup.sh .好吧,${TOP} ,我猜,是 repo 克隆一切的地方。看起来它正在尝试执行 soong_ui来自 envsetup.sh 的参数是--build-mode --${bc} --dir="$(pwd)" "$@" , 其中 $@ "all-modules" "$@" , 我猜。
我假设 song_ui是很快的可执行文件。它应该寻找 Android.bp${TOP} ,但我认为在 repo 克隆所有内容的地方没有一个。

最佳答案

你已经发现了很多,你是对的,来自 m 的链接至soong_ui.bash然后开始 microfactory .
根据我对代码的阅读,soong_build_go 的目的是构建包android/soong/cmd/soong_ui , 二进制名称为 soong_ui .就像 Yong 在另一个答案中所说的那样,这会创建二进制 soong_ui目录下 $(getoutdir) ,并且该二进制文件的源位于 build/soong/cmd/soong_ui/main.go .
至于您关于 Android.bp 的更新问题文件,它是 symlinked来自 build/soong/root.bp repo sync已运行,但如您所见,该文件为空。
相反,在 m它告诉宋建 all_modules ,最终运行另一个名为 kati 的工具.来自 https://github.com/google/kati 中的描述, Kati 处理 GNU makefile 并将它们转换为 Ninja构建文件。
在这一点上,我们可以(大部分)假设常规 Make 语义,即使底层构建系统实际上是 Kati 和 Ninja 和 Soong 等。因为工作目录是 $TOP , Makefile位于根目录,符号链接(symbolic link)自 build/make/core/root.mk 用来。其中包括 main.mk 然后包括build/make/core/Makefile .在该 makefile 中,您可以看到不同的 .img文件被构建(例如 system.img )。

关于android - AOSP项目是如何构建的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65450678/

相关文章:

docker - Docker Go SDK ContainerExecAttach返回时间戳

android - AOSP Marshmallow 修改/设置默认权限

android - 无法在android系统应用程序中导入(导入com.android.internal.statusbar)语句

android - 将自定义 etc 文件添加到 aosp build

java - 震动检测计数器

android - 增强现实框架

android - Firebase 测试实验室 : ClassNotFoundException: Didn't find class "android.support.test.runner.AndroidJUnitRunner"

android - 如何在 WebView 中加载 HTML 页面时显示进度对话框

go - 如何在 golang 的所有包中访问全局常量?

java - Java 和 Go 中不同的 CRC32 值