8

Is it good practice to edit source code in poky/build/tmp/work directory ? because if we accidentally cleansstate ,the changes will be erased.

Alternatively we can edit source code in "files" directory along with recipe file but since mostly code here is in zipped form due to large number of files , so we will need to unzip and zip again just to change one line of code.

So what is best way to edit source code in yocto ?

waqas
  • 81
  • 1
  • 1
  • 5

2 Answers2

12

If your question is about permanent changes, then Dan's answer is the one to follow. I.e. add a <recipe name>.bbappend to the recipe in your own layer, in which you add SRC_URI += "file://mypatch1.patch \ file://mypatch2.patch \ " enumerating all the patches you need.

If there's a large number of patches, it might make sense to fork the upstream repository, and maintain your own branch in your fork. In that case, you'll likely want to reference your own repository, instead of either the upstream repository or tarball.

OTOH, if your question was more about work-in-progress; then sure, doing it in oky/build/tmp/workoky/build/tmp/work/xxxx will work. (And quite likely, it's what most people have been doing for a long time).

However, there's a much better way in recent releases (from 1.8, fido). The new tool is called devtool. You can use it as follows:

devtool modify -x <recipe-name> <path-to-unpack-source> unpacks the source and creates a new bbappend to build from the unpacked source. It also creates a git repo in the source directory.

Now you can modify the source. You can test-build your modified source by running devtool build <recipe-name>. Once you're satisfied, use git add ... and git commit to commit your changes to the local repo. Once you've commited the changes to the local repo, you can run: devtool update-recipe <recipe-name> to update the recipe in question. When you're satisfied, you can run devtool reset <recipe-name> to remove the temporary bbappend.

See also: Yocto manual on modifying source code

user2394284
  • 5,520
  • 4
  • 32
  • 38
Anders
  • 8,541
  • 1
  • 27
  • 34
1

If you are continuously "patching" a given package manually, I would recommend you to look at implementing a .bbappend file in a separate layer which applies your patch using the do_patch function (http://www.yoctoproject.org/docs/2.0/mega-manual/mega-manual.html#patching-dev-environment).

  • @Anders et.al. is the answer, but just failed to mention that devtool creates the bbappend file if you use a different layer than the original. – Ariel M. Feb 09 '19 at 21:50