Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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. 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. 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.

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.

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?
  • or is there a reason why this isn't being created by the python recipe itself?
like image 402
davidA Avatar asked Nov 19 '25 20:11

davidA


1 Answers

Since this symlink is clearly related to python3 I would recommend that you create it using a bbappend for that recipe. The recipe name is python3_(version).bb, so to catch all versions name the 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. But if you have something so need to do when the whole rootfs is populated look into using ROOTFS_POSTPROCESS_COMMAND. E.g. 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; "
like image 52
Erik Botö Avatar answered Nov 21 '25 09:11

Erik Botö