Skip to contentSkip to conversation

RFC: How to improve packaged-staging and setscene

DISCUSSION Richard Purdie 2 participants 5 messages Jul 5, 2010 – Aug 5, 2010

lore
Share & tools
lore
#0 lore raw

There are still some things bothering me about packaged-staging. As anyone who's looked into what it does behind the scenes will agree, its hard to follow what it does and the paths are insane.

Why? The simple reason is that its trying to capture the output from all the tasks in one step. The tricks it plays with the stamp files are also evil.

My proposal is to do something a bit more radical, to capture the output on a per task basis. The structure would therefore be the following:

# Set the name of the setscene function for this task do_foo[setscene] = "do_foo_setscene"
# The name of functions to call after do_doo completes successfully do_foo[postfuncs] = "do_foo_packager"
do_foo_setscene () {
# Call a shared function stating the task checksum and seeing # whether a prebuilt binary is available
# If yes, decompress to WORKDIR, install it using
# do_foo_installer() (optional step useful for say staging), exit 0 # If no, exit 1
}

do_foo () {
	# Some task which generates output to ${FOO_OUT}

	# As the last step install it
	do_foo_installer()
}

do_foo_packager () {
# Call a shared function to package up the tasks output
}

The workflow would then be that runqueue builds a list of tasks to execute as normal. Before it does the usual processing, it inverts the list starting at the targets and looks for tasks with setscene functions. If it finds them, it runs them. If they succeed it marks that part of the task list as complete (including all dependencies of that task).

In real terms this means that for say an image target foo-image with a fully populated cache, if would search until it found the setscene functions for the do_package_write_rpm tasks. These would be found and run, which would make the .rpm files available. Also, binaries needed for image creation would be found, their do_populate_staging setscene tasks would be run and the binaries would be come available. The image would then build.

If you then enabled debian packaging with a cache that wasn't full and ran the image again, the setscene tasks for each package's do_package function would run. The resulting directory would be packaged by debain packaging and then an image would be build from it.

This all sounds ideal but it may not be quite this simple. Its hard to tell which recursive dependencies to follow and which are met by the results of the setscene function. In the above example we need the write_rpm function to run for all dependent packages. I suspect the existing code dependency code will result in too many tasks being run (all package_write_rpm functions even for build utilities which we wouldn't need packaged for the image?). Regardless, I suspect the best way forward is to experiment.

The good side of this is that the bitbake implementation is relatively simple and backwards compatible.

Questions/further thoughts/objections?

Cheers,

Richard

#1 lore raw
Quoted 7 lines · Richard Purdie

There are still some things bothering me about packaged-staging. As anyone who's looked into what it does behind the scenes will agree, its hard to follow what it does and the paths are insane.

Why? The simple reason is that its trying to capture the output from all the tasks in one step. The tricks it plays with the stamp files are also evil.

The code in my original proposal made my eyes and head hurt but the underlying general principle was good. I've iterated over this several times over the past few months and have something worth sharing/discussing now.

First I'll skip to the punchline and show how to convert a task like do_package_write_ipk to this new style task based staging. You need to:

a) Stage files in some directory in WORKDIR
b) As implied by a), split out usage of the final destination, in this case DEPLOY_DIR_IPK
c) Add some code to handling the staging/packaging of the files

For package_write_ipk, this looks like:

SSTATETASKS += "do_package_write_ipk" do_package_write_ipk[sstate-name] = "deploy-ipk" do_package_write_ipk[sstate-inputdirs] = "${PKGWRITEDIRIPK}" do_package_write_ipk[sstate-outputdirs] = "${DEPLOY_DIR_IPK}"

python do_package_write_ipk_setscene () {
sstate_setscene(d)
}
addtask do_package_write_ipk_setscene

which is hopefully concise and clear. Behind the scenes is packaged-staging2.bbclass which has some similarities to its predecessor but is pretty much a rewrite learning from the mistakes made there.

The minor changes to bitbake this relies upon are:

a) Dedicated prefuncs and postfuncs hooks. These are flags against tasks which list functions to run before and after the main body of a task completes. Yes, we could use _prepend and _append but that assumes you know a given function is python/shell and is fundamentally ugly. I wanted a generic mechanism which would just work.

b) Added a BB_CURRENTTASK variable which has the name of the currently running task in it. This means we can allow functions to be shared between tasks.

I don't think there should be anything to controversial in adding that functionality.

The big major change to bitbake this code needs is the setscene task handling. The idea behind this is simple. bitbake works out what tasks its going to execute, e.g. foo:do_package_write_ipk and bar:do_populate_sysroot as normal. It then looks for any of these task names with "_setscene" on the end. For any of these that exist, for example, foo:do_package_write_ipk_setscene and bar:do_populate_sysroot_setscene, each is run and returns a success/failure. If it returns success bitbake takes this to mean the task has been "accelerated" and it does not need to run the non setscene variant. It also means any dependencies that task had can be ignored.

So for example you're building an image and all the do_package_write_ipk_setscene tasks return success, it will just skip to building the image from those ipk files.

I have a patch to bitbake to implement this. It works as described and I was able to reuse large amounts of code. I already merged most of the refactoring into master as it made sense in its own right.

