【问题标题】:Listing SRC_URI of all packages/files needed to build Yocto image列出构建 Yocto 映像所需的所有包/文件的 SRC_URI
【发布时间】:2022-01-19 20:52:03
【问题描述】:

我想列出在我烘焙图像时 bitbake 将获取的所有文件。

目前,我可以通过执行bitbake core-image-minimal -c fetchall 获取烘焙 Yocto 映像所需的所有文件的 SRC_URI,然后解析日志文件。

有没有更简单的方法来获得相同的结果而无需下载文件?

我不确定 bitbake 是否支持此类功能。理想情况下,我正在寻找一个打印出包名称并列出所有具有相应 URL 的文件的命令

> bitbake core-image-minimal -c fetchall --print-only

【问题讨论】:

  • SuperUser superuser.com/questions/977100/… 上列出了一个类似的问题目前没有答案,但如果在这里找到一个好的答案,它可能也适合那里。

标签: yocto bitbake


【解决方案1】:

一般bitbake不提供这样的功能。

但我能够创建一个简单的解决方案,通过将其添加到 local.conf 文件中创建简单的 .bbclass 文件,该文件在所有配方中都继承,请参阅我存档的步骤:

步骤:

  1. 让我们创建一个类 print-src.bbclass 文件用于获取和打印 SRC_URI 变量(请记住将此类文件存储在 conf/bblayers 中可用的层中.conf):

    $ cat print-src.bbclass
    
    python do_print_src () {
        # should probably be indented
        srcuri = d.getVar('SRC_URI', True).split()
        bb.warn("SRC_URI look like: %s" % srcuri)
    }
    
    addtask do_print_src before do_fetch
    
  2. INHERIT += "print-src" 添加到您的 conf/local.conf 文件中

编辑: 使用 bitbake --runonly 选项很重要,它允许为指定目标运行任务图的特定任务(使用 -- runonly 选项do_print_src 需要作为print_src),

编辑:请注意,--runall=RUNALL--runonly=RUNONLY 是在 Yocto Sumo release 2.5 中引入的,

$ bitbake core-image-minimal --runonly print_src
Loaded 1236 entries from dependency cache.
NOTE: Resolving any missing task queue dependencies

Build Configuration:
BB_VERSION           = "1.37.0"
BUILD_SYS            = "x86_64-linux"
NATIVELSBSTRING      = "universal-4.8"
TARGET_SYS           = "i586-poky-linux"
MACHINE              = "qemux86"
DISTRO               = "poky"
DISTRO_VERSION       = "2.5"
TUNE_FEATURES        = "m32 i586"
TARGET_FPU           = ""
meta                 
meta-poky            
meta-yocto-bsp       = "master:13cc30cd7de4841990b600e83e1249c81a5171dd"

Initialising tasks: 100% |##########################################################################################################################################################################| Time: 0:00:00
NOTE: Executing RunQueue Tasks
WARNING: ptest-runner-2.2+gitAUTOINC+49956f65bb-r0 do_print_src: SRC_URI look like: ['git://git.yoctoproject.org/ptest-runner2']
WARNING: grep-3.1-r0 do_print_src: SRC_URI look like: ['http://ftp.gnu.org/gnu/grep/grep-3.1.tar.xz', 'file://0001-Unset-need_charset_alias-when-building-for-musl.patch']
...
... 
NOTE: Tasks Summary: Attempted 201 tasks of which 0 didn't need to be rerun and all succeeded.

Summary: There were 202 WARNING messages shown.

请查看示例警告输出日志行:

警告: ptest-runner-2.2+gitAUTOINC+49956f65bb-r0 do_print_src:SRC_URI 看起来像:['git://git.yoctoproject.org/ptest-runner2']。

【讨论】:

  • 非常有趣的解决方案,但我没有获得构建映像所需的所有包的 SRC_URI。有什么想法吗?
  • 我不确定 100%,但看起来有些任务被缓存了。你能 rm tmp/ssache/ 并缓存目录吗,那么我认为类应该在所有依赖的食谱中打印 SRC_URI。
  • 是的,我在干净的工作区尝试了bitbake my-image -c do_print_src
  • 你是对的,对于没有 SRC_URI 的食谱(如 core-image-minimal),这个解决方案只是运行单个目标并完成 - 目前我不知道如何force bitbake 运行所有依赖链任务。我试着纠正这个。但是请尝试使用 world 目标 $ bitbake world -c do_print_src 这实际上是为每个食谱打印 SRC_URI。
  • @Bechir 在使用没有 SRC_URI 的配方时,我能够解决没有输出的问题。请看我编辑的帖子。
