mirror of
https://git.yoctoproject.org/poky
synced 2026-09-19 18:49:32 +02:00
insane: use oe.cachedpath.CachedPath instead of os.path
The insane QAPATHTESTs make many os.stat() calls, the majority of which are redundant with caching as the initial sweep does a stat() on every entry to determine if it is a file or a directory, and from then on each test that does further stat()s is redundant as the tree doesn't change. Switch os.stat() and friends (os.path.isfile(), etc) to use a common oe.cachedpath.CachedPath() instance that is shared between all of the functions, meaning only one stat is done. In my test case of ltp:do_package_qa, this reduces the time taken from 44s to 37s. (From OE-Core rev: cad3c889439fd6a007debd6f2f6578f4a1e16c9c) Signed-off-by: Ross Burton <ross.burton@arm.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
c812b378e0
commit
fe5cf7dc81
@@ -82,7 +82,9 @@ def package_qa_clean_path(path, d, pkg=None):
|
|||||||
|
|
||||||
QAPATHTEST[shebang-size] = "package_qa_check_shebang_size"
|
QAPATHTEST[shebang-size] = "package_qa_check_shebang_size"
|
||||||
def package_qa_check_shebang_size(path, name, d, elf):
|
def package_qa_check_shebang_size(path, name, d, elf):
|
||||||
if elf or os.path.islink(path) or not os.path.isfile(path):
|
global cpath
|
||||||
|
|
||||||
|
if elf or cpath.islink(path) or not cpath.isfile(path):
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -167,8 +169,8 @@ def package_qa_check_dev(path, name, d, elf):
|
|||||||
"""
|
"""
|
||||||
Check for ".so" library symlinks in non-dev packages
|
Check for ".so" library symlinks in non-dev packages
|
||||||
"""
|
"""
|
||||||
|
global cpath
|
||||||
if not name.endswith("-dev") and not name.endswith("-dbg") and not name.endswith("-ptest") and not name.startswith("nativesdk-") and path.endswith(".so") and os.path.islink(path):
|
if not name.endswith("-dev") and not name.endswith("-dbg") and not name.endswith("-ptest") and not name.startswith("nativesdk-") and path.endswith(".so") and cpath.islink(path):
|
||||||
oe.qa.handle_error("dev-so", "non -dev/-dbg/nativesdk- package %s contains symlink .so '%s'" % \
|
oe.qa.handle_error("dev-so", "non -dev/-dbg/nativesdk- package %s contains symlink .so '%s'" % \
|
||||||
(name, package_qa_clean_path(path, d, name)), d)
|
(name, package_qa_clean_path(path, d, name)), d)
|
||||||
|
|
||||||
@@ -179,7 +181,8 @@ def package_qa_check_dev_elf(path, name, d, elf):
|
|||||||
check that the file is not a link and is an ELF object as some recipes
|
check that the file is not a link and is an ELF object as some recipes
|
||||||
install link-time .so files that are linker scripts.
|
install link-time .so files that are linker scripts.
|
||||||
"""
|
"""
|
||||||
if name.endswith("-dev") and path.endswith(".so") and not os.path.islink(path) and elf:
|
global cpath
|
||||||
|
if name.endswith("-dev") and path.endswith(".so") and not cpath.islink(path) and elf:
|
||||||
oe.qa.handle_error("dev-elf", "-dev package %s contains non-symlink .so '%s'" % \
|
oe.qa.handle_error("dev-elf", "-dev package %s contains non-symlink .so '%s'" % \
|
||||||
(name, package_qa_clean_path(path, d, name)), d)
|
(name, package_qa_clean_path(path, d, name)), d)
|
||||||
|
|
||||||
@@ -422,9 +425,9 @@ def package_qa_check_buildpaths(path, name, d, elf):
|
|||||||
explicitly ignored.
|
explicitly ignored.
|
||||||
"""
|
"""
|
||||||
import stat
|
import stat
|
||||||
|
global cpath
|
||||||
# Ignore symlinks/devs/fifos
|
# Ignore symlinks/devs/fifos
|
||||||
mode = os.lstat(path).st_mode
|
mode = cpath.lstat(path).st_mode
|
||||||
if stat.S_ISLNK(mode) or stat.S_ISBLK(mode) or stat.S_ISFIFO(mode) or stat.S_ISCHR(mode) or stat.S_ISSOCK(mode):
|
if stat.S_ISLNK(mode) or stat.S_ISBLK(mode) or stat.S_ISFIFO(mode) or stat.S_ISCHR(mode) or stat.S_ISSOCK(mode):
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -469,7 +472,8 @@ def package_qa_check_symlink_to_sysroot(path, name, d, elf):
|
|||||||
"""
|
"""
|
||||||
Check that the package doesn't contain any absolute symlinks to the sysroot.
|
Check that the package doesn't contain any absolute symlinks to the sysroot.
|
||||||
"""
|
"""
|
||||||
if os.path.islink(path):
|
global cpath
|
||||||
|
if cpath.islink(path):
|
||||||
target = os.readlink(path)
|
target = os.readlink(path)
|
||||||
if os.path.isabs(target):
|
if os.path.isabs(target):
|
||||||
tmpdir = d.getVar('TMPDIR')
|
tmpdir = d.getVar('TMPDIR')
|
||||||
@@ -760,14 +764,19 @@ def qa_check_staged(path,d):
|
|||||||
oe.qa.handle_error("pkgconfig", error_msg, d)
|
oe.qa.handle_error("pkgconfig", error_msg, d)
|
||||||
|
|
||||||
if not skip_shebang_size:
|
if not skip_shebang_size:
|
||||||
|
global cpath
|
||||||
|
cpath = oe.cachedpath.CachedPath()
|
||||||
package_qa_check_shebang_size(path, "", d, None)
|
package_qa_check_shebang_size(path, "", d, None)
|
||||||
|
cpath = None
|
||||||
|
|
||||||
# Walk over all files in a directory and call func
|
# Walk over all files in a directory and call func
|
||||||
def package_qa_walk(checkfuncs, package, d):
|
def package_qa_walk(checkfuncs, package, d):
|
||||||
|
global cpath
|
||||||
|
|
||||||
elves = {}
|
elves = {}
|
||||||
for path in pkgfiles[package]:
|
for path in pkgfiles[package]:
|
||||||
elf = None
|
elf = None
|
||||||
if os.path.isfile(path) and not os.path.islink(path):
|
if cpath.isfile(path) and not cpath.islink(path):
|
||||||
elf = oe.qa.ELFFile(path)
|
elf = oe.qa.ELFFile(path)
|
||||||
try:
|
try:
|
||||||
elf.open()
|
elf.open()
|
||||||
@@ -915,11 +924,12 @@ def package_qa_check_deps(pkg, pkgdest, d):
|
|||||||
|
|
||||||
QAPKGTEST[usrmerge] = "package_qa_check_usrmerge"
|
QAPKGTEST[usrmerge] = "package_qa_check_usrmerge"
|
||||||
def package_qa_check_usrmerge(pkg, d):
|
def package_qa_check_usrmerge(pkg, d):
|
||||||
|
global cpath
|
||||||
pkgdest = d.getVar('PKGDEST')
|
pkgdest = d.getVar('PKGDEST')
|
||||||
pkg_dir = pkgdest + os.sep + pkg + os.sep
|
pkg_dir = pkgdest + os.sep + pkg + os.sep
|
||||||
merged_dirs = ['bin', 'sbin', 'lib'] + d.getVar('MULTILIB_VARIANTS').split()
|
merged_dirs = ['bin', 'sbin', 'lib'] + d.getVar('MULTILIB_VARIANTS').split()
|
||||||
for f in merged_dirs:
|
for f in merged_dirs:
|
||||||
if os.path.exists(pkg_dir + f) and not os.path.islink(pkg_dir + f):
|
if cpath.exists(pkg_dir + f) and not cpath.islink(pkg_dir + f):
|
||||||
msg = "%s package is not obeying usrmerge distro feature. /%s should be relocated to /usr." % (pkg, f)
|
msg = "%s package is not obeying usrmerge distro feature. /%s should be relocated to /usr." % (pkg, f)
|
||||||
oe.qa.handle_error("usrmerge", msg, d)
|
oe.qa.handle_error("usrmerge", msg, d)
|
||||||
return
|
return
|
||||||
@@ -985,10 +995,11 @@ def package_qa_check_empty_dirs(pkg, d):
|
|||||||
empty.
|
empty.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
global cpath
|
||||||
pkgd = oe.path.join(d.getVar('PKGDEST'), pkg)
|
pkgd = oe.path.join(d.getVar('PKGDEST'), pkg)
|
||||||
for dir in (d.getVar('QA_EMPTY_DIRS') or "").split():
|
for dir in (d.getVar('QA_EMPTY_DIRS') or "").split():
|
||||||
empty_dir = oe.path.join(pkgd, dir)
|
empty_dir = oe.path.join(pkgd, dir)
|
||||||
if os.path.exists(empty_dir) and os.listdir(empty_dir):
|
if cpath.exists(empty_dir) and os.listdir(empty_dir):
|
||||||
recommendation = (d.getVar('QA_EMPTY_DIRS_RECOMMENDATION:' + dir) or
|
recommendation = (d.getVar('QA_EMPTY_DIRS_RECOMMENDATION:' + dir) or
|
||||||
"but it is expected to be empty")
|
"but it is expected to be empty")
|
||||||
msg = "%s installs files in %s, %s" % (pkg, dir, recommendation)
|
msg = "%s installs files in %s, %s" % (pkg, dir, recommendation)
|
||||||
@@ -1018,8 +1029,9 @@ HOST_USER_GID := "${@os.getgid()}"
|
|||||||
QAPATHTEST[host-user-contaminated] = "package_qa_check_host_user"
|
QAPATHTEST[host-user-contaminated] = "package_qa_check_host_user"
|
||||||
def package_qa_check_host_user(path, name, d, elf):
|
def package_qa_check_host_user(path, name, d, elf):
|
||||||
"""Check for paths outside of /home which are owned by the user running bitbake."""
|
"""Check for paths outside of /home which are owned by the user running bitbake."""
|
||||||
|
global cpath
|
||||||
|
|
||||||
if not os.path.lexists(path):
|
if not cpath.lexists(path):
|
||||||
return
|
return
|
||||||
|
|
||||||
dest = d.getVar('PKGDEST')
|
dest = d.getVar('PKGDEST')
|
||||||
@@ -1029,7 +1041,7 @@ def package_qa_check_host_user(path, name, d, elf):
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
stat = os.lstat(path)
|
stat = cpath.lstat(path)
|
||||||
except OSError as exc:
|
except OSError as exc:
|
||||||
import errno
|
import errno
|
||||||
if exc.errno != errno.ENOENT:
|
if exc.errno != errno.ENOENT:
|
||||||
@@ -1105,13 +1117,14 @@ python do_package_qa () {
|
|||||||
if not packages:
|
if not packages:
|
||||||
return
|
return
|
||||||
|
|
||||||
global pkgfiles
|
global pkgfiles, cpath
|
||||||
pkgfiles = {}
|
pkgfiles = {}
|
||||||
|
cpath = oe.cachedpath.CachedPath()
|
||||||
pkgdest = d.getVar('PKGDEST')
|
pkgdest = d.getVar('PKGDEST')
|
||||||
for pkg in packages:
|
for pkg in packages:
|
||||||
pkgdir = os.path.join(pkgdest, pkg)
|
pkgdir = os.path.join(pkgdest, pkg)
|
||||||
pkgfiles[pkg] = []
|
pkgfiles[pkg] = []
|
||||||
for walkroot, dirs, files in os.walk(pkgdir):
|
for walkroot, dirs, files in cpath.walk(pkgdir):
|
||||||
# Don't walk into top-level CONTROL or DEBIAN directories as these
|
# Don't walk into top-level CONTROL or DEBIAN directories as these
|
||||||
# are temporary directories created by do_package.
|
# are temporary directories created by do_package.
|
||||||
if walkroot == pkgdir:
|
if walkroot == pkgdir:
|
||||||
@@ -1159,6 +1172,7 @@ python do_package_qa () {
|
|||||||
|
|
||||||
package_qa_check_libdir(d)
|
package_qa_check_libdir(d)
|
||||||
|
|
||||||
|
cpath = None
|
||||||
oe.qa.exit_if_errors(d)
|
oe.qa.exit_if_errors(d)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user