列出构建Yocto映像所需的所有软件包/文件的SRC_URI

4
我希望能列出所有在烘焙映像时bitbake将提取的文件。
目前,我能够通过执行bitbake core-image-minimal -c fetchall并解析日志文件来获得制作Yocto镜像所需的所有文件的SRC_URI。
是否有一种更简单的方法可以获得相同的结果而无需下载文件?
我不确定bitbake是否支持这样的功能。理想情况下,我正在寻找一个命令,它打印出包名称并列出所有文件及其相应的URL。
> bitbake core-image-minimal -c fetchall --print-only

这个与之类似的问题已经在SuperUser上发布了 https://superuser.com/questions/977100/yocto-bitbake-list-of-files-which-are-to-download-in-the-build-process ,目前还没有答案,但如果在这里找到一个好的答案,那么也许适用于那里。 - TafT
5个回答

12

一般来说,bitbake并不提供这样的功能。

但是,我能够创建一个简单的解决方案,通过创建一个简单的.bbclass文件,并将其添加到local.conf文件中,使其在所有配方中继承。请按照以下步骤进行操作:

步骤:

  1. let's create a class print-src.bbclass file used to get and print SRC_URI variable (remember to store this class file in layer which is available in 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. Add INHERIT += "print-src" into Your conf/local.conf file

编辑:重要的是使用bitbake --runonly选项,它允许运行指定目标的任务图中的特定任务(使用--runonly选项,do_print_src需要用作print_src)。 编辑:请注意,--runall=RUNALL--runonly=RUNONLY是在Yocto Sumo 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。有什么想法吗? - Bechir
我不是100%确定,但似乎有些任务被缓存了。 你能否删除tmp/ ssache/和cache目录,然后我认为类应该在所有依赖配方中打印SRC_URI。 - lukaszgard
你说得对,对于没有SRC_URI(例如core-image-minimal)的配方,这个解决方案只需要运行单个目标并完成 - 目前我不知道如何_强制_ bitbake 运行所有依赖链任务。我希望尝试纠正这个问题。但请尝试使用world目标_$ bitbake world -c do_print_src_,它实际上会为每个配方打印SRC_URI。 - lukaszgard
1
@Bechir,我能够解决没有输出的问题,而在使用没有SRC_URI的recipe的时候。请看一下我编辑过的文章。 - lukaszgard
使用nostamp功能,我们可以避免缓存依赖。do_print_src[nostamp] = "1" - evk1206
显示剩余4条评论

2
我修改了poky,使其在downloads中创建包含有效获取URL的*.src文件。
 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

这不是最佳解决方案,但我希望这种功能能够被纳入主流流程中。

1
我需要这样的东西,之前已经有了一部分。我可以通过执行以下命令生成混乱的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=

这将为您提供食谱中使用的所有URI和文件以及一些注释。

虽然不是完美的解决方案,但我会看看能否改进它。


1
一种比较繁琐的方法是从头开始构建您的镜像,并复制所有提取日志,然后进行查看。
$ 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。


0

我根据问题的解决方案编写了脚本。 基本上,我需要创建所有源的cscope项目,因此需要列出所有URI并克隆所有存储库。 我编写了两个脚本: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 "-------------------------------------"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接