简体   繁体   English

Yocto:在图像配方中创建符号链接

[英]Yocto: create a symlink in an image recipe

I have a custom Yocto 'image' recipe, that uses IMAGE_INSTALL += "... " to construct the image, which also contains Python 3.5. 我有一个自定义的Yocto“图像”配方,它使用IMAGE_INSTALL += "... "来构造图像,该图像也包含Python 3.5。 Unfortunately, the often-used /usr/bin/pdb symlink is not created, and my users expect to be able to run pdb from the command line. 不幸的是,没有创建经常使用的/usr/bin/pdb符号链接,我的用户希望能够从命令行运行pdb So I want to make a single symlink for this, within the image. 所以我想在图像中为此做一个符号链接。 If it were run on the target, it would be the result of this command: 如果在目标上运行,它将是以下命令的结果:

ln -s /usr/lib/python3.5/pdb.py /usr/bin/pdb

I understand I can create a custom task in the image recipe with this sort of construct: 我知道我可以使用这种结构在图像配方中创建自定义任务:

addtask create_pdb_symlink before do_image
do_create_pdb_symlink () {
    ln -s /usr/lib/python3.5/pdb.py ${D}/usr/bin/pdb
}

However this doesn't work because I'm guessing at using ${D} , and I don't think the filesystem is staged at that point. 但是,这是行不通的,因为我正在猜测要使用${D} ,而且我认为文件系统此时还没有上演。 It generates this error: 它生成此错误:

DEBUG: Executing shell function do_create_pdb_symlink
ln: failed to create symbolic link 
'/home/user/project/build/tmp/work/custom-linux/my-image/1.0-r0/image/usr/bin/pdb': No such file or directory
WARNING: exit code 1 from a shell command.

Inspecting the filesystem confirms that /home/user/project/build/tmp/work/custom-linux/ exists, but /home/user/project/build/tmp/work/custom-linux/my-image does not. 检查文件系统会确认/home/user/project/build/tmp/work/custom-linux/存在,但/home/user/project/build/tmp/work/custom-linux/my-image不存在。

There are some directories in that custom-linux directory, one of which is called rootfs and looks suspiciously useful, but I'm not sure if my task should be poking around below the my-image directory. custom-linux目录中有一些目录,其中一个称为rootfs ,看起来可疑有用,但是我不确定我的任务是否应该在my-image目录下浏览。

So my questions are: 所以我的问题是:

  • is this the right approach? 这是正确的方法吗?
  • or should I create a brand new recipe just to construct this single symlink? 还是应该创建一个全新的配方来构建这个单一的符号链接?
  • or should I create a python3-core.bbappend to do this task? 还是应该创建一个python3-core.bbappend来执行此任务?
  • or is there a reason why this isn't being created by the python recipe itself? 还是有一个原因为什么它不是由python食谱本身创建的?

Since this symlink is clearly related to python3 I would recommend that you create it using a bbappend for that recipe. 由于此符号链接显然与python3有关,因此我建议您使用该食谱的bbappend创建它。 The recipe name is python3_(version).bb, so to catch all versions name the bbappend python3_%.bbappend. 配方名称为python3_(version).bb,因此要捕获所有版本,请将其命名为bbappend python3 _%。bbappend。

This should work: 这应该工作:

# Create symlink at the end of do_install
do_install_append() {
    ln -sf /usr/lib/python3.5/pdb.py ${D}/usr/bin/pdb
}

# Include the symlink in the python3-debugger package
FILES_${PN}-debugger += "/usr/bin/pdb"

You can also create symlink as the stage where the whole rootfs is created, but in this case I would not recommend it. 您也可以将symlink创建为创建整个rootfs的阶段,但是在这种情况下,我不建议这样做。 But if you have something so need to do when the whole rootfs is populated look into using ROOTFS_POSTPROCESS_COMMAND . 但是,如果在填充整个rootfs时需要这样做,请使用ROOTFS_POSTPROCESS_COMMAND Eg put this in you image recipe: 例如,将其放入您的图像配方中:

my_image_postprocess_function() {
    ln -sf /usr/lib/python3.5/pdb.py ${IMAGE_ROOTFS}/usr/bin/pdb
}

ROOTFS_POSTPROCESS_COMMAND += "my_image_postprocess_function; "

Erik Botö's answer is probably the best way to do this, however I'd like to record what I found myself, in case it helps other people trying to do something similar (creating a symlink in an image recipe, although perhaps not with this specific symlink). ErikBotö的答案可能是做到这一点的最好方法,但是我想记录一下自己的发现,以防其他人尝试做类似的事情(在图像配方中创建符号链接,尽管可能与此无关)符号链接)。

In my image recipe (which I call recipes-core/images/myimage.bb in my custom layer) I added the following lines: 在我的图像配方中(在我的自定义层中将其称为recipes-core/images/myimage.bb ),添加了以下几行:

addtask create_pdb_symlink after do_rootfs before do_image
do_create_pdb_symlink () {
    ln -s /usr/lib/python3.5/pdb.py ${IMAGE_ROOTFS}/usr/bin/pdb
}

The two key things I had to understand here were the use of IMAGE_ROOTFS (which I found by searching the output of bitbake -e ), and the ordering of tasks: symlink creation has to happen after do_rootfs otherwise there's nothing in ${IMAGE_ROOTFS} , but obviously needs to happen before any images are created, to be included. 我在这里必须了解的两个关键事项是IMAGE_ROOTFS的使用(我是通过搜索bitbake -e的输出发现的)以及任务的顺序:符号链接的创建必须在do_rootfs之后do_rootfs否则${IMAGE_ROOTFS}没有任何内容,但显然需要在创建任何图像之前就将其包含在内。

However in this case I agree that a bbappend on the python3 recipe is more appropriate. 但是在这种情况下,我同意在python3配方上使用bbappend更合适。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM