Improve externalsrc task dependency tracking
v3 cover Improve externalsrc task dependency tracking
This iteration of divides the patchset into two parts.
The first patch only enables file-checksums tracking for git repositories. The functionality is now changed so that a git tree hash of the work tree content is written into a separate file which is checksummed by bitbake. It turns out that checksumming git index file (done in v2 of the patchset) was not reliable as its checksum might change without any changes in the work tree.
The first patch depends on a bitbake patch which introduces BB_DONT_CACHE variable:
http://patchwork.openembedded.org/patch/118465/
The second patch enables source files tracking for non-Git source trees. This part is basically unchanged from v2 of the patchset. However, in order for it to behave nicely another bitbake patch needs to be applied:
http://patchwork.openembedded.org/patch/118463/ The reason is that without this bitbake patch the EXTERNALSRC_SYMLINKS in the source tree are causing a failure in checksumming which, in turn, causes the build to fail.
If so desired, the first patch can be merged independently, leaving the non-Git support for later time.
[YOCTO #8853]
The following changes since commit 9c200760cbbe322ed884729eb395f389c863e1c8:
oe-buildenv-internal: Correct the sed expression which updates $PATH (2016-03-21 11:57:27 +0000)
are available in the git repository at:
git://git.openembedded.org/openembedded-core-contrib marquiz/devtool/fixes
Markus Lehtonen (2):
externalsrc: do not use do_configure[nostamp] for git srctrees
externalsrc: remove nostamp from do_configure
meta/classes/externalsrc.bbclass | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-)
Signature · 1 line
2.6.2
PATCH v3 2/2 externalsrc: remove nostamp from do_configure
Extend the srctree_hash_files() function in externalsrc.bbclass to handle non-Git source trees. If the source tree is not a git repository, srctree_hash_files() now simply adds the whole source tree as a dependency, causing bitbake to basically hash every file in it. Hidden files and directories in the source tree root are ignored by the glob currently used. This has the advantage of automatically ignoring .git directory, for example.
During the first bitbake run preparing of the task runqueue may take much longer if the source tree is not a git repository. The reason is that all the files in the source tree are hashed. Subsequent builds are not significantly slower because (most) file hashes are found from the cache.
[YOCTO #8853]
--- meta/classes/externalsrc.bbclass | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
meta/classes/externalsrc.bbclass +1 -1
@@ -149,5 +149,5 @@ def srctree_hash_files(d): fobj.write(sha1) ret = oe_hash_file + ':True' else: - d.setVarFlag('do_compile', 'nostamp', '1') + ret = d.getVar('EXTERNALSRC', True) + '/*:True' return ret
Signature · 1 line
2.6.2
PATCH v3 1/2 externalsrc: do not use do_configure[nostamp] for git srctrees
In reply to Markus LehtonenBe a bit more intelligent than mindlessly re-compiling every time. Instead of always using 'nostamp' flag for do_compile run a python function to get a list of files to add as 'file-checksums' flag. The intention is to only re-run do_compile if something in the source tree content changes.
This python function, srctree_hash_files(), works differently, depending if the source tree is a git repository clone or not. If the source tree is a git repository, the function runs 'git add .' and 'git write tree' to get a hash of the working tree and writes this hash into a file under the .git directory. This file containing the hash is then returned as the file for the task to depend on. Hash is changed if any changes are made in the source tree causing the task to be re-run. A trick is used to parse the recipe every time so that the hash file gets updated.
If the source tree is not a git repository behaviour remains the same. In this case srctree_hash_files() currently sets the 'nostamp' flag for do_compile causing it to be re-run every time.
This method of tracking changes source tree changes to determine if re-build is needed does not work perofectly, though. Many packages are built under ${S} which effectively changes the source tree causing some unwanted re-compilations. However, if do_compile of the recipe does not produce new/different artefacts on every run (as commonly is and should be the case) the re-compilation loop stops. Thus, you should usually see only one re-compilation (if any) after which the source tree is "stabilized" and no more re-compilations happen.
[YOCTO #8853]
--- meta/classes/externalsrc.bbclass | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-)
meta/classes/externalsrc.bbclass +29 -2
@@ -85,8 +85,10 @@ python () { d.prependVarFlag('do_compile', 'prefuncs', "externalsrc_compile_prefunc ") d.prependVarFlag('do_configure', 'prefuncs', "externalsrc_configure_prefunc ") - # Ensure compilation happens every time - d.setVarFlag('do_compile', 'nostamp', '1') + # Force the recipe to be always re-parsed so that the file_checksums + # function is run every time + d.setVar('BB_DONT_CACHE', '1') + d.setVarFlag('do_compile', 'file-checksums', '${@srctree_hash_files(d)}') # We don't want the workdir to go away d.appendVar('RM_WORK_EXCLUDE', ' ' + d.getVar('PN', True))
@@ -124,3 +126,28 @@ python externalsrc_compile_prefunc() { # Make it obvious that this is happening, since forgetting about it could lead to much confusion bb.plain('NOTE: %s: compiling from external source tree %s' % (d.getVar('PN', True), d.getVar('EXTERNALSRC', True))) } + +def srctree_hash_files(d): + import shutil + import subprocess + + s_dir = d.getVar('EXTERNALSRC', True) + git_dir = os.path.join(s_dir, '.git') + oe_index_file = os.path.join(git_dir, 'oe-devtool-index') + oe_hash_file = os.path.join(git_dir, 'oe-devtool-tree-sha1') + + ret = " " + if os.path.exists(git_dir): + # Clone index + shutil.copy2(os.path.join(git_dir, 'index'), oe_index_file) + # Update our custom index + env = os.environ.copy() + env['GIT_INDEX_FILE'] = oe_index_file + subprocess.check_output(['git', 'add', '.'], cwd=s_dir, env=env) + sha1 = subprocess.check_output(['git', 'write-tree'], cwd=s_dir, env=env) + with open(oe_hash_file, 'w') as fobj: + fobj.write(sha1) + ret = oe_hash_file + ':True' + else: + d.setVarFlag('do_compile', 'nostamp', '1') + return ret
Signature · 1 line
2.6.2