【解决方案2】:

我修补了 poky 以在 downloads 中创建 *.src 文件,其中包含包的有效获取 URL。

 bitbake/lib/bb/fetch2/__init__.py | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py
index b853da30bd..03e84e0919 100644
--- a/bitbake/lib/bb/fetch2/__init__.py
+++ b/bitbake/lib/bb/fetch2/__init__.py
@@ -1257,16 +1257,16 @@ class FetchData(object):

         # Note: .done and .lock files should always be in DL_DIR whereas localpath may not be.
         if self.localpath and self.localpath.startswith(dldir):
-            basepath = self.localpath
+            self.basepath = self.localpath
         elif self.localpath:
-            basepath = dldir + os.sep + os.path.basename(self.localpath)
+            self.basepath = dldir + os.sep + os.path.basename(self.localpath)
         elif self.basepath or self.basename:
-            basepath = dldir + os.sep + (self.basepath or self.basename)
+            self.basepath = dldir + os.sep + (self.basepath or self.basename)
         else:
              bb.fatal("Can't determine lock path for url %s" % url)

-        self.donestamp = basepath + '.done'
-        self.lockfile = basepath + '.lock'
+        self.donestamp = self.basepath + '.done'
+        self.lockfile = self.basepath + '.lock'

     def setup_revisions(self, d):
         self.revisions = {}
@@ -1607,6 +1607,15 @@ class Fetch(object):
             m = ud.method
             localpath = ""

+            p = "%s.src"%ud.basepath
+            d = os.path.dirname(p)
+            if d != '':
+                bb.utils.mkdirhier(d)
+            with open(p, 'wb') as f:
+                data = "%s" % ud.url
+                f.write(bytes(data, 'ASCII'))
+            return True
+
             if ud.lockfile:
                 lf = bb.utils.lockfile(ud.lockfile)

运行bitbake core-image-minimal -c fetchall 结果:

$> find downloads/ -name '*.src' | head -n 5
downloads/lzop-1.03.tar.gz.src
downloads/libtheora-1.1.1.tar.bz2.src
downloads/mpfr-3.1.5.tar.xz.src
downloads/makedevs.c.src
downloads/expat-2.2.0.tar.bz2.src

这不是一个最佳解决方案,但我希望这样的功能能够进入主流。

