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>
This commit is contained in:
Richard Purdie
2023-01-04 13:05:33 +00:00
parent ed07d52b47
commit 93be2cdf49
5 changed files with 81 additions and 80 deletions

View File

@@ -257,82 +257,6 @@ python () {
d.appendVarFlag('do_package', 'deptask', " do_packagedata")
}
# Get a list of files from file vars by searching files under current working directory
# The list contains symlinks, directories and normal files.
def files_from_filevars(filevars):
import os,glob
cpath = oe.cachedpath.CachedPath()
files = []
for f in filevars:
if os.path.isabs(f):
f = '.' + f
if not f.startswith("./"):
f = './' + f
globbed = glob.glob(f)
if globbed:
if [ f ] != globbed:
files += globbed
continue
files.append(f)
symlink_paths = []
for ind, f in enumerate(files):
# Handle directory symlinks. Truncate path to the lowest level symlink
parent = ''
for dirname in f.split('/')[:-1]:
parent = os.path.join(parent, dirname)
if dirname == '.':
continue
if cpath.islink(parent):
bb.warn("FILES contains file '%s' which resides under a "
"directory symlink. Please fix the recipe and use the "
"real path for the file." % f[1:])
symlink_paths.append(f)
files[ind] = parent
f = parent
break
if not cpath.islink(f):
if cpath.isdir(f):
newfiles = [ os.path.join(f,x) for x in os.listdir(f) ]
if newfiles:
files += newfiles
return files, symlink_paths
# Called in package_<rpm,ipk,deb>.bbclass to get the correct list of configuration files
def get_conffiles(pkg, d):
pkgdest = d.getVar('PKGDEST')
root = os.path.join(pkgdest, pkg)
cwd = os.getcwd()
os.chdir(root)
conffiles = d.getVar('CONFFILES:%s' % pkg);
if conffiles == None:
conffiles = d.getVar('CONFFILES')
if conffiles == None:
conffiles = ""
conffiles = conffiles.split()
conf_orig_list = files_from_filevars(conffiles)[0]
# Remove links and directories from conf_orig_list to get conf_list which only contains normal files
conf_list = []
for f in conf_orig_list:
if os.path.isdir(f):
continue
if os.path.islink(f):
continue
if not os.path.exists(f):
continue
conf_list.append(f)
# Remove the leading './'
for i in range(0, len(conf_list)):
conf_list[i] = conf_list[i][1:]
os.chdir(cwd)
return conf_list
def checkbuildpath(file, d):
tmpdir = d.getVar('TMPDIR')
with open(file) as f:
@@ -1209,7 +1133,7 @@ python populate_packages () {
filesvar.replace("//", "/")
origfiles = filesvar.split()
files, symlink_paths = files_from_filevars(origfiles)
files, symlink_paths = oe.package.files_from_filevars(origfiles)
if autodebug and pkg.endswith("-dbg"):
files.extend(debug)

View File

@@ -269,7 +269,7 @@ def deb_write_pkg(pkg, d):
scriptfile.close()
os.chmod(os.path.join(controldir, script), 0o755)
conffiles_str = ' '.join(get_conffiles(pkg, d))
conffiles_str = ' '.join(oe.package.get_conffiles(pkg, d))
if conffiles_str:
conffiles = open(os.path.join(controldir, 'conffiles'), 'w')
for f in conffiles_str.split():

View File

@@ -226,7 +226,7 @@ def ipk_write_pkg(pkg, d):
scriptfile.close()
os.chmod(os.path.join(controldir, script), 0o755)
conffiles_str = ' '.join(get_conffiles(pkg, d))
conffiles_str = ' '.join(oe.package.get_conffiles(pkg, d))
if conffiles_str:
conffiles = open(os.path.join(controldir, 'conffiles'), 'w')
for f in conffiles_str.split():

View File

@@ -341,7 +341,7 @@ python write_specfile () {
localdata.setVar('OVERRIDES', d.getVar("OVERRIDES", False) + ":" + pkg)
conffiles = get_conffiles(pkg, d)
conffiles = oe.package.get_conffiles(pkg, d)
dirfiles = localdata.getVar('DIRFILES')
if dirfiles is not None:
dirfiles = dirfiles.split()

View File

@@ -4,6 +4,8 @@
# SPDX-License-Identifier: GPL-2.0-only
#
import os
import glob
import stat
import mmap
import subprocess
@@ -532,5 +534,80 @@ def fixup_perms(d):
each_file = os.path.join(root, f)
fix_perms(each_file, fs_perms_table[dir].fmode, fs_perms_table[dir].fuid, fs_perms_table[dir].fgid, dir)
# Get a list of files from file vars by searching files under current working directory
# The list contains symlinks, directories and normal files.
def files_from_filevars(filevars):
import oe.cachedpath
cpath = oe.cachedpath.CachedPath()
files = []
for f in filevars:
if os.path.isabs(f):
f = '.' + f
if not f.startswith("./"):
f = './' + f
globbed = glob.glob(f)
if globbed:
if [ f ] != globbed:
files += globbed
continue
files.append(f)
symlink_paths = []
for ind, f in enumerate(files):
# Handle directory symlinks. Truncate path to the lowest level symlink
parent = ''
for dirname in f.split('/')[:-1]:
parent = os.path.join(parent, dirname)
if dirname == '.':
continue
if cpath.islink(parent):
bb.warn("FILES contains file '%s' which resides under a "
"directory symlink. Please fix the recipe and use the "
"real path for the file." % f[1:])
symlink_paths.append(f)
files[ind] = parent
f = parent
break
if not cpath.islink(f):
if cpath.isdir(f):
newfiles = [ os.path.join(f,x) for x in os.listdir(f) ]
if newfiles:
files += newfiles
return files, symlink_paths
# Called in package_<rpm,ipk,deb>.bbclass to get the correct list of configuration files
def get_conffiles(pkg, d):
pkgdest = d.getVar('PKGDEST')
root = os.path.join(pkgdest, pkg)
cwd = os.getcwd()
os.chdir(root)
conffiles = d.getVar('CONFFILES:%s' % pkg);
if conffiles == None:
conffiles = d.getVar('CONFFILES')
if conffiles == None:
conffiles = ""
conffiles = conffiles.split()
conf_orig_list = files_from_filevars(conffiles)[0]
# Remove links and directories from conf_orig_list to get conf_list which only contains normal files
conf_list = []
for f in conf_orig_list:
if os.path.isdir(f):
continue
if os.path.islink(f):
continue
if not os.path.exists(f):
continue
conf_list.append(f)
# Remove the leading './'
for i in range(0, len(conf_list)):
conf_list[i] = conf_list[i][1:]
os.chdir(cwd)
return conf_list