davidA
davidA

Reputation: 13664

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:

Upvotes: 3

Views: 6307

Answers (2)

davidA
davidA

Reputation: 13664

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

In my image recipe (which I call recipes-core/images/myimage.bb in my custom layer) I added the following lines:

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.

However in this case I agree that a bbappend on the python3 recipe is more appropriate.

Upvotes: 2

Erik Botö
Erik Botö

Reputation: 1126

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; "

Upvotes: 3

Related Questions