devtool refactoring
cover devtool refactoring
This patchset contains contains some refactoring of the devtool code, hopefully making the code more maintainable and somewhat easier to read.
The following changes since commit c91ffdb8fff4a62ccb80196a3d735e4b9a3056a3:
dosfstools: Add recipe for v3.0.28 (2015-06-03 16:38:14 +0100)
are available in the git repository at:
ssh://oegit/openembedded-core-contrib marquiz/devtool/refactor
http://git.openembedded.org/openembedded-core-contrib/commit/?h=marquiz/devtool/refactor
Markus Lehtonen (10):
devtool: fix wrong indentation
devtool: refactor bb task execution into a separate class
devtool: update-recipe: do rev parsing in a separate function
devtool: simplify the logic of determining patches to be removed
devtool: simplify few conditionals a bit
devtool: slight simplification of path splitting logic
devtool: split out 'srcrev' update mode into a separate function
devtool: split out 'patch' update mode into a separate function
devtool: remove some unused return values
devtool: use DevtoolError for error handling
scripts/devtool | 9 +- scripts/lib/devtool/__init__.py | 6 + scripts/lib/devtool/deploy.py | 31 +- scripts/lib/devtool/standard.py | 646 +++++++++++++++++++++------------------- 4 files changed, 369 insertions(+), 323 deletions(-)
Signature · 1 line
2.1.4
PATCH 1/10 devtool: fix wrong indentation
--- scripts/lib/devtool/standard.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/lib/devtool/standard.py +2 -2
@@ -657,8 +657,8 @@ def update_recipe(args, config, basepath, workspace): for newpatch in newpatches: if seqpatch_re.search(newpatch) and patchfile[5:] == newpatch[5:]: break - else: - removepatches.append(patch) + else: + removepatches.append(patch) elif patchfile not in newpatches: removepatches.append(patch) finally:
Signature · 1 line
2.1.4
PATCH 2/10 devtool: refactor bb task execution into a separate class
In reply to Markus Lehtonen--- scripts/lib/devtool/standard.py | 50 ++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 20 deletions(-)
scripts/lib/devtool/standard.py +30 -20
@@ -213,6 +213,32 @@ def extract(args, config, basepath, workspace): else: return -1 +class BbTaskExecutor(object): + """Class for executing bitbake tasks for a recipe + + FIXME: This is very awkward. Unfortunately it's not currently easy to + properly execute tasks outside of bitbake itself, until then this has to + suffice if we are to handle e.g. linux-yocto's extra tasks + """ + + def __init__(self, rdata): + self.rdata = rdata + self.executed = [] + + def exec_func(self, func, report): + """Run bitbake task function""" + if not func in self.executed: + deps = self.rdata.getVarFlag(func, 'deps') + if deps: + for taskdepfunc in deps: + self.exec_func(taskdepfunc, True) + if report: + logger.info('Executing %s...' % func) + fn = self.rdata.getVar('FILE', True) + localdata = bb.build._task_data(fn, func, self.rdata) + bb.build.exec_func(func, localdata) + self.executed.append(func) + def _extract_source(srctree, keep_temp, devbranch, d): """Extract sources of a recipe"""
@@ -270,28 +296,12 @@ def _extract_source(srctree, keep_temp, devbranch, d): # We don't want to move the source to STAGING_KERNEL_DIR here crd.setVar('STAGING_KERNEL_DIR', '${S}') - # FIXME: This is very awkward. Unfortunately it's not currently easy to properly - # execute tasks outside of bitbake itself, until then this has to suffice if we - # are to handle e.g. linux-yocto's extra tasks - executed = [] - def exec_task_func(func, report): - """Run specific bitbake task for a recipe""" - if not func in executed: - deps = crd.getVarFlag(func, 'deps') - if deps: - for taskdepfunc in deps: - exec_task_func(taskdepfunc, True) - if report: - logger.info('Executing %s...' % func) - fn = d.getVar('FILE', True) - localdata = bb.build._task_data(fn, func, crd) - bb.build.exec_func(func, localdata) - executed.append(func) + task_executor = BbTaskExecutor(crd) logger.info('Fetching %s...' % pn) - exec_task_func('do_fetch', False) + task_executor.exec_func('do_fetch', False) logger.info('Unpacking...') - exec_task_func('do_unpack', False) + task_executor.exec_func('do_unpack', False) srcsubdir = crd.getVar('S', True) if srcsubdir == workdir: # Find non-patch sources that were "unpacked" to srctree directory
@@ -343,7 +353,7 @@ def _extract_source(srctree, keep_temp, devbranch, d): crd.setVar('PATCHTOOL', 'git') logger.info('Patching...') - exec_task_func('do_patch', False) + task_executor.exec_func('do_patch', False) bb.process.run('git tag -f devtool-patched', cwd=srcsubdir)
Signature · 1 line
2.1.4
PATCH 3/10 devtool: update-recipe: do rev parsing in a separate function
In reply to Markus LehtonenSplit out the logic of determining "initial rev" and "update rev" into a separate function.
--- scripts/lib/devtool/standard.py | 55 +++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 24 deletions(-)
scripts/lib/devtool/standard.py +31 -24
@@ -514,6 +514,36 @@ def modify(args, config, basepath, workspace): return 0 +def _get_patchset_revs(args, srctree, recipe_path): + """Get initial and update rev of a recipe. These are the start point of the + whole patchset and start point for the patches to be re-generated/updated. + """ + import bb + + if args.initial_rev: + return args.initial_rev, args.initial_rev + + # Parse initial rev from recipe + commits = [] + initial_rev = None + with open(recipe_path, 'r') as f: + for line in f: + if line.startswith('# initial_rev:'): + initial_rev = line.split(':')[-1].strip() + elif line.startswith('# commit:'): + commits.append(line.split(':')[-1].strip()) + + update_rev = initial_rev + if initial_rev: + # Find first actually changed revision + stdout, _ = bb.process.run('git rev-list --reverse %s..HEAD' % + initial_rev, cwd=srctree) + newcommits = stdout.split() + for i in xrange(min(len(commits), len(newcommits))): + if newcommits[i] == commits[i]: + update_rev = commits[i] + + return initial_rev, update_rev def update_recipe(args, config, basepath, workspace): """Entry point for the devtool 'update-recipe' subcommand"""
@@ -618,34 +648,11 @@ def update_recipe(args, config, basepath, workspace): logger.info('You will need to update SRC_URI within the recipe to point to a git repository where you have pushed your changes') elif mode == 'patch': - commits = [] - update_rev = None - if args.initial_rev: - initial_rev = args.initial_rev - else: - initial_rev = None - with open(append, 'r') as f: - for line in f: - if line.startswith('# initial_rev:'): - initial_rev = line.split(':')[-1].strip() - elif line.startswith('# commit:'): - commits.append(line.split(':')[-1].strip()) - - if initial_rev: - # Find first actually changed revision - (stdout, _) = bb.process.run('git rev-list --reverse %s..HEAD' % initial_rev, cwd=srctree) - newcommits = stdout.split() - for i in xrange(min(len(commits), len(newcommits))): - if newcommits[i] == commits[i]: - update_rev = commits[i] - + initial_rev, update_rev = _get_patchset_revs(args, srctree, append) if not initial_rev: logger.error('Unable to find initial revision - please specify it with --initial-rev') return -1 - if not update_rev: - update_rev = initial_rev - # Find list of existing patches in recipe file existing_patches = oe.recipeutils.get_recipe_patches(rd)
Signature · 1 line
2.1.4
PATCH 4/10 devtool: simplify the logic of determining patches to be removed
In reply to Markus LehtonenA slight simplification of the code.
--- scripts/lib/devtool/standard.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-)
scripts/lib/devtool/standard.py +11 -14
@@ -657,26 +657,23 @@ def update_recipe(args, config, basepath, workspace): existing_patches = oe.recipeutils.get_recipe_patches(rd) removepatches = [] - seqpatch_re = re.compile('^[0-9]{4}-') + seqpatch_re = re.compile('^([0-9]{4}-)?(.+)') if not args.no_remove: # Get all patches from source tree and check if any should be removed tempdir = tempfile.mkdtemp(prefix='devtool') try: GitApplyTree.extractPatches(srctree, initial_rev, tempdir) - newpatches = os.listdir(tempdir) + # Strip numbering from patch names. If it's a git sequence + # named patch, the numbers might not match up since we are + # starting from a different revision This does assume that + # people are using unique shortlog values, but they ought to be + # anyway... + newpatches = [seqpatch_re.match(fname).group(2) for fname in + os.listdir(tempdir)] for patch in existing_patches: - # If it's a git sequence named patch, the numbers might not match up - # since we are starting from a different revision - # This does assume that people are using unique shortlog values, but - # they ought to be anyway... - patchfile = os.path.basename(patch) - if seqpatch_re.search(patchfile): - for newpatch in newpatches: - if seqpatch_re.search(newpatch) and patchfile[5:] == newpatch[5:]: - break - else: - removepatches.append(patch) - elif patchfile not in newpatches: + basename = seqpatch_re.match( + os.path.basename(patch)).group(2) + if basename not in newpatches: removepatches.append(patch) finally: shutil.rmtree(tempdir)
Signature · 1 line
2.1.4
PATCH 5/10 devtool: simplify few conditionals a bit
In reply to Markus LehtonenJust refactor the code.
--- scripts/lib/devtool/standard.py | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-)
scripts/lib/devtool/standard.py +12 -15
@@ -49,18 +49,16 @@ def add(args, config, basepath, workspace): return -1 srctree = os.path.abspath(args.srctree) - if os.path.exists(srctree): - if args.fetch: - if not os.path.isdir(srctree): - logger.error("Cannot fetch into source tree path %s as it exists and is not a directory" % srctree) - return 1 - elif os.listdir(srctree): - logger.error("Cannot fetch into source tree path %s as it already exists and is non-empty" % srctree) - return 1 - else: - if not args.fetch: - logger.error("Specified source tree %s could not be found" % srctree) + if os.path.exists(srctree) and args.fetch: + if not os.path.isdir(srctree): + logger.error("Cannot fetch into source tree path %s as it exists and is not a directory" % srctree) return 1 + elif os.listdir(srctree): + logger.error("Cannot fetch into source tree path %s as it already exists and is non-empty" % srctree) + return 1 + elif not args.fetch: + logger.error("Specified source tree %s could not be found" % srctree) + return 1 appendpath = os.path.join(config.workspace_path, 'appends') if not os.path.exists(appendpath):
@@ -424,10 +422,9 @@ def modify(args, config, basepath, workspace): logger.error("recipe %s is already in your workspace" % args.recipename) return -1 - if not args.extract: - if not os.path.isdir(args.srctree): - logger.error("directory %s does not exist or not a directory (specify -x to extract source from recipe)" % args.srctree) - return -1 + if not args.extract and not os.path.isdir(args.srctree): + logger.error("directory %s does not exist or not a directory (specify -x to extract source from recipe)" % args.srctree) + return -1 tinfoil = setup_tinfoil()
Signature · 1 line
2.1.4
PATCH 6/10 devtool: slight simplification of path splitting logic
In reply to Markus Lehtonen--- scripts/lib/devtool/standard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/lib/devtool/standard.py +1 -1
@@ -468,7 +468,7 @@ def modify(args, config, basepath, workspace): if s.startswith(workdir): # Handle if S is set to a subdirectory of the source if s != workdir and os.path.dirname(s) != workdir: - srcsubdir = os.sep.join(os.path.relpath(s, workdir).split(os.sep)[1:]) + srcsubdir = os.path.relpath(s, workdir).split(os.sep, 1)[1] srctree = os.path.join(srctree, srcsubdir) appendpath = os.path.join(config.workspace_path, 'appends')
Signature · 1 line
2.1.4
PATCH 7/10 devtool: split out 'srcrev' update mode into a separate function
In reply to Markus LehtonenRefactor update_recipe() (i.e. the implementation of the update-recipe command) by splitting out the 'srcrev' into a distinct function.
--- scripts/lib/devtool/standard.py | 188 ++++++++++++++++++++++++---------------- 1 file changed, 111 insertions(+), 77 deletions(-)
scripts/lib/devtool/standard.py +111 -77
@@ -29,6 +29,12 @@ from devtool import exec_build_env_command, setup_tinfoil logger = logging.getLogger('devtool') + +class DevtoolError(Exception): + """Exception for handling devtool errors""" + pass + + def plugin_init(pluginlist): """Plugin initialization""" pass
@@ -542,6 +548,103 @@ def _get_patchset_revs(args, srctree, recipe_path): return initial_rev, update_rev +def _remove_patch_entries(srcuri, patchlist): + """Remove patch entries from SRC_URI""" + remaining = patchlist[:] + entries = [] + for patch in patchlist: + patchfile = os.path.basename(patch) + for i in xrange(len(srcuri)): + if srcuri[i].startswith('file://') and os.path.basename(srcuri[i].split(';')[0]) == patchfile: + entries.append(srcuri[i]) + remaining.remove(patch) + srcuri.pop(i) + break + return entries, remaining + +def _remove_patch_files(args, patches, destpath): + """Unlink existing patch files""" + for patchfile in patches: + if args.append: + if not destpath: + raise Exception('destpath should be set here') + patchfile = os.path.join(destpath, os.path.basename(patchfile)) + + if os.path.exists(patchfile): + logger.info('Removing patch %s' % patchfile) + # FIXME "git rm" here would be nice if the file in question is + # tracked + # FIXME there's a chance that this file is referred to by + # another recipe, in which case deleting wouldn't be the + # right thing to do + os.remove(patchfile) + # Remove directory if empty + try: + os.rmdir(os.path.dirname(patchfile)) + except OSError as ose: + if ose.errno != errno.ENOTEMPTY: + raise + +def _update_recipe_srcrev(args, srctree, rd, config_data): + """Implement the 'srcrev' mode of update-recipe""" + import bb + import oe.recipeutils + from oe.patch import GitApplyTree + + recipefile = rd.getVar('FILE', True) + logger.info('Updating SRCREV in recipe %s' % os.path.basename(recipefile)) + + # Get HEAD revision + try: + stdout, _ = bb.process.run('git rev-parse HEAD', cwd=srctree) + except bb.process.ExecutionError as err: + raise DevtoolError('Failed to get HEAD revision in %s: %s' % + (srctree, err)) + srcrev = stdout.strip() + if len(srcrev) != 40: + raise DevtoolError('Invalid hash returned by git: %s' % stdout) + + destpath = None + removepatches = [] + patchfields = {} + patchfields['SRCREV'] = srcrev + orig_src_uri = rd.getVar('SRC_URI', False) or '' + if not args.no_remove: + # Find list of existing patches in recipe file + existing_patches = oe.recipeutils.get_recipe_patches(rd) + + old_srcrev = (rd.getVar('SRCREV', False) or '') + tempdir = tempfile.mkdtemp(prefix='devtool') + try: + GitApplyTree.extractPatches(srctree, old_srcrev, tempdir) + newpatches = os.listdir(tempdir) + for patch in existing_patches: + patchfile = os.path.basename(patch) + if patchfile in newpatches: + removepatches.append(patch) + finally: + shutil.rmtree(tempdir) + + if removepatches: + srcuri = orig_src_uri.split() + removedentries, _ = _remove_patch_entries(srcuri, removepatches) + if removedentries: + patchfields['SRC_URI'] = ' '.join(srcuri) + + if args.append: + _, destpath = oe.recipeutils.bbappend_recipe( + rd, args.append, None, wildcardver=args.wildcard_version, + extralines=patchfields) + else: + oe.recipeutils.patch_recipe(config_data, recipefile, patchfields) + + if not 'git://' in orig_src_uri: + logger.info('You will need to update SRC_URI within the recipe to ' + 'point to a git repository where you have pushed your ' + 'changes') + + _remove_patch_files(args, removepatches, destpath) + def update_recipe(args, config, basepath, workspace): """Entry point for the devtool 'update-recipe' subcommand""" if not args.recipename in workspace:
@@ -581,69 +684,16 @@ def update_recipe(args, config, basepath, workspace): else: mode = args.mode - def remove_patch_entries(srcuri, patchlist): - """Remove patch entries from SRC_URI""" - remaining = patchlist[:] - entries = [] - for patch in patchlist: - patchfile = os.path.basename(patch) - for i in xrange(len(srcuri)): - if srcuri[i].startswith('file://') and os.path.basename(srcuri[i].split(';')[0]) == patchfile: - entries.append(srcuri[i]) - remaining.remove(patch) - srcuri.pop(i) - break - return entries, remaining - srctree = workspace[args.recipename] - # Get HEAD revision - try: - (stdout, _) = bb.process.run('git rev-parse HEAD', cwd=srctree) - except bb.process.ExecutionError as err: - print('Failed to get HEAD revision in %s: %s' % (srctree, err)) - return 1 - srcrev = stdout.strip() - if len(srcrev) != 40: - logger.error('Invalid hash returned by git: %s' % stdout) - return 1 - removepatches = [] destpath = None if mode == 'srcrev': - logger.info('Updating SRCREV in recipe %s' % os.path.basename(recipefile)) - removevalues = None - patchfields = {} - patchfields['SRCREV'] = srcrev - if not args.no_remove: - # Find list of existing patches in recipe file - existing_patches = oe.recipeutils.get_recipe_patches(rd) - - old_srcrev = (rd.getVar('SRCREV', False) or '') - tempdir = tempfile.mkdtemp(prefix='devtool') - try: - GitApplyTree.extractPatches(srctree, old_srcrev, tempdir) - newpatches = os.listdir(tempdir) - for patch in existing_patches: - patchfile = os.path.basename(patch) - if patchfile in newpatches: - removepatches.append(patch) - finally: - shutil.rmtree(tempdir) - if removepatches: - srcuri = (rd.getVar('SRC_URI', False) or '').split() - removedentries, _ = remove_patch_entries(srcuri, removepatches) - if removedentries: - patchfields['SRC_URI'] = ' '.join(srcuri) - - if args.append: - (appendfile, destpath) = oe.recipeutils.bbappend_recipe(rd, args.append, None, wildcardver=args.wildcard_version, extralines=patchfields) - else: - oe.recipeutils.patch_recipe(tinfoil.config_data, recipefile, patchfields) - - if not 'git://' in orig_src_uri: - logger.info('You will need to update SRC_URI within the recipe to point to a git repository where you have pushed your changes') - + try: + _update_recipe_srcrev(args, srctree, rd, tinfoil.config_data) + except DevtoolError as err: + logger.error(err) + return 1 elif mode == 'patch': initial_rev, update_rev = _get_patchset_revs(args, srctree, append) if not initial_rev:
@@ -698,7 +748,7 @@ def update_recipe(args, config, basepath, workspace): removevalues = None if removepatches: srcuri = (rd.getVar('SRC_URI', False) or '').split() - removedentries, remaining = remove_patch_entries(srcuri, removepatches) + removedentries, remaining = _remove_patch_entries(srcuri, removepatches) if removedentries or remaining: removevalues = {'SRC_URI': removedentries + ['file://' + os.path.basename(item) for item in remaining]} (appendfile, destpath) = oe.recipeutils.bbappend_recipe(rd, args.append, patchfiles, removevalues=removevalues)
@@ -737,28 +787,12 @@ def update_recipe(args, config, basepath, workspace): finally: shutil.rmtree(tempdir) + _remove_patch_files(args, removepatches, destpath) + else: logger.error('update_recipe: invalid mode %s' % mode) return 1 - if removepatches: - for patchfile in removepatches: - if args.append: - if not destpath: - raise Exception('destpath should be set here') - patchfile = os.path.join(destpath, os.path.basename(patchfile)) - - if os.path.exists(patchfile): - logger.info('Removing patch %s' % patchfile) - # FIXME "git rm" here would be nice if the file in question is tracked - # FIXME there's a chance that this file is referred to by another recipe, in which case deleting wouldn't be the right thing to do - os.remove(patchfile) - # Remove directory if empty - try: - os.rmdir(os.path.dirname(patchfile)) - except OSError as ose: - if ose.errno != errno.ENOTEMPTY: - raise return 0
Signature · 1 line
2.1.4
PATCH 8/10 devtool: split out 'patch' update mode into a separate function
In reply to Markus LehtonenContinue refactoring of update_recipe() by splitting out the 'patch' mode into a separate function.
--- scripts/lib/devtool/standard.py | 236 +++++++++++++++++++++------------------- 1 file changed, 122 insertions(+), 114 deletions(-)
scripts/lib/devtool/standard.py +122 -114
@@ -645,6 +645,119 @@ def _update_recipe_srcrev(args, srctree, rd, config_data): _remove_patch_files(args, removepatches, destpath) +def _update_recipe_patch(args, config, srctree, rd, config_data): + """Implement the 'patch' mode of update-recipe""" + import bb + import oe.recipeutils + from oe.patch import GitApplyTree + + recipefile = rd.getVar('FILE', True) + append = os.path.join(config.workspace_path, 'appends', '%s.bbappend' % + os.path.splitext(os.path.basename(recipefile))[0]) + if not os.path.exists(append): + raise DevtoolError('unable to find workspace bbappend for recipe %s' % + args.recipename) + + initial_rev, update_rev = _get_patchset_revs(args, srctree, append) + if not initial_rev: + raise DevtoolError('Unable to find initial revision - please specify ' + 'it with --initial-rev') + + # Find list of existing patches in recipe file + existing_patches = oe.recipeutils.get_recipe_patches(rd) + + removepatches = [] + seqpatch_re = re.compile('^([0-9]{4}-)?(.+)') + if not args.no_remove: + # Get all patches from source tree and check if any should be removed + tempdir = tempfile.mkdtemp(prefix='devtool') + try: + GitApplyTree.extractPatches(srctree, initial_rev, tempdir) + # Strip numbering from patch names. If it's a git sequence named + # patch, the numbers might not match up since we are starting from + # a different revision This does assume that people are using + # unique shortlog values, but they ought to be anyway... + newpatches = [seqpatch_re.match(fname).group(2) for fname in + os.listdir(tempdir)] + for patch in existing_patches: + basename = seqpatch_re.match( + os.path.basename(patch)).group(2) + if basename not in newpatches: + removepatches.append(patch) + finally: + shutil.rmtree(tempdir) + + # Get updated patches from source tree + tempdir = tempfile.mkdtemp(prefix='devtool') + try: + GitApplyTree.extractPatches(srctree, update_rev, tempdir) + + # Match up and replace existing patches with corresponding new patches + updatepatches = False + updaterecipe = False + destpath = None + newpatches = os.listdir(tempdir) + if args.append: + patchfiles = {} + for patch in existing_patches: + patchfile = os.path.basename(patch) + if patchfile in newpatches: + patchfiles[os.path.join(tempdir, patchfile)] = patchfile + newpatches.remove(patchfile) + for patchfile in newpatches: + patchfiles[os.path.join(tempdir, patchfile)] = None + + if patchfiles or removepatches: + removevalues = None + if removepatches: + srcuri = (rd.getVar('SRC_URI', False) or '').split() + removedentries, remaining = _remove_patch_entries( + srcuri, removepatches) + if removedentries or remaining: + remaining = ['file://' + os.path.basename(item) for + item in remaining] + removevalues = {'SRC_URI': removedentries + remaining} + _, destpath = oe.recipeutils.bbappend_recipe( + rd, args.append, patchfiles, + removevalues=removevalues) + else: + logger.info('No patches needed updating') + else: + for patch in existing_patches: + patchfile = os.path.basename(patch) + if patchfile in newpatches: + logger.info('Updating patch %s' % patchfile) + shutil.move(os.path.join(tempdir, patchfile), patch) + newpatches.remove(patchfile) + updatepatches = True + srcuri = (rd.getVar('SRC_URI', False) or '').split() + if newpatches: + # Add any patches left over + patchdir = os.path.join(os.path.dirname(recipefile), + rd.getVar('BPN', True)) + bb.utils.mkdirhier(patchdir) + for patchfile in newpatches: + logger.info('Adding new patch %s' % patchfile) + shutil.move(os.path.join(tempdir, patchfile), + os.path.join(patchdir, patchfile)) + srcuri.append('file://%s' % patchfile) + updaterecipe = True + if removepatches: + removedentries, _ = _remove_patch_entries(srcuri, removepatches) + if removedentries: + updaterecipe = True + if updaterecipe: + logger.info('Updating recipe %s' % os.path.basename(recipefile)) + oe.recipeutils.patch_recipe(config_data, recipefile, + {'SRC_URI': ' '.join(srcuri)}) + elif not updatepatches: + # Neither patches nor recipe were updated + logger.info('No patches need updating') + finally: + shutil.rmtree(tempdir) + + _remove_patch_files(args, removepatches, destpath) + def update_recipe(args, config, basepath, workspace): """Entry point for the devtool 'update-recipe' subcommand""" if not args.recipename in workspace:
@@ -660,20 +773,10 @@ def update_recipe(args, config, basepath, workspace): return 2 tinfoil = setup_tinfoil() - import bb - from oe.patch import GitApplyTree - import oe.recipeutils rd = _parse_recipe(config, tinfoil, args.recipename, True) if not rd: return -1 - recipefile = rd.getVar('FILE', True) - - # Get initial revision from bbappend - append = os.path.join(config.workspace_path, 'appends', '%s.bbappend' % os.path.splitext(os.path.basename(recipefile))[0]) - if not os.path.exists(append): - logger.error('unable to find workspace bbappend for recipe %s' % args.recipename) - return -1 orig_src_uri = rd.getVar('SRC_URI', False) or '' if args.mode == 'auto':
@@ -686,111 +789,16 @@ def update_recipe(args, config, basepath, workspace): srctree = workspace[args.recipename] - removepatches = [] - destpath = None - if mode == 'srcrev': - try: + try: + if mode == 'srcrev': _update_recipe_srcrev(args, srctree, rd, tinfoil.config_data) - except DevtoolError as err: - logger.error(err) - return 1 - elif mode == 'patch': - initial_rev, update_rev = _get_patchset_revs(args, srctree, append) - if not initial_rev: - logger.error('Unable to find initial revision - please specify it with --initial-rev') - return -1 - - # Find list of existing patches in recipe file - existing_patches = oe.recipeutils.get_recipe_patches(rd) - - removepatches = [] - seqpatch_re = re.compile('^([0-9]{4}-)?(.+)') - if not args.no_remove: - # Get all patches from source tree and check if any should be removed - tempdir = tempfile.mkdtemp(prefix='devtool') - try: - GitApplyTree.extractPatches(srctree, initial_rev, tempdir) - # Strip numbering from patch names. If it's a git sequence - # named patch, the numbers might not match up since we are - # starting from a different revision This does assume that - # people are using unique shortlog values, but they ought to be - # anyway... - newpatches = [seqpatch_re.match(fname).group(2) for fname in - os.listdir(tempdir)] - for patch in existing_patches: - basename = seqpatch_re.match( - os.path.basename(patch)).group(2) - if basename not in newpatches: - removepatches.append(patch) - finally: - shutil.rmtree(tempdir) - - # Get updated patches from source tree - tempdir = tempfile.mkdtemp(prefix='devtool') - try: - GitApplyTree.extractPatches(srctree, update_rev, tempdir) - - # Match up and replace existing patches with corresponding new patches - updatepatches = False - updaterecipe = False - newpatches = os.listdir(tempdir) - if args.append: - patchfiles = {} - for patch in existing_patches: - patchfile = os.path.basename(patch) - if patchfile in newpatches: - patchfiles[os.path.join(tempdir, patchfile)] = patchfile - newpatches.remove(patchfile) - for patchfile in newpatches: - patchfiles[os.path.join(tempdir, patchfile)] = None - - if patchfiles or removepatches: - removevalues = None - if removepatches: - srcuri = (rd.getVar('SRC_URI', False) or '').split() - removedentries, remaining = _remove_patch_entries(srcuri, removepatches) - if removedentries or remaining: - removevalues = {'SRC_URI': removedentries + ['file://' + os.path.basename(item) for item in remaining]} - (appendfile, destpath) = oe.recipeutils.bbappend_recipe(rd, args.append, patchfiles, removevalues=removevalues) - else: - logger.info('No patches needed updating') - else: - for patch in existing_patches: - patchfile = os.path.basename(patch) - if patchfile in newpatches: - logger.info('Updating patch %s' % patchfile) - shutil.move(os.path.join(tempdir, patchfile), patch) - newpatches.remove(patchfile) - updatepatches = True - srcuri = (rd.getVar('SRC_URI', False) or '').split() - if newpatches: - # Add any patches left over - patchdir = os.path.join(os.path.dirname(recipefile), rd.getVar('BPN', True)) - bb.utils.mkdirhier(patchdir) - for patchfile in newpatches: - logger.info('Adding new patch %s' % patchfile) - shutil.move(os.path.join(tempdir, patchfile), os.path.join(patchdir, patchfile)) - srcuri.append('file://%s' % patchfile) - updaterecipe = True - if removepatches: - removedentries, _ = remove_patch_entries(srcuri, removepatches) - if removedentries: - updaterecipe = True - if updaterecipe: - logger.info('Updating recipe %s' % os.path.basename(recipefile)) - oe.recipeutils.patch_recipe(tinfoil.config_data, - recipefile, {'SRC_URI': ' '.join(srcuri)}) - elif not updatepatches: - # Neither patches nor recipe were updated - logger.info('No patches need updating') - - finally: - shutil.rmtree(tempdir) - - _remove_patch_files(args, removepatches, destpath) - - else: - logger.error('update_recipe: invalid mode %s' % mode) + elif mode == 'patch': + _update_recipe_patch(args, config, srctree, rd, + tinfoil.config_data) + else: + raise DevtoolError('update_recipe: invalid mode %s' % mode) + except DevtoolError as err: + logger.error(err) return 1 return 0
Signature · 1 line
2.1.4
PATCH 9/10 devtool: remove some unused return values
In reply to Markus Lehtonen--- scripts/devtool | 1 - scripts/lib/devtool/standard.py | 3 --- 2 files changed, 4 deletions(-)
scripts/devtool +0 -1
@@ -157,7 +157,6 @@ def _enable_workspace_layer(workspacedir, config, basepath): bblayers_conf = os.path.join(basepath, 'conf', 'bblayers.conf') if not os.path.exists(bblayers_conf): logger.error('Unable to find bblayers.conf') - return -1 _, added = bb.utils.edit_bblayers_conf(bblayers_conf, workspacedir, config.workspace_path) if added: logger.info('Enabling workspace layer in bblayers.conf')
scripts/lib/devtool/standard.py +0 -3
@@ -416,9 +416,6 @@ def _check_preserve(config, recipename): tf.write(line) os.rename(newfile, origfile) - return False - - def modify(args, config, basepath, workspace): """Entry point for the devtool 'modify' subcommand""" import bb
Signature · 1 line
2.1.4
PATCH 10/10 devtool: use DevtoolError for error handling
In reply to Markus LehtonenUse DevtoolError exception more widely for handling error cases. This exception is now caught in the main script and raising it can be used to exit with an error. This hopefully simplifies error handling. The change also makes exit codes more consistent, always returning '1' when an error occurs.
--- scripts/devtool | 8 ++- scripts/lib/devtool/__init__.py | 6 ++ scripts/lib/devtool/deploy.py | 31 ++++---- scripts/lib/devtool/standard.py | 152 ++++++++++++++++++---------------------- 4 files changed, 97 insertions(+), 100 deletions(-)
scripts/devtool +7 -1
@@ -35,6 +35,7 @@ context = None scripts_path = os.path.dirname(os.path.realpath(__file__)) lib_path = scripts_path + '/lib' sys.path = sys.path + [lib_path] +from devtool import DevtoolError import scriptutils logger = scriptutils.logger_create('devtool')
@@ -249,7 +250,12 @@ def main(): if args.subparser_name != 'create-workspace': read_workspace() - ret = args.func(args, config, basepath, workspace) + try: + ret = args.func(args, config, basepath, workspace) + except DevtoolError as err: + if str(err): + logger.error(str(err)) + ret = 1 return ret
scripts/lib/devtool/__init__.py +6 -0
@@ -25,6 +25,12 @@ import logging logger = logging.getLogger('devtool') + +class DevtoolError(Exception): + """Exception for handling devtool errors""" + pass + + def exec_build_env_command(init_path, builddir, cmd, watch=False, **options): """Run a program in bitbake build context""" import bb
scripts/lib/devtool/deploy.py +16 -15
@@ -19,7 +19,7 @@ import os import subprocess import logging -from devtool import exec_build_env_command, setup_tinfoil +from devtool import exec_build_env_command, setup_tinfoil, DevtoolError logger = logging.getLogger('devtool')
@@ -34,8 +34,8 @@ def deploy(args, config, basepath, workspace): import oe.recipeutils if not args.recipename in workspace: - logger.error("no recipe named %s in your workspace" % args.recipename) - return -1 + raise DevtoolError("no recipe named %s in your workspace" % + args.recipename) try: host, destdir = args.target.split(':') except ValueError:
@@ -50,12 +50,13 @@ def deploy(args, config, basepath, workspace): try: rd = oe.recipeutils.parse_recipe_simple(tinfoil.cooker, args.recipename, tinfoil.config_data) except Exception as e: - logger.error('Exception parsing recipe %s: %s' % (args.recipename, e)) - return 2 + raise DevtoolError('Exception parsing recipe %s: %s' % + (args.recipename, e)) recipe_outdir = rd.getVar('D', True) if not os.path.exists(recipe_outdir) or not os.listdir(recipe_outdir): - logger.error('No files to deploy - have you built the %s recipe? If so, the install step has not installed any files.' % args.recipename) - return -1 + raise DevtoolError('No files to deploy - have you built the %s ' + 'recipe? If so, the install step has not installed ' + 'any files.' % args.recipename) if args.dry_run: print('Files to be deployed for %s on target %s:' % (args.recipename, args.target))
@@ -67,7 +68,7 @@ def deploy(args, config, basepath, workspace): if os.path.exists(deploy_file): if undeploy(args, config, basepath, workspace): # Error already shown - return -1 + return 1 extraoptions = '' if args.no_host_check:
@@ -76,8 +77,8 @@ def deploy(args, config, basepath, workspace): extraoptions += ' -q' ret = subprocess.call('scp -r %s %s/* %s:%s' % (extraoptions, recipe_outdir, args.target, destdir), shell=True) if ret != 0: - logger.error('Deploy failed - rerun with -s to get a complete error message') - return ret + raise DevtoolError('Deploy failed - rerun with -s to get a complete ' + 'error message') logger.info('Successfully deployed %s' % recipe_outdir)
@@ -99,8 +100,7 @@ def undeploy(args, config, basepath, workspace): """Entry point for the devtool 'undeploy' subcommand""" deploy_file = os.path.join(basepath, 'target_deploy', args.target, args.recipename + '.list') if not os.path.exists(deploy_file): - logger.error('%s has not been deployed' % args.recipename) - return -1 + raise DevtoolError('%s has not been deployed' % args.recipename) if args.dry_run: print('Previously deployed files to be un-deployed for %s on target %s:' % (args.recipename, args.target))
@@ -117,15 +117,16 @@ def undeploy(args, config, basepath, workspace): ret = subprocess.call("scp %s %s %s:/tmp" % (extraoptions, deploy_file, args.target), shell=True) if ret != 0: - logger.error('Failed to copy file list to %s - rerun with -s to get a complete error message' % args.target) - return -1 + raise DevtoolError('Failed to copy file list to %s - rerun with -s to ' + 'get a complete error message' % args.target) ret = subprocess.call("ssh %s %s 'xargs -n1 rm -f </tmp/%s'" % (extraoptions, args.target, os.path.basename(deploy_file)), shell=True) if ret == 0: logger.info('Successfully undeployed %s' % args.recipename) os.remove(deploy_file) else: - logger.error('Undeploy failed - rerun with -s to get a complete error message') + raise DevtoolError('Undeploy failed - rerun with -s to get a complete ' + 'error message') return ret
scripts/lib/devtool/standard.py +68 -84
297 lines not on this page · raw message
Signature · 1 line
2.1.4
Hi Markus,
Quoted 2 lines · On Thursday 04 June 2015 19:31:44 Markus Lehtonen wrote:
This patchset contains contains some refactoring of the devtool code, hopefully making the code more maintainable and somewhat easier to read.
Unfortunately something in here breaks the QA tests - and this time I've double-checked that they pass without this patchset (well, deploy_target seems to be failing on one of my machines but not another - am looking into that).
Could you please investigate?
Thanks,
Paul
Signature · 2 lines
Paul Eggleton Intel Open Source Technology Centre
Hi,
Quoted 6 lines · Paul Eggleton
Hi Markus,
Quoted 2 lines · On Thursday 04 June 2015 19:31:44 Markus Lehtonen wrote:
This patchset contains contains some refactoring of the devtool code, hopefully making the code more maintainable and somewhat easier to read.
Quoted 7 lines
Unfortunately something in here breaks the QA tests - and this time I've double-checked that they pass without this patchset (well,
deploy_targetseems
to be failing on one of my machines but not another - am looking into that).Could you please investigate?
Hmm, strange. I will investigate and get back to this.
Thanks,
Markus