diff options
Diffstat (limited to 'meta/lib/oe/recipeutils.py')
| -rw-r--r-- | meta/lib/oe/recipeutils.py | 48 |
1 files changed, 36 insertions, 12 deletions
diff --git a/meta/lib/oe/recipeutils.py b/meta/lib/oe/recipeutils.py index cab94b1350..a1e191afc7 100644 --- a/meta/lib/oe/recipeutils.py +++ b/meta/lib/oe/recipeutils.py | |||
| @@ -251,7 +251,7 @@ def patch_recipe_lines(fromlines, values, trailing_newline=True): | |||
| 251 | return changed, tolines | 251 | return changed, tolines |
| 252 | 252 | ||
| 253 | 253 | ||
| 254 | def patch_recipe_file(fn, values, patch=False, relpath=''): | 254 | def patch_recipe_file(fn, values, patch=False, relpath='', redirect_output=None): |
| 255 | """Update or insert variable values into a recipe file (assuming you | 255 | """Update or insert variable values into a recipe file (assuming you |
| 256 | have already identified the exact file you want to update.) | 256 | have already identified the exact file you want to update.) |
| 257 | Note that some manual inspection/intervention may be required | 257 | Note that some manual inspection/intervention may be required |
| @@ -263,7 +263,11 @@ def patch_recipe_file(fn, values, patch=False, relpath=''): | |||
| 263 | 263 | ||
| 264 | _, tolines = patch_recipe_lines(fromlines, values) | 264 | _, tolines = patch_recipe_lines(fromlines, values) |
| 265 | 265 | ||
| 266 | if patch: | 266 | if redirect_output: |
| 267 | with open(os.path.join(redirect_output, os.path.basename(fn)), 'w') as f: | ||
| 268 | f.writelines(tolines) | ||
| 269 | return None | ||
| 270 | elif patch: | ||
| 267 | relfn = os.path.relpath(fn, relpath) | 271 | relfn = os.path.relpath(fn, relpath) |
| 268 | diff = difflib.unified_diff(fromlines, tolines, 'a/%s' % relfn, 'b/%s' % relfn) | 272 | diff = difflib.unified_diff(fromlines, tolines, 'a/%s' % relfn, 'b/%s' % relfn) |
| 269 | return diff | 273 | return diff |
| @@ -313,7 +317,7 @@ def localise_file_vars(fn, varfiles, varlist): | |||
| 313 | 317 | ||
| 314 | return filevars | 318 | return filevars |
| 315 | 319 | ||
| 316 | def patch_recipe(d, fn, varvalues, patch=False, relpath=''): | 320 | def patch_recipe(d, fn, varvalues, patch=False, relpath='', redirect_output=None): |
| 317 | """Modify a list of variable values in the specified recipe. Handles inc files if | 321 | """Modify a list of variable values in the specified recipe. Handles inc files if |
| 318 | used by the recipe. | 322 | used by the recipe. |
| 319 | """ | 323 | """ |
| @@ -323,7 +327,7 @@ def patch_recipe(d, fn, varvalues, patch=False, relpath=''): | |||
| 323 | patches = [] | 327 | patches = [] |
| 324 | for f,v in locs.items(): | 328 | for f,v in locs.items(): |
| 325 | vals = {k: varvalues[k] for k in v} | 329 | vals = {k: varvalues[k] for k in v} |
| 326 | patchdata = patch_recipe_file(f, vals, patch, relpath) | 330 | patchdata = patch_recipe_file(f, vals, patch, relpath, redirect_output) |
| 327 | if patch: | 331 | if patch: |
| 328 | patches.append(patchdata) | 332 | patches.append(patchdata) |
| 329 | 333 | ||
| @@ -584,7 +588,7 @@ def get_bbappend_path(d, destlayerdir, wildcardver=False): | |||
| 584 | return (appendpath, pathok) | 588 | return (appendpath, pathok) |
| 585 | 589 | ||
| 586 | 590 | ||
| 587 | def bbappend_recipe(rd, destlayerdir, srcfiles, install=None, wildcardver=False, machine=None, extralines=None, removevalues=None): | 591 | def bbappend_recipe(rd, destlayerdir, srcfiles, install=None, wildcardver=False, machine=None, extralines=None, removevalues=None, redirect_output=None): |
| 588 | """ | 592 | """ |
| 589 | Writes a bbappend file for a recipe | 593 | Writes a bbappend file for a recipe |
| 590 | Parameters: | 594 | Parameters: |
| @@ -611,6 +615,9 @@ def bbappend_recipe(rd, destlayerdir, srcfiles, install=None, wildcardver=False, | |||
| 611 | value pairs, or simply a list of the lines. | 615 | value pairs, or simply a list of the lines. |
| 612 | removevalues: | 616 | removevalues: |
| 613 | Variable values to remove - a dict of names/values. | 617 | Variable values to remove - a dict of names/values. |
| 618 | redirect_output: | ||
| 619 | If specified, redirects writing the output file to the | ||
| 620 | specified directory (for dry-run purposes) | ||
| 614 | """ | 621 | """ |
| 615 | 622 | ||
| 616 | if not removevalues: | 623 | if not removevalues: |
| @@ -625,7 +632,8 @@ def bbappend_recipe(rd, destlayerdir, srcfiles, install=None, wildcardver=False, | |||
| 625 | bb.warn('Unable to determine correct subdirectory path for bbappend file - check that what %s adds to BBFILES also matches .bbappend files. Using %s for now, but until you fix this the bbappend will not be applied.' % (os.path.join(destlayerdir, 'conf', 'layer.conf'), os.path.dirname(appendpath))) | 632 | bb.warn('Unable to determine correct subdirectory path for bbappend file - check that what %s adds to BBFILES also matches .bbappend files. Using %s for now, but until you fix this the bbappend will not be applied.' % (os.path.join(destlayerdir, 'conf', 'layer.conf'), os.path.dirname(appendpath))) |
| 626 | 633 | ||
| 627 | appenddir = os.path.dirname(appendpath) | 634 | appenddir = os.path.dirname(appendpath) |
| 628 | bb.utils.mkdirhier(appenddir) | 635 | if not redirect_output: |
| 636 | bb.utils.mkdirhier(appenddir) | ||
| 629 | 637 | ||
| 630 | # FIXME check if the bbappend doesn't get overridden by a higher priority layer? | 638 | # FIXME check if the bbappend doesn't get overridden by a higher priority layer? |
| 631 | 639 | ||
| @@ -702,9 +710,18 @@ def bbappend_recipe(rd, destlayerdir, srcfiles, install=None, wildcardver=False, | |||
| 702 | if instfunclines: | 710 | if instfunclines: |
| 703 | bbappendlines.append(('do_install_append%s()' % appendoverride, '', instfunclines)) | 711 | bbappendlines.append(('do_install_append%s()' % appendoverride, '', instfunclines)) |
| 704 | 712 | ||
| 705 | bb.note('Writing append file %s' % appendpath) | 713 | if redirect_output: |
| 714 | bb.note('Writing append file %s (dry-run)' % appendpath) | ||
| 715 | outfile = os.path.join(redirect_output, os.path.basename(appendpath)) | ||
| 716 | # Only take a copy if the file isn't already there (this function may be called | ||
| 717 | # multiple times per operation when we're handling overrides) | ||
| 718 | if os.path.exists(appendpath) and not os.path.exists(outfile): | ||
| 719 | shutil.copy2(appendpath, outfile) | ||
| 720 | else: | ||
| 721 | bb.note('Writing append file %s' % appendpath) | ||
| 722 | outfile = appendpath | ||
| 706 | 723 | ||
| 707 | if os.path.exists(appendpath): | 724 | if os.path.exists(outfile): |
| 708 | # Work around lack of nonlocal in python 2 | 725 | # Work around lack of nonlocal in python 2 |
| 709 | extvars = {'destsubdir': destsubdir} | 726 | extvars = {'destsubdir': destsubdir} |
| 710 | 727 | ||
| @@ -776,7 +793,7 @@ def bbappend_recipe(rd, destlayerdir, srcfiles, install=None, wildcardver=False, | |||
| 776 | if removevalues: | 793 | if removevalues: |
| 777 | varnames.extend(list(removevalues.keys())) | 794 | varnames.extend(list(removevalues.keys())) |
| 778 | 795 | ||
| 779 | with open(appendpath, 'r') as f: | 796 | with open(outfile, 'r') as f: |
| 780 | (updated, newlines) = bb.utils.edit_metadata(f, varnames, appendfile_varfunc) | 797 | (updated, newlines) = bb.utils.edit_metadata(f, varnames, appendfile_varfunc) |
| 781 | 798 | ||
| 782 | destsubdir = extvars['destsubdir'] | 799 | destsubdir = extvars['destsubdir'] |
| @@ -793,20 +810,27 @@ def bbappend_recipe(rd, destlayerdir, srcfiles, install=None, wildcardver=False, | |||
| 793 | updated = True | 810 | updated = True |
| 794 | 811 | ||
| 795 | if updated: | 812 | if updated: |
| 796 | with open(appendpath, 'w') as f: | 813 | with open(outfile, 'w') as f: |
| 797 | f.writelines(newlines) | 814 | f.writelines(newlines) |
| 798 | 815 | ||
| 799 | if copyfiles: | 816 | if copyfiles: |
| 800 | if machine: | 817 | if machine: |
| 801 | destsubdir = os.path.join(destsubdir, machine) | 818 | destsubdir = os.path.join(destsubdir, machine) |
| 819 | if redirect_output: | ||
| 820 | outdir = redirect_output | ||
| 821 | else: | ||
| 822 | outdir = appenddir | ||
| 802 | for newfile, srcfile in copyfiles.items(): | 823 | for newfile, srcfile in copyfiles.items(): |
| 803 | filedest = os.path.join(appenddir, destsubdir, os.path.basename(srcfile)) | 824 | filedest = os.path.join(outdir, destsubdir, os.path.basename(srcfile)) |
| 804 | if os.path.abspath(newfile) != os.path.abspath(filedest): | 825 | if os.path.abspath(newfile) != os.path.abspath(filedest): |
| 805 | if newfile.startswith(tempfile.gettempdir()): | 826 | if newfile.startswith(tempfile.gettempdir()): |
| 806 | newfiledisp = os.path.basename(newfile) | 827 | newfiledisp = os.path.basename(newfile) |
| 807 | else: | 828 | else: |
| 808 | newfiledisp = newfile | 829 | newfiledisp = newfile |
| 809 | bb.note('Copying %s to %s' % (newfiledisp, filedest)) | 830 | if redirect_output: |
| 831 | bb.note('Copying %s to %s (dry-run)' % (newfiledisp, os.path.join(appenddir, destsubdir, os.path.basename(srcfile)))) | ||
| 832 | else: | ||
| 833 | bb.note('Copying %s to %s' % (newfiledisp, filedest)) | ||
| 810 | bb.utils.mkdirhier(os.path.dirname(filedest)) | 834 | bb.utils.mkdirhier(os.path.dirname(filedest)) |
| 811 | shutil.copyfile(newfile, filedest) | 835 | shutil.copyfile(newfile, filedest) |
| 812 | 836 | ||
