diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-01-04 13:05:33 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-01-05 11:52:50 +0000 |
commit | 93be2cdf492e1ec3d3c13f9c2ce82346be323da6 (patch) | |
tree | 2678b4740c7ff1c1b4a0fa32d9b5bdb74e6b1241 /meta | |
parent | ed07d52b476a22959cdd1c61d1c396345f996bbf (diff) | |
download | poky-93be2cdf492e1ec3d3c13f9c2ce82346be323da6.tar.gz |
package: Move get_conffiles/files_from_filevars functions to lib
To avoid reparsing the bbclass code all the time, move the functions
to the python function library code which is more efficient.
(From OE-Core rev: 424e65627c018b3119050f515b0c7cfb43be5573)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r-- | meta/classes-global/package.bbclass | 78 | ||||
-rw-r--r-- | meta/classes-global/package_deb.bbclass | 2 | ||||
-rw-r--r-- | meta/classes-global/package_ipk.bbclass | 2 | ||||
-rw-r--r-- | meta/classes-global/package_rpm.bbclass | 2 | ||||
-rw-r--r-- | meta/lib/oe/package.py | 77 |
5 files changed, 81 insertions, 80 deletions
diff --git a/meta/classes-global/package.bbclass b/meta/classes-global/package.bbclass index 29f0c80abd..a31224f243 100644 --- a/meta/classes-global/package.bbclass +++ b/meta/classes-global/package.bbclass | |||
@@ -257,82 +257,6 @@ python () { | |||
257 | d.appendVarFlag('do_package', 'deptask', " do_packagedata") | 257 | d.appendVarFlag('do_package', 'deptask', " do_packagedata") |
258 | } | 258 | } |
259 | 259 | ||
260 | # Get a list of files from file vars by searching files under current working directory | ||
261 | # The list contains symlinks, directories and normal files. | ||
262 | def files_from_filevars(filevars): | ||
263 | import os,glob | ||
264 | cpath = oe.cachedpath.CachedPath() | ||
265 | files = [] | ||
266 | for f in filevars: | ||
267 | if os.path.isabs(f): | ||
268 | f = '.' + f | ||
269 | if not f.startswith("./"): | ||
270 | f = './' + f | ||
271 | globbed = glob.glob(f) | ||
272 | if globbed: | ||
273 | if [ f ] != globbed: | ||
274 | files += globbed | ||
275 | continue | ||
276 | files.append(f) | ||
277 | |||
278 | symlink_paths = [] | ||
279 | for ind, f in enumerate(files): | ||
280 | # Handle directory symlinks. Truncate path to the lowest level symlink | ||
281 | parent = '' | ||
282 | for dirname in f.split('/')[:-1]: | ||
283 | parent = os.path.join(parent, dirname) | ||
284 | if dirname == '.': | ||
285 | continue | ||
286 | if cpath.islink(parent): | ||
287 | bb.warn("FILES contains file '%s' which resides under a " | ||
288 | "directory symlink. Please fix the recipe and use the " | ||
289 | "real path for the file." % f[1:]) | ||
290 | symlink_paths.append(f) | ||
291 | files[ind] = parent | ||
292 | f = parent | ||
293 | break | ||
294 | |||
295 | if not cpath.islink(f): | ||
296 | if cpath.isdir(f): | ||
297 | newfiles = [ os.path.join(f,x) for x in os.listdir(f) ] | ||
298 | if newfiles: | ||
299 | files += newfiles | ||
300 | |||
301 | return files, symlink_paths | ||
302 | |||
303 | # Called in package_<rpm,ipk,deb>.bbclass to get the correct list of configuration files | ||
304 | def get_conffiles(pkg, d): | ||
305 | pkgdest = d.getVar('PKGDEST') | ||
306 | root = os.path.join(pkgdest, pkg) | ||
307 | cwd = os.getcwd() | ||
308 | os.chdir(root) | ||
309 | |||
310 | conffiles = d.getVar('CONFFILES:%s' % pkg); | ||
311 | if conffiles == None: | ||
312 | conffiles = d.getVar('CONFFILES') | ||
313 | if conffiles == None: | ||
314 | conffiles = "" | ||
315 | conffiles = conffiles.split() | ||
316 | conf_orig_list = files_from_filevars(conffiles)[0] | ||
317 | |||
318 | # Remove links and directories from conf_orig_list to get conf_list which only contains normal files | ||
319 | conf_list = [] | ||
320 | for f in conf_orig_list: | ||
321 | if os.path.isdir(f): | ||
322 | continue | ||
323 | if os.path.islink(f): | ||
324 | continue | ||
325 | if not os.path.exists(f): | ||
326 | continue | ||
327 | conf_list.append(f) | ||
328 | |||
329 | # Remove the leading './' | ||
330 | for i in range(0, len(conf_list)): | ||
331 | conf_list[i] = conf_list[i][1:] | ||
332 | |||
333 | os.chdir(cwd) | ||
334 | return conf_list | ||
335 | |||
336 | def checkbuildpath(file, d): | 260 | def checkbuildpath(file, d): |
337 | tmpdir = d.getVar('TMPDIR') | 261 | tmpdir = d.getVar('TMPDIR') |
338 | with open(file) as f: | 262 | with open(file) as f: |
@@ -1209,7 +1133,7 @@ python populate_packages () { | |||
1209 | filesvar.replace("//", "/") | 1133 | filesvar.replace("//", "/") |
1210 | 1134 | ||
1211 | origfiles = filesvar.split() | 1135 | origfiles = filesvar.split() |
1212 | files, symlink_paths = files_from_filevars(origfiles) | 1136 | files, symlink_paths = oe.package.files_from_filevars(origfiles) |
1213 | 1137 | ||
1214 | if autodebug and pkg.endswith("-dbg"): | 1138 | if autodebug and pkg.endswith("-dbg"): |
1215 | files.extend(debug) | 1139 | files.extend(debug) |
diff --git a/meta/classes-global/package_deb.bbclass b/meta/classes-global/package_deb.bbclass index ec7e10dbc9..c3ae7d574d 100644 --- a/meta/classes-global/package_deb.bbclass +++ b/meta/classes-global/package_deb.bbclass | |||
@@ -269,7 +269,7 @@ def deb_write_pkg(pkg, d): | |||
269 | scriptfile.close() | 269 | scriptfile.close() |
270 | os.chmod(os.path.join(controldir, script), 0o755) | 270 | os.chmod(os.path.join(controldir, script), 0o755) |
271 | 271 | ||
272 | conffiles_str = ' '.join(get_conffiles(pkg, d)) | 272 | conffiles_str = ' '.join(oe.package.get_conffiles(pkg, d)) |
273 | if conffiles_str: | 273 | if conffiles_str: |
274 | conffiles = open(os.path.join(controldir, 'conffiles'), 'w') | 274 | conffiles = open(os.path.join(controldir, 'conffiles'), 'w') |
275 | for f in conffiles_str.split(): | 275 | for f in conffiles_str.split(): |
diff --git a/meta/classes-global/package_ipk.bbclass b/meta/classes-global/package_ipk.bbclass index c43592af7e..0207ea874b 100644 --- a/meta/classes-global/package_ipk.bbclass +++ b/meta/classes-global/package_ipk.bbclass | |||
@@ -226,7 +226,7 @@ def ipk_write_pkg(pkg, d): | |||
226 | scriptfile.close() | 226 | scriptfile.close() |
227 | os.chmod(os.path.join(controldir, script), 0o755) | 227 | os.chmod(os.path.join(controldir, script), 0o755) |
228 | 228 | ||
229 | conffiles_str = ' '.join(get_conffiles(pkg, d)) | 229 | conffiles_str = ' '.join(oe.package.get_conffiles(pkg, d)) |
230 | if conffiles_str: | 230 | if conffiles_str: |
231 | conffiles = open(os.path.join(controldir, 'conffiles'), 'w') | 231 | conffiles = open(os.path.join(controldir, 'conffiles'), 'w') |
232 | for f in conffiles_str.split(): | 232 | for f in conffiles_str.split(): |
diff --git a/meta/classes-global/package_rpm.bbclass b/meta/classes-global/package_rpm.bbclass index 39efcc328e..7ba73f48e7 100644 --- a/meta/classes-global/package_rpm.bbclass +++ b/meta/classes-global/package_rpm.bbclass | |||
@@ -341,7 +341,7 @@ python write_specfile () { | |||
341 | 341 | ||
342 | localdata.setVar('OVERRIDES', d.getVar("OVERRIDES", False) + ":" + pkg) | 342 | localdata.setVar('OVERRIDES', d.getVar("OVERRIDES", False) + ":" + pkg) |
343 | 343 | ||
344 | conffiles = get_conffiles(pkg, d) | 344 | conffiles = oe.package.get_conffiles(pkg, d) |
345 | dirfiles = localdata.getVar('DIRFILES') | 345 | dirfiles = localdata.getVar('DIRFILES') |
346 | if dirfiles is not None: | 346 | if dirfiles is not None: |
347 | dirfiles = dirfiles.split() | 347 | dirfiles = dirfiles.split() |
diff --git a/meta/lib/oe/package.py b/meta/lib/oe/package.py index 05447f8808..b4c8ab7222 100644 --- a/meta/lib/oe/package.py +++ b/meta/lib/oe/package.py | |||
@@ -4,6 +4,8 @@ | |||
4 | # SPDX-License-Identifier: GPL-2.0-only | 4 | # SPDX-License-Identifier: GPL-2.0-only |
5 | # | 5 | # |
6 | 6 | ||
7 | import os | ||
8 | import glob | ||
7 | import stat | 9 | import stat |
8 | import mmap | 10 | import mmap |
9 | import subprocess | 11 | import subprocess |
@@ -532,5 +534,80 @@ def fixup_perms(d): | |||
532 | each_file = os.path.join(root, f) | 534 | each_file = os.path.join(root, f) |
533 | fix_perms(each_file, fs_perms_table[dir].fmode, fs_perms_table[dir].fuid, fs_perms_table[dir].fgid, dir) | 535 | fix_perms(each_file, fs_perms_table[dir].fmode, fs_perms_table[dir].fuid, fs_perms_table[dir].fgid, dir) |
534 | 536 | ||
537 | # Get a list of files from file vars by searching files under current working directory | ||
538 | # The list contains symlinks, directories and normal files. | ||
539 | def files_from_filevars(filevars): | ||
540 | import oe.cachedpath | ||
541 | |||
542 | cpath = oe.cachedpath.CachedPath() | ||
543 | files = [] | ||
544 | for f in filevars: | ||
545 | if os.path.isabs(f): | ||
546 | f = '.' + f | ||
547 | if not f.startswith("./"): | ||
548 | f = './' + f | ||
549 | globbed = glob.glob(f) | ||
550 | if globbed: | ||
551 | if [ f ] != globbed: | ||
552 | files += globbed | ||
553 | continue | ||
554 | files.append(f) | ||
555 | |||
556 | symlink_paths = [] | ||
557 | for ind, f in enumerate(files): | ||
558 | # Handle directory symlinks. Truncate path to the lowest level symlink | ||
559 | parent = '' | ||
560 | for dirname in f.split('/')[:-1]: | ||
561 | parent = os.path.join(parent, dirname) | ||
562 | if dirname == '.': | ||
563 | continue | ||
564 | if cpath.islink(parent): | ||
565 | bb.warn("FILES contains file '%s' which resides under a " | ||
566 | "directory symlink. Please fix the recipe and use the " | ||
567 | "real path for the file." % f[1:]) | ||
568 | symlink_paths.append(f) | ||
569 | files[ind] = parent | ||
570 | f = parent | ||
571 | break | ||
572 | |||
573 | if not cpath.islink(f): | ||
574 | if cpath.isdir(f): | ||
575 | newfiles = [ os.path.join(f,x) for x in os.listdir(f) ] | ||
576 | if newfiles: | ||
577 | files += newfiles | ||
578 | |||
579 | return files, symlink_paths | ||
580 | |||
581 | # Called in package_<rpm,ipk,deb>.bbclass to get the correct list of configuration files | ||
582 | def get_conffiles(pkg, d): | ||
583 | pkgdest = d.getVar('PKGDEST') | ||
584 | root = os.path.join(pkgdest, pkg) | ||
585 | cwd = os.getcwd() | ||
586 | os.chdir(root) | ||
587 | |||
588 | conffiles = d.getVar('CONFFILES:%s' % pkg); | ||
589 | if conffiles == None: | ||
590 | conffiles = d.getVar('CONFFILES') | ||
591 | if conffiles == None: | ||
592 | conffiles = "" | ||
593 | conffiles = conffiles.split() | ||
594 | conf_orig_list = files_from_filevars(conffiles)[0] | ||
595 | |||
596 | # Remove links and directories from conf_orig_list to get conf_list which only contains normal files | ||
597 | conf_list = [] | ||
598 | for f in conf_orig_list: | ||
599 | if os.path.isdir(f): | ||
600 | continue | ||
601 | if os.path.islink(f): | ||
602 | continue | ||
603 | if not os.path.exists(f): | ||
604 | continue | ||
605 | conf_list.append(f) | ||
606 | |||
607 | # Remove the leading './' | ||
608 | for i in range(0, len(conf_list)): | ||
609 | conf_list[i] = conf_list[i][1:] | ||
535 | 610 | ||
611 | os.chdir(cwd) | ||
612 | return conf_list | ||
536 | 613 | ||