The big drawback with the current patch is the feedback to the user is totally screwed up as it stands. We don't care about errors in setscene functions for example yet bitbake will shows these in the way it would for a normal build. This can be fixed with some time spent on the code. At the moment I want to see whether people like the direction.

I should also talk about what packaged-staging2.bbclass does behind the scenes and how it differs from packaged-staging.

The "sstate" name refers to the idea of "shared state" which is what "staging" effectively is.

Each task has a data structure associated with it which details what files it installs and where it expects these to go. This structure is built from the sstate-name, sstate-inputdirs and sstate-outputdirs variables. A task can write multiple directories but sstate-inputdirs and sstate-outputdirs should obviously have the same number of elements. The class behind the scenes builds its own structure for this data as using the flags fields directly looked prone to error. sstate_init(), sstate_add() and sstate_state_fromvars() are all to do with handling the data structures.

sstate_install() copies data from workdir to the staging are and handled "package management". In this version I've thrown away any notion of using a package manager as it doesn't fit our usecase. Instead we just create a list of files/directories we install for a given recipe.

sstate_installpkg() finds any staging package and then decompresses it, handles path relocations and then calls the installer above

sstate_clean() removes a set of files in the manifest from staging

sstate_package() builds a staging package

We wrap the task with a pre and post hook to handle first cleaning staging, then building a staging package from the output of the task.

The other major difference compared to packaged-staging.bbclass is we never need to mess with stamp files at all thanks to the setscene task.

To me, these changes deal with all the things I've disliked about packaged-staging and this is a vast improvement on what we have today. Its not 100% there yet but I think all the hard bits have a solution. Discussion welcome!

Finally, links to the code:

The packaged-staging2.bbclass and sstate code:
http://git.pokylinux.org/cgit.cgi/poky-contrib/commit/?h=rpurdie/scenequeue&id=7af6c4f02e2641b49547093632b206fe496b6f8a

Example changes to package_ipk.bbclass to enable this:
http://git.pokylinux.org/cgit.cgi/poky-contrib/commit/?h=rpurdie/scenequeue&id=87822f22ecddfc5a0d351b168394ac1d4a5c6fd3

The major bitbake setscene change:
http://git.pokylinux.org/cgit.cgi/poky-contrib/commit/?h=rpurdie/scenequeue&id=30c8e3dadfa7619398cdc6a56ca677a637addb0e

Minor bitbake tweaks:
http://git.pokylinux.org/cgit.cgi/poky-contrib/commit/?h=rpurdie/scenequeue&id=7c8004c56a06fa0ae7bf2c27b37e918df4bbf717
http://git.pokylinux.org/cgit.cgi/poky-contrib/commit/?h=rpurdie/scenequeue&id=0f516fe9a043276c670622895c4760ff6468f293

These links should continue to work although its likely further updates will appear on that branch as I'm actively working on refining this.

Cheers,

Richard

#2 lore raw

Richard,

Sounds good to me. Not sure whether I have time to try it out on short term. Too much other things at hand.

One small concern:
Would it in your proposal be possible to disable packaged staging? I think it would be nice if a user (in local.conf or so) could decide on whether he wants to spent build time and space on this.

Frans

#3 lore raw
Quoted 7 lines · Frans Meulenbroeks

Sounds good to me. Not sure whether I have time to try it out on short term. Too much other things at hand.

One small concern:
Would it in your proposal be possible to disable packaged staging? I think it would be nice if a user (in local.conf or so) could decide on whether he wants to spent build time and space on this.

Technically, disabling would be possible but you lose some important benefits such as when enabled, cleaning a package will remove whatever it put into staging.

One of our problems in OE is too many code paths. I'd like to see us try and minimise that problem. Disk space is cheap and this code shouldn't take much more time.

Once combined with checksums, it should actually save people large amounts of time as needing to rebuild from scratch should be a think of the patch (unless you make a change effecting everything in which case you'd expect it).

Cheers,

Richard

#4 lore raw

2010/8/5 Richard Purdie <[email protected]>:

Quoted 12 lines · Frans Meulenbroeks
Quoted 7 lines

Sounds good to me. Not sure whether I have time to try it out on short term. Too much other things at hand.

One small concern:
Would it in your proposal be possible to disable packaged staging? I think it would be nice if a user (in local.conf or so) could decide on whether he wants to spent build time and space on this.

Technically, disabling would be possible but you lose some important benefits such as when enabled, cleaning a package will remove whatever it put into staging.

Ah ok, that is a benefit I would not like to give up.

Quoted 4 lines

One of our problems in OE is too many code paths. I'd like to see us try and minimise that problem. Disk space is cheap and this code shouldn't take much more time.

Space is less of an issue than time. An additonal task does consume some time, if only to get started

Quoted 5 lines

Once combined with checksums, it should actually save people large amounts of time as needing to rebuild from scratch should be a think of the patch (unless you make a change effecting everything in which case you'd expect it).

Well one of the scenario's I was thinking of when I had this in mind was an autobuilder which builds images from scratch for verification purposes.

But I understand your concern about paths. Indeed currently there are sometimes unexpected side effects

Frans