【讨论】:

    【解决方案3】:

    我需要这样的东西,并且在此之前已经成功了。

    我可以通过执行以下命令生成一个混乱的 URI 列表:

    bitbake -g zlib && cat recipe-depends.dot | \
    grep -v -e '-native' | grep -v digraph | \
    grep -v -e '-image' | awk '{print $1}' | \
    sort | uniq | xargs -I {} -t bitbake -e {} | grep SRC_URI=
    

    这为您提供了配方和一些 cmets 中使用的所有 URI 和文件。

    不是一个完美的解决方案,但我会看看我是否可以改进它。

    【讨论】:

      【解决方案4】:

      有点手动和直接的方法是从头开始构建您的图像,并复制所有获取日志,然后通过它。

      $ mkdir fetch_logs
      $ find tmp/work/ -type f -name log.do_fetch*  | cpio -pdm fetch_logs
      

      现在在这个 fetch_logs 中 grep “Fetch(ing/er)”,它将提供有关您的配方用于获取源的 URL 的信息。这将有助于查看用于在基于 PREMIRROR 的构建中获取的最终 URI。

      注意:如果您启用了 sstate-cache 且功能正常,您可能根本看不到 do_fetch。

      【讨论】:

        【解决方案5】:

        我根据问题中的解决方案编写了脚本。 基本上我需要为所有源创建一个 cscope 项目,因此我需要列出所有 URI 并克隆所有 repos。 我写了 2 个脚本 1) 列出所有 SRC_URI 和分支 2) 在一个目录中安装(克隆)所有代码

        listURI.sh

        #!/bin/bash
        TMP_FILE="___x__2242230p.txt"
        SRCH_FILE="log.do_fetch"
        TIME=$(date +%Y-%m-%d-%H-%M)
        OUT_FILE="Project-$TIME.txt"
        DEF_BRANCH="master"
        BRANCH=""
        SRC_URI=""
        
        function usage {
            echo "Usage : $0 < -f | -g > <Component-List-file>"
            echo "Options :"
            echo "        -f    : Run bitbake fetch and collect URI"
            echo "        -g    : Get URI from Already fetched Project"
        }
        
        if [ $# -eq 0 ]
        then
            usage
            exit
        fi
        
        if [ "$1" == "-f" ] || [ "$1" == "-g" ];then
            if [ "$1" == "-f" ] && [  -z "$2" ];then
                echo "Should pass Project-Name after -f Option"
                exit
            fi
        else
            echo "Unknown Option"
            usage
            exit
        fi
        POKYROOTDIR=`basename "$PWD"`
        #echo $POKYROOTDIR
        if [[ $POKYROOTDIR != "build" ]];then
            echo "You are not on poky/build (Sourced Poky) Directory"
            exit 0
        fi
        POKYROOTDIR=$PWD
        
        if [ "$1" == "-f" ];then
            echo "Running === bitbake -c fetchall $2 -f --no-setscene =="
             bitbake -c fetchall $2 -f --no-setscene
        fi
        
        if [ "$1" == "-g" ];then
            if [ ! -d tmp/work ];then
                echo " Please run == bitbake -c fetchall <image> -f --no-setscene == before this"
                usage
                exit
            fi
        fi
        
        echo "Looking for URIs --- It may take couple of minuites!"
        
        rm -rf $OUT_FILE
        cd tmp/work
        find . -name $SRCH_FILE -exec grep -i 'DEBUG: For url git' {} \; -print > $POKYROOTDIR/$TMP_FILE
        cd $POKYROOTDIR
        
        while IFS= read -r line
        do
              #echo "$line"
              BRANCH=$(echo $line | awk -F"branch=" '/branch=/{print $2}' | sed -e 's/;/ /' | awk '{print $1}')
              SRC_URI=$(echo $line | cut -d';' -f1-1 | awk -F"url" '/url/{print $2}' | awk '{print $1}' | sed -e 's/git:/ssh:/')
        
              if [ ! -z "$BRANCH" ] && [ ! -z "$SRC_URI" ];then
                  echo "$BRANCH  $SRC_URI" >> $OUT_FILE
              elif [ ! -z "$SRC_URI" ];then
                  echo "$DEF_BRANCH  $SRC_URI" >> $OUT_FILE
              fi
        
            if [ ! -z "$BRANCH" ];then
              echo "Found URI : BRANCH:$BRANCH URI:$SRC_URI"
            elif [ ! -z "$SRC_URI" ];then
                echo "Found URI : BRANCH:Default URI:$SRC_URI"
            fi
              #echo "$BRANCH  $SRC_URI" >> $OUT_FILE
        done < "$TMP_FILE"
        
        #echo "=================== OUT PUT ==========================="
        #cat $OUT_FILE
        
        rm -rf $TMP_FILE
        
        
        echo "----------------INFO-----------------"
        echo "Project Creation: Success"
        echo "Project Path      : $POKYROOTDIR"
        echo "Project file      : $OUT_FILE"
        
        echo "-------------------------------------"
        

        installURI.sh

        #!/bin/bash
        
        function usage {
            echo "Usage : $0 <List-file>"
        }
        
        if [ $# -eq 0 ]
        then
            usage
            exit
        fi
        
        if [ -z "$1" ];then
            usage
            exit
        fi
        
        
        if [ ! -z "$(ls -A $PWD)" ]; then
            echo "Directory ($PWD) must be Empty.... else it will mess up project creation"
            exit
        fi
        
        if [ ! -f $1 ];then
            echo "list file ($1) not found"
            usage
            exit
        fi
        
        filename=$1
        while read -r line; do
            name="$line"
            echo "Fetching Projects"
            git clone -b $line
        done < "$filename"
        
        echo "----------------INFO-----------------"
        echo "Project Creation: Success"
        echo "Project Path    : $PWD"
        echo "-------------------------------------"
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-11-28
          • 1970-01-01
          • 2020-03-12
          • 2018-01-02
          • 1970-01-01
          • 1970-01-01
          • 2017-10-11
          • 1970-01-01
          相关资源
          最近更新 更多