aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormerakor <cem@ckyln.com>2020-10-25 21:49:36 +0000
committermerakor <cem@ckyln.com>2020-10-25 21:49:36 +0000
commite57f3cf96b1c21afc0b6bd37b77a5b2491b0e775 (patch)
treedcdc9018304ff0588d9abbbaf1f0f814169b6e7e
parente3145335fb336b83e32ba22a0ec259e0c1cbe61a (diff)
downloadcpt-e57f3cf96b1c21afc0b6bd37b77a5b2491b0e775.tar.gz
cpt-lib (pkg_fixdeps): rename to pkg_fix_deps and major changes:
Following the changes on kiss, pkg_fixdeps has been renamed to pkg_fix_deps and added readelf support. Readelf is a much better solution for checking dependencies as it can differentiate between actual dependencies and "dependencies of dependencies". cpt will check for the tool to use in the following order: - readelf - eu-readelf - llvm-readelf - ldd CPT_ELF: This new variable can be used to force a specific tool, such as ldd, or a specific readelf program. Other changes include: - The function no longer prints found dependencies - It checks for the dependencies on the current manifest first, and skips if they have been found on the package. - The function now uses the pkg_owns() for finding packages FossilOrigin-Name: 42927fcc2cd7f588be2658c506773b9be22f2b268e0999903ce1a84c65f7b5ec
-rw-r--r--src/cpt-lib65
1 files changed, 33 insertions, 32 deletions
diff --git a/src/cpt-lib b/src/cpt-lib
index 56f43de..bb7cc2d 100644
--- a/src/cpt-lib
+++ b/src/cpt-lib
@@ -763,11 +763,10 @@ pkg_strip() {
done 2>/dev/null ||:
}
-pkg_fixdeps() {
- # Dynamically look for missing runtime dependencies by checking
- # each binary and library with 'ldd'. This catches any extra
- # libraries and or dependencies pulled in by the package's
- # build suite.
+pkg_fix_deps() {
+ # Dynamically look for missing runtime dependencies by checking each binary
+ # and library with either 'ldd' or 'readelf'. This catches any extra
+ # libraries and or dependencies pulled in by the package's build suite.
log "$1" "Checking for missing dependencies"
# Go to the directory containing the built package to
@@ -793,38 +792,32 @@ pkg_fixdeps() {
find "$pkg_dir/$pkg_name/" -type f 2>/dev/null |
while read -r file; do
- # Run 'ldd' on the file and parse each line. The code
- # then checks to see which packages own the linked
- # libraries and it prints the result.
- ldd "$file" 2>/dev/null | while read -r dep; do
+ case ${elf_prog:-ldd} in
+ *readelf) "$elf_prog" -d "$file" 2>/dev/null ;;
+ *) ldd "$file" 2>/dev/null ;;
+ esac |
+ while read -r dep; do
# Skip lines containing 'ldd'.
[ "${dep##*ldd*}" ] || continue
+ case $dep in *NEEDED*\[*\] | *'=>'*) ;; *) continue; esac
- # Extract the file path from 'ldd' output, and
- # canonicalize the path.
+ # readelf output:
+ # 0x0000 (NEEDED) Shared library: [libc.so]
+ dep=${dep##*\[}
+ dep=${dep%%\]*}
+
+ # ldd output:
+ # libc.so => /lib/ld-musl-x86_64.so.1
dep=${dep#* => }
dep=${dep% *}
- dep=$(cpt-readlink "$dep")
-
- # Figure out which package owns the file.
- own=$("$grep" -lFx "${dep#$CPT_ROOT}" "$@")
-
- # If the package wasn't found, retry by removing
- # the '/usr' prefix.
- if [ -z "$own" ] && [ -z "${dep##$CPT_ROOT/usr*}" ]; then
- own=$("$grep" -lFx "${dep#$CPT_ROOT/usr}" "$@")
- dep=${dep#/usr}
- fi
- # Extract package name from 'grep' match.
- own=${own%/*}
- own=${own##*/}
-
- case $own in "$pkg_name"|"$pkg_name-bin"|"") continue ; esac
- printf 'Found %s (%s) in (%s)\n' "$own" "$dep" \
- "${file##$pkg_dir/$pkg_name}" >&2
-
- printf '%s\n' "$own"
+ # Figure out which package owns the file. Skip file if it is owned
+ # by the current package. This also handles cases where a '*-bin'
+ # package exists on the system, so the package manager doesn't think
+ # that the package we are building depends on the *-bin version of
+ # itself, or any other renamed versions of the same software.
+ pkg_owner -l "/${dep#/}\$" "$PWD/manifest" >/dev/null && continue
+ pkg_owner -l "/${dep#/}\$" "$@" ||:
done ||:
done >> depends
@@ -1044,7 +1037,7 @@ pkg_build() {
: > "$pkg_dir/$pkg/$pkg_db/$pkg/etcsums"
pkg_strip "$pkg"
- pkg_fixdeps "$pkg"
+ pkg_fix_deps "$pkg"
pkg_manifest "$pkg"
pkg_etcsums "$pkg"
pkg_tar "$pkg"
@@ -1823,6 +1816,14 @@ main() {
# of the log files the package manager creates uring builds.
time=$(date '+%Y-%m-%d-%H:%M')
+ # Use readelf for fixing dependencies if it is available, fallback to
+ # ldd. readelf shows only the actual dependencies and doesn't include
+ # the libraries required by the dependencies.
+ elf_prog=${CPT_ELF:="$(
+ command -v readelf ||
+ command -v llvm-readelf ||
+ command -v eu-readelf)"} || elf_prog=ldd
+
# Make note of the user's current ID to do root checks later on.
# This is used enough to warrant a place here.
uid=$(id -u)