devtool: update-recipe: support replacing remote patches

If you have a patch remotely fetched in a recipe (e.g. from an http
server) that needs updating then add a local version and substitute the
entry in SRC_URI to point to it.

One can argue about how desirable it is to be modifying patches fetched
in this way, but then one can argue about how desirable it is to have
such patches in the recipe in the first place - and in any case if
devtool update-recipe is to correctly transfer changes to such patches
made in the git repository within the source tree to the recipe then
there isn't much choice but to do it this way.

(From OE-Core rev: a19c26cc78a181f9dd2706dd42e7e450d7ad4082)

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Paul Eggleton
2016-11-10 14:45:18 +13:00
committed by Richard Purdie
parent 55a157f4e6
commit 13c3a4bfa2

View File

@@ -1104,6 +1104,15 @@ def _remove_file_entries(srcuri, filelist):
break
return entries, remaining
def _replace_srcuri_entry(srcuri, filename, newentry):
"""Replace entry corresponding to specified file with a new entry"""
basename = os.path.basename(filename)
for i in range(len(srcuri)):
if os.path.basename(srcuri[i].split(';')[0]) == basename:
srcuri.pop(i)
srcuri.insert(i, newentry)
break
def _remove_source_files(append, files, destpath):
"""Unlink existing patch files"""
for path in files:
@@ -1424,6 +1433,10 @@ def _update_recipe_patch(recipename, workspace, srctree, rd, appendlayerdir, wil
raise DevtoolError('Unable to find initial revision - please specify '
'it with --initial-rev')
dl_dir = rd.getVar('DL_DIR', True)
if not dl_dir.endswith('/'):
dl_dir += '/'
tempdir = tempfile.mkdtemp(prefix='devtool')
try:
local_files_dir = tempfile.mkdtemp(dir=tempdir)
@@ -1468,6 +1481,7 @@ def _update_recipe_patch(recipename, workspace, srctree, rd, appendlayerdir, wil
logger.info('No patches or local source files needed updating')
else:
# Update existing files
files_dir = _determine_files_dir(rd)
for basepath, path in upd_f.items():
logger.info('Updating file %s' % basepath)
if os.path.isabs(basepath):
@@ -1479,11 +1493,19 @@ def _update_recipe_patch(recipename, workspace, srctree, rd, appendlayerdir, wil
updatefiles = True
for basepath, path in upd_p.items():
patchfn = os.path.join(patches_dir, basepath)
logger.info('Updating patch %s' % basepath)
if os.path.dirname(path) + '/' == dl_dir:
# This is a a downloaded patch file - we now need to
# replace the entry in SRC_URI with our local version
logger.info('Replacing remote patch %s with updated local version' % basepath)
path = os.path.join(files_dir, basepath)
_replace_srcuri_entry(srcuri, basepath, 'file://%s' % basepath)
updaterecipe = True
else:
logger.info('Updating patch %s' % basepath)
logger.debug('Moving new patch %s to %s' % (patchfn, path))
_move_file(patchfn, path)
updatefiles = True
# Add any new files
files_dir = _determine_files_dir(rd)
for basepath, path in new_f.items():
logger.info('Adding new file %s' % basepath)
_move_file(os.path.join(local_files_dir, basepath),