2

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?
davidA
  • 12,528
  • 9
  • 64
  • 96

2 Answers2

3

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; "
Erik Botö
  • 966
  • 7
  • 11
  • Be aware that you will receive a warning when creating an absolute path link. – Nayfe Mar 28 '18 at 07:25
  • The recipe filename uses `%` so will catch all versions of python3 recipes, however there's a `3.5` in the symlink creation command - is there a way to extract the first two parts of the `%` match and use this in the command? I'll do some research however I suspect there will be a variable containing the `%` match somewhere... – davidA Apr 02 '18 at 22:10
  • Looks like the original Python recipe defines `PYTHON_MAJMIN` so I'll use that for now. Not sure about the general case although `PV` seems promising. – davidA Apr 02 '18 at 22:30
1

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.

davidA
  • 12,528
  • 9
  • 64
  • 96