9阅网

您现在的位置是:首页 > 知识 > 正文

知识

yocto - 如何动态创建一个带有git信息的文件,并将其包含在镜像中并保存在构建系统中。

admin2022-11-07知识19

我们有几个开发人员在做一个项目。 我们关注的领域(而且我们经常修改)是内核、我们的自定义代码和yocto空间本身。

我们想在这个过程中的某个时刻(do_fetch,或者do_install?)创建一个文件,包含正在构建的信息。 比如上面每个仓库的git分支名和哈希值。 然后,我们会将该文件(或需要时的文件)安装到镜像上,并将其归档到一个集中的服务器上。

我知道这些信息在buildhistory中是可用的,但我不确定当我们要安装和打包时,这些信息是否在那里。

通过recipe函数中的shell命令来获取分支和哈希应该很容易。

在我去黑掉一些东西之前,我想我应该问一下是否有一个标准的方法来做类似的事情。

谢谢!我们有几个开发人员正在做一个项目。



【回答】:

以防你需要包含自定义信息。一个很好的方法是创建一个自定义层bbclass,定义如下。

DEPENDS += "git-native"

do_rootfs_save_versions() {
    #Do custom tasks here like getting layer names and linked SHA numbers
    #Store these information in a file and deploy it in ${DEPLOY_DIR_IMAGE}
}

ROOTFS_POSTPROCESS_COMMAND += "do_rootfs_save_versions;"

然后,在你的图片文件中加入bbclass。

IMAGE_CLASSES += "<bbclass_name>"

当你想确定目标上运行的图层版本名称时,它非常有用。

【回答】:

好的,这是我做的。

在我想跟踪的do_install函数上添加了附录,并把它们放在build dir的顶部。

do_install_append () {
 echo ${SRCPV} > ${TOPDIR}/kernel_manifest.txt
 git rev-parse --abbrev-ref HEAD >> ${TOPDIR}/kernel_manifest.txt
}

在元目录下添加了一个新的bbclass。

DEPENDS += "git-native"

do_rootfs_save_manifests[nostamp] = "1"
do_rootfs_save_manifests() {

    date  > ${TOPDIR}/buildinfo.txt
    hostname >> ${TOPDIR}/buildinfo.txt
    git config user.name >> ${TOPDIR}/buildinfo.txt
    cp ${TOPDIR}/buildinfo.txt ${IMAGE_ROOTFS}/usr/custom_space/

    if [ ! -f ${TOPDIR}/kernel_manifest.txt ]; then
       echo "kernel_manifest empty:  Rebuild or run cleanall on it's recipe" >    ${TOPDIR}/error_kernel_manifest.txt
       cp  ${TOPDIR}/error_kernel_manifest.txt ${IMAGE_ROOTFS}/usr/custom_space/
    else
       cp  ${TOPDIR}/kernel_manifest.txt ${IMAGE_ROOTFS}/usr/custom_space/
       if [ -f ${TOPDIR}/error_kernel_manifest.txt ]; then
           rm ${TOPDIR}/error_kernel_manifest.txt
       fi

    fi

    if [ ! -f ${TOPDIR}/buildhistory/metadata-revs ]; then
       echo " metadata_revs empty:  Make sure INHERIT += \"buildhistory\" and" > ${TOPDIR}/error_yocto_manifest.txt
       echo " BUILDHISTORY_COMMIT = "1" are in your local.conf " >> ${TOPDIR}/error_yocto_manifest.txt
       cp  ${TOPDIR}/error_yocto_manifest.txt ${IMAGE_ROOTFS}/usr/custom_space/

    else
       if [ -f ${TOPDIR}/error_yocto_manifest.txt ]; then
           rm ${TOPDIR}/error_yocto_manifest.txt
       fi
       cp  ${TOPDIR}/buildhistory/metadata-revs ${TOPDIR}/yocto_manifest.txt
       cp  ${TOPDIR}/buildhistory/metadata-revs ${IMAGE_ROOTFS}/usr/custom_space/yocto_manifest.txt
    fi

}

ROOTFS_POSTPROCESS_COMMAND += "do_rootfs_save_manifests;"

在我们想使用的图像配方中添加了以下几行内容。

IMAGE_CLASSES += "manifest"
inherit ${IMAGE_CLASSES}

谢谢你的帮助!