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/lib | |
| 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/lib')
| -rw-r--r-- | meta/lib/oe/package.py | 77 |
1 files changed, 77 insertions, 0 deletions
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 | ||
