summaryrefslogtreecommitdiffstats
path: root/scripts/lib
diff options
context:
space:
mode:
authorJulien Stephan <jstephan@baylibre.com>2023-12-05 15:56:27 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-12-06 22:55:49 +0000
commitde5ab8e8634bf3ced0b04dc14c56f14019f516b8 (patch)
tree56551002d04e096a0bcd3470ea1bff9e81ec92ae /scripts/lib
parent2c59f5ad01aa0e6dfd1e6291e770c77041be762e (diff)
downloadpoky-de5ab8e8634bf3ced0b04dc14c56f14019f516b8.tar.gz
recipetool: appendsrcfile(s): add dry-run mode
Add dry-run mode for recipetool appendsrcfile and appendsrcfiles, with if necessary, a diff of changes (From OE-Core rev: 456c726e6b52f4dc57ff605e1cf1687097537002) Signed-off-by: Julien Stephan <jstephan@baylibre.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib')
-rw-r--r--scripts/lib/recipetool/append.py33
1 files changed, 32 insertions, 1 deletions
diff --git a/scripts/lib/recipetool/append.py b/scripts/lib/recipetool/append.py
index 4b6a7112c2..58512e9e4b 100644
--- a/scripts/lib/recipetool/append.py
+++ b/scripts/lib/recipetool/append.py
@@ -18,6 +18,7 @@ import shutil
18import scriptutils 18import scriptutils
19import errno 19import errno
20from collections import defaultdict 20from collections import defaultdict
21import difflib
21 22
22logger = logging.getLogger('recipetool') 23logger = logging.getLogger('recipetool')
23 24
@@ -355,7 +356,35 @@ def appendsrc(args, files, rd, extralines=None):
355 extralines.append('SRC_URI += {0}'.format(source_uri)) 356 extralines.append('SRC_URI += {0}'.format(source_uri))
356 copyfiles[newfile] = {'path' : srcfile} 357 copyfiles[newfile] = {'path' : srcfile}
357 358
358 oe.recipeutils.bbappend_recipe(rd, args.destlayer, copyfiles, None, wildcardver=args.wildcard_version, machine=args.machine, extralines=extralines) 359 dry_run_output = None
360 dry_run_outdir = None
361 if args.dry_run:
362 import tempfile
363 dry_run_output = tempfile.TemporaryDirectory(prefix='devtool')
364 dry_run_outdir = dry_run_output.name
365
366 appendfile, _ = oe.recipeutils.bbappend_recipe(rd, args.destlayer, copyfiles, None, wildcardver=args.wildcard_version, machine=args.machine, extralines=extralines, redirect_output=dry_run_outdir)
367 if args.dry_run:
368 output = ''
369 appendfilename = os.path.basename(appendfile)
370 newappendfile = appendfile
371 if appendfile and os.path.exists(appendfile):
372 with open(appendfile, 'r') as f:
373 oldlines = f.readlines()
374 else:
375 appendfile = '/dev/null'
376 oldlines = []
377
378 with open(os.path.join(dry_run_outdir, appendfilename), 'r') as f:
379 newlines = f.readlines()
380 diff = difflib.unified_diff(oldlines, newlines, appendfile, newappendfile)
381 difflines = list(diff)
382 if difflines:
383 output += ''.join(difflines)
384 if output:
385 logger.info('Diff of changed files:\n%s' % output)
386 else:
387 logger.info('No changed files')
359 tinfoil.modified_files() 388 tinfoil.modified_files()
360 389
361def appendsrcfiles(parser, args): 390def appendsrcfiles(parser, args):
@@ -436,6 +465,7 @@ def register_commands(subparsers):
436 help='Create/update a bbappend to add or replace source files', 465 help='Create/update a bbappend to add or replace source files',
437 description='Creates a bbappend (or updates an existing one) to add or replace the specified file in the recipe sources, either those in WORKDIR or those in the source tree. This command lets you specify multiple files with a destination directory, so cannot specify the destination filename. See the `appendsrcfile` command for the other behavior.') 466 description='Creates a bbappend (or updates an existing one) to add or replace the specified file in the recipe sources, either those in WORKDIR or those in the source tree. This command lets you specify multiple files with a destination directory, so cannot specify the destination filename. See the `appendsrcfile` command for the other behavior.')
438 parser.add_argument('-D', '--destdir', help='Destination directory (relative to S or WORKDIR, defaults to ".")', default='', type=destination_path) 467 parser.add_argument('-D', '--destdir', help='Destination directory (relative to S or WORKDIR, defaults to ".")', default='', type=destination_path)
468 parser.add_argument('-n', '--dry-run', help='Dry run mode', action='store_true')
439 parser.add_argument('files', nargs='+', metavar='FILE', help='File(s) to be added to the recipe sources (WORKDIR or S)', type=existing_path) 469 parser.add_argument('files', nargs='+', metavar='FILE', help='File(s) to be added to the recipe sources (WORKDIR or S)', type=existing_path)
440 parser.set_defaults(func=lambda a: appendsrcfiles(parser, a), parserecipes=True) 470 parser.set_defaults(func=lambda a: appendsrcfiles(parser, a), parserecipes=True)
441 471
@@ -443,6 +473,7 @@ def register_commands(subparsers):
443 parents=[common_src], 473 parents=[common_src],
444 help='Create/update a bbappend to add or replace a source file', 474 help='Create/update a bbappend to add or replace a source file',
445 description='Creates a bbappend (or updates an existing one) to add or replace the specified files in the recipe sources, either those in WORKDIR or those in the source tree. This command lets you specify the destination filename, not just destination directory, but only works for one file. See the `appendsrcfiles` command for the other behavior.') 475 description='Creates a bbappend (or updates an existing one) to add or replace the specified files in the recipe sources, either those in WORKDIR or those in the source tree. This command lets you specify the destination filename, not just destination directory, but only works for one file. See the `appendsrcfiles` command for the other behavior.')
476 parser.add_argument('-n', '--dry-run', help='Dry run mode', action='store_true')
446 parser.add_argument('file', metavar='FILE', help='File to be added to the recipe sources (WORKDIR or S)', type=existing_path) 477 parser.add_argument('file', metavar='FILE', help='File to be added to the recipe sources (WORKDIR or S)', type=existing_path)
447 parser.add_argument('destfile', metavar='DESTFILE', nargs='?', help='Destination path (relative to S or WORKDIR, optional)', type=destination_path) 478 parser.add_argument('destfile', metavar='DESTFILE', nargs='?', help='Destination path (relative to S or WORKDIR, optional)', type=destination_path)
448 parser.set_defaults(func=lambda a: appendsrcfile(parser, a), parserecipes=True) 479 parser.set_defaults(func=lambda a: appendsrcfile(parser, a), parserecipes=True)