summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Stephan <jstephan@baylibre.com>2023-12-05 15:56:32 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-12-06 22:55:49 +0000
commit29dc0d73154f60635da740f9785f02740816a2fa (patch)
tree76bccf0e05cb6b2d933db18b96d581f44f60e4f8
parent165626f7b97d905835337bdde9e30fd54d15cc08 (diff)
downloadpoky-29dc0d73154f60635da740f9785f02740816a2fa.tar.gz
recipetool: appendsrcfile(s): use params instead of extraline
appendsrc function relies on oe.recipeutils.bbappend_recipe to copy files and add the corresponding entries in SRC_URI. Currently, appendsrc function build itself the new SRC_URI entry to add the correct subdir param, and gives it using the extralines parameter. This has 2 drawbacks: - oe.recipeutils.bbappend_recipe can already do this if we specify the correct params, so we have duplicate code - the duplicated code is not fully functional: for example, it doesn't take into account the -m/--machine parameter So fix this by not using extralines but give correctly formatted params. Also remove the check for already existing entries as oe.recipeutils.bbappend_recipe already implement it The new bbappend file now have the SRC_URI entry after the FILESEXTRAPATHS so fix the selftest. Update test_recipetool_appendsrcfile_existing_in_src_uri_diff_params test because recipetool appendsrcfiles used to not add new src_uri entry if the entry already exist even with different parameters while oe.recipeutils.bbappend_recipe adds it if parameters are different (and remove the old entry) (From OE-Core rev: cd5de8d53849a6f3bb6f82e45fb301e39892c789) 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>
-rw-r--r--meta/lib/oeqa/selftest/cases/recipetool.py21
-rw-r--r--scripts/lib/recipetool/append.py26
2 files changed, 23 insertions, 24 deletions
diff --git a/meta/lib/oeqa/selftest/cases/recipetool.py b/meta/lib/oeqa/selftest/cases/recipetool.py
index b59e53f599..fa3bfa4625 100644
--- a/meta/lib/oeqa/selftest/cases/recipetool.py
+++ b/meta/lib/oeqa/selftest/cases/recipetool.py
@@ -1108,9 +1108,9 @@ class RecipetoolAppendsrcBase(RecipetoolBase):
1108 for uri in src_uri: 1108 for uri in src_uri:
1109 p = urllib.parse.urlparse(uri) 1109 p = urllib.parse.urlparse(uri)
1110 if p.scheme == 'file': 1110 if p.scheme == 'file':
1111 return p.netloc + p.path 1111 return p.netloc + p.path, uri
1112 1112
1113 def _test_appendsrcfile(self, testrecipe, filename=None, destdir=None, has_src_uri=True, srcdir=None, newfile=None, options=''): 1113 def _test_appendsrcfile(self, testrecipe, filename=None, destdir=None, has_src_uri=True, srcdir=None, newfile=None, remove=None, options=''):
1114 if newfile is None: 1114 if newfile is None:
1115 newfile = self.testfile 1115 newfile = self.testfile
1116 1116
@@ -1137,12 +1137,18 @@ class RecipetoolAppendsrcBase(RecipetoolBase):
1137 1137
1138 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n', 1138 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
1139 '\n'] 1139 '\n']
1140
1141 if remove:
1142 for entry in remove:
1143 expectedlines.extend(['SRC_URI:remove = "%s"\n' % entry,
1144 '\n'])
1145
1140 if has_src_uri: 1146 if has_src_uri:
1141 uri = 'file://%s' % filename 1147 uri = 'file://%s' % filename
1142 if expected_subdir: 1148 if expected_subdir:
1143 uri += ';subdir=%s' % expected_subdir 1149 uri += ';subdir=%s' % expected_subdir
1144 expectedlines[0:0] = ['SRC_URI += "%s"\n' % uri, 1150 expectedlines.extend(['SRC_URI += "%s"\n' % uri,
1145 '\n'] 1151 '\n'])
1146 1152
1147 return self._try_recipetool_appendsrcfile(testrecipe, newfile, destpath, options, expectedlines, [filename]) 1153 return self._try_recipetool_appendsrcfile(testrecipe, newfile, destpath, options, expectedlines, [filename])
1148 1154
@@ -1197,18 +1203,17 @@ class RecipetoolAppendsrcTests(RecipetoolAppendsrcBase):
1197 1203
1198 def test_recipetool_appendsrcfile_existing_in_src_uri(self): 1204 def test_recipetool_appendsrcfile_existing_in_src_uri(self):
1199 testrecipe = 'base-files' 1205 testrecipe = 'base-files'
1200 filepath = self._get_first_file_uri(testrecipe) 1206 filepath,_ = self._get_first_file_uri(testrecipe)
1201 self.assertTrue(filepath, 'Unable to test, no file:// uri found in SRC_URI for %s' % testrecipe) 1207 self.assertTrue(filepath, 'Unable to test, no file:// uri found in SRC_URI for %s' % testrecipe)
1202 self._test_appendsrcfile(testrecipe, filepath, has_src_uri=False) 1208 self._test_appendsrcfile(testrecipe, filepath, has_src_uri=False)
1203 1209
1204 def test_recipetool_appendsrcfile_existing_in_src_uri_diff_params(self): 1210 def test_recipetool_appendsrcfile_existing_in_src_uri_diff_params(self):
1205 testrecipe = 'base-files' 1211 testrecipe = 'base-files'
1206 subdir = 'tmp' 1212 subdir = 'tmp'
1207 filepath = self._get_first_file_uri(testrecipe) 1213 filepath, srcuri_entry = self._get_first_file_uri(testrecipe)
1208 self.assertTrue(filepath, 'Unable to test, no file:// uri found in SRC_URI for %s' % testrecipe) 1214 self.assertTrue(filepath, 'Unable to test, no file:// uri found in SRC_URI for %s' % testrecipe)
1209 1215
1210 output = self._test_appendsrcfile(testrecipe, filepath, subdir, has_src_uri=False) 1216 self._test_appendsrcfile(testrecipe, filepath, subdir, remove=[srcuri_entry])
1211 self.assertTrue(any('with different parameters' in l for l in output))
1212 1217
1213 def test_recipetool_appendsrcfile_replace_file_srcdir(self): 1218 def test_recipetool_appendsrcfile_replace_file_srcdir(self):
1214 testrecipe = 'bash' 1219 testrecipe = 'bash'
diff --git a/scripts/lib/recipetool/append.py b/scripts/lib/recipetool/append.py
index 58512e9e4b..fc3cc4a0b7 100644
--- a/scripts/lib/recipetool/append.py
+++ b/scripts/lib/recipetool/append.py
@@ -300,7 +300,9 @@ def appendfile(args):
300 if st.st_mode & stat.S_IXUSR: 300 if st.st_mode & stat.S_IXUSR:
301 perms = '0755' 301 perms = '0755'
302 install = {args.newfile: (args.targetpath, perms)} 302 install = {args.newfile: (args.targetpath, perms)}
303 oe.recipeutils.bbappend_recipe(rd, args.destlayer, {args.newfile: {'path' : sourcepath}}, install, wildcardver=args.wildcard_version, machine=args.machine) 303 if sourcepath:
304 sourcepath = os.path.basename(sourcepath)
305 oe.recipeutils.bbappend_recipe(rd, args.destlayer, {args.newfile: {'newname' : sourcepath}}, install, wildcardver=args.wildcard_version, machine=args.machine)
304 tinfoil.modified_files() 306 tinfoil.modified_files()
305 return 0 307 return 0
306 else: 308 else:
@@ -329,6 +331,7 @@ def appendsrc(args, files, rd, extralines=None):
329 331
330 copyfiles = {} 332 copyfiles = {}
331 extralines = extralines or [] 333 extralines = extralines or []
334 params = []
332 for newfile, srcfile in files.items(): 335 for newfile, srcfile in files.items():
333 src_destdir = os.path.dirname(srcfile) 336 src_destdir = os.path.dirname(srcfile)
334 if not args.use_workdir: 337 if not args.use_workdir:
@@ -339,22 +342,12 @@ def appendsrc(args, files, rd, extralines=None):
339 src_destdir = os.path.join(os.path.relpath(srcdir, workdir), src_destdir) 342 src_destdir = os.path.join(os.path.relpath(srcdir, workdir), src_destdir)
340 src_destdir = os.path.normpath(src_destdir) 343 src_destdir = os.path.normpath(src_destdir)
341 344
342 source_uri = 'file://{0}'.format(os.path.basename(srcfile))
343 if src_destdir and src_destdir != '.': 345 if src_destdir and src_destdir != '.':
344 source_uri += ';subdir={0}'.format(src_destdir) 346 params.append({'subdir': src_destdir})
345
346 simple = bb.fetch.URI(source_uri)
347 simple.params = {}
348 simple_str = str(simple)
349 if simple_str in simplified:
350 existing = simplified[simple_str]
351 if source_uri != existing:
352 logger.warning('{0!r} is already in SRC_URI, with different parameters: {1!r}, not adding'.format(source_uri, existing))
353 else:
354 logger.warning('{0!r} is already in SRC_URI, not adding'.format(source_uri))
355 else: 347 else:
356 extralines.append('SRC_URI += {0}'.format(source_uri)) 348 params.append({})
357 copyfiles[newfile] = {'path' : srcfile} 349
350 copyfiles[newfile] = {'newname' : os.path.basename(srcfile)}
358 351
359 dry_run_output = None 352 dry_run_output = None
360 dry_run_outdir = None 353 dry_run_outdir = None
@@ -363,7 +356,8 @@ def appendsrc(args, files, rd, extralines=None):
363 dry_run_output = tempfile.TemporaryDirectory(prefix='devtool') 356 dry_run_output = tempfile.TemporaryDirectory(prefix='devtool')
364 dry_run_outdir = dry_run_output.name 357 dry_run_outdir = dry_run_output.name
365 358
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) 359 appendfile, _ = oe.recipeutils.bbappend_recipe(rd, args.destlayer, copyfiles, None, wildcardver=args.wildcard_version, machine=args.machine, extralines=extralines, params=params,
360 redirect_output=dry_run_outdir)
367 if args.dry_run: 361 if args.dry_run:
368 output = '' 362 output = ''
369 appendfilename = os.path.basename(appendfile) 363 appendfilename = os.path.basename(appendfile)