From patchwork Sun Dec 12 10:54:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Allan McRae X-Patchwork-Id: 1994 Return-Path: Delivered-To: patchwork@archlinux.org Received: from mail.archlinux.org [2a01:4f9:c010:3052::1] by patchwork.archlinux.org with IMAP (fetchmail-6.4.24) for (single-drop); Sun, 12 Dec 2021 10:55:07 +0000 (UTC) Received: from mail.archlinux.org by mail.archlinux.org with LMTP id EO7OKArVtWFjTgUAK+/4rw (envelope-from ) for ; Sun, 12 Dec 2021 10:55:06 +0000 Received: from lists.archlinux.org (lists.archlinux.org [IPv6:2a01:4f9:c010:9eb4::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.archlinux.org (Postfix) with ESMTPS id 0B6ECB3DC40; Sun, 12 Dec 2021 10:55:06 +0000 (UTC) Received: from lists.archlinux.org (localhost [IPv6:::1]) by lists.archlinux.org (Postfix) with ESMTP id 7D37EA8387A; Sun, 12 Dec 2021 10:55:01 +0000 (UTC) X-Original-To: pacman-dev@lists.archlinux.org Delivered-To: pacman-dev@lists.archlinux.org Received: from mail.archlinux.org (mail.archlinux.org [95.216.189.61]) by lists.archlinux.org (Postfix) with ESMTPS id 7B890A83864 for ; Sun, 12 Dec 2021 10:54:59 +0000 (UTC) From: Allan McRae DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=archlinux.org; s=dkim-rsa; t=1639306498; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Nl57bUO2FCulV3fzz/Uctj8BG9GN2UEu7/J3Kr8o9dE=; b=e/Lra3B9QMzfKH5FYpAS90Ew6h5/RIrUFvqoP3tYL+rFL5NJepyuiq/Bsji8uNdLTUOvID gKii9HoFa4WO3YH1qjB4eRHmAgMWjnlwKcM8y11UCID61vk0iy+SbnaTohe8h5JzeXcP4e rwIsUZOBUNHNwxayk4DC5RRuBKO/NLkqAHZAhl+PRmfEel50RYDrVmzuOWxzZLlZHdN9Ad arzR6EUkp/k0azHIrH4bd3Hac1qLzFASjMFuippJWuBbhnQHBUia5V7W9s2OGbLyo+y0Ac ZMb4B4g3x5uRcuFTYajQMonUHVUDQ38P8OUrTw4g3xFQiLgovnnbTtIeGGLX8+zO1bdLIZ f4PctZOXZF4NHgRCnulGSJBb5zqULIX2tU7fayRiRAraF7WfJuxRFoTDWQK+RioGVTAIAp 0USzFx3GpUwkZZKFOUNujSkHhhbr+31rO4qzyHT6E2lGlEmdcf4n4RzqLcO1ArTP3ereKG 29BkCR4m9JhGnoWEySH3rHHdXSGCQqJnAjmo7V6VaE2AVzpJuS51VAzYDQEIVA746lriK6 RifbXkF6YDXpaEruQ3SN+10R2MNyp5StebBbRfbIxb+YOlGmmUJFoyOfWP249XxGCyZXkQ 7Mk79YviJ8LyyhE54PWdaiWYzk3bHFguxDHIZ/PnxqenY4Qilm0Wo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=archlinux.org; s=dkim-ed25519; t=1639306499; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Nl57bUO2FCulV3fzz/Uctj8BG9GN2UEu7/J3Kr8o9dE=; b=zbODNGXVSo0TdXuVuhrwQWS/phFwo4qbJuHCDgbrpCLYUCpNOysB4CLokozfskMrMvOfUo 2/rZeehbR++lB+Cw== To: pacman-dev@lists.archlinux.org Subject: [PATCH] libmakepkg: automatically add library dependencies Date: Sun, 12 Dec 2021 20:54:40 +1000 Message-Id: <20211212105440.1129363-5-allan@archlinux.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211212105440.1129363-1-allan@archlinux.org> References: <20211212105440.1129363-1-allan@archlinux.org> MIME-Version: 1.0 X-BeenThere: pacman-dev@lists.archlinux.org X-Mailman-Version: 2.1.38 Precedence: list List-Id: Discussion list for pacman development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: pacman-dev-bounces@lists.archlinux.org Sender: "pacman-dev" Authentication-Results: mail.archlinux.org; dkim=pass header.d=archlinux.org header.s=dkim-rsa header.b="e/Lra3B9"; dkim=pass header.d=archlinux.org header.s=dkim-ed25519 header.b=zbODNGXV; dmarc=pass (policy=none) header.from=archlinux.org; spf=pass (mail.archlinux.org: domain of pacman-dev-bounces@lists.archlinux.org designates 2a01:4f9:c010:9eb4::1 as permitted sender) smtp.mailfrom=pacman-dev-bounces@lists.archlinux.org X-Rspamd-Queue-Id: 0B6ECB3DC40 X-Spamd-Result: default: False [-2.61 / 15.00]; DWL_DNSWL_MED(-2.00)[archlinux.org:dkim]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; DMARC_POLICY_ALLOW(-0.50)[archlinux.org,none]; RCVD_DKIM_ARC_DNSWL_MED(-0.50)[]; RCVD_IN_DNSWL_MED(-0.40)[2a01:4f9:c010:9eb4::1:from,95.216.189.61:received]; R_DKIM_ALLOW(-0.20)[archlinux.org:s=dkim-rsa,archlinux.org:s=dkim-ed25519]; R_SPF_ALLOW(-0.20)[+ip6:2a01:4f9:c010:9eb4::1:c]; MAILLIST(-0.20)[mailman]; MIME_GOOD(-0.10)[text/plain]; HAS_LIST_UNSUB(-0.01)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:24940, ipnet:2a01:4f9::/32, country:DE]; RCVD_TLS_LAST(0.00)[]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; RCVD_COUNT_THREE(0.00)[3]; FROM_HAS_DN(0.00)[]; NEURAL_HAM(-0.00)[-1.000]; DKIM_TRACE(0.00)[archlinux.org:+]; PREVIOUSLY_DELIVERED(0.00)[pacman-dev@lists.archlinux.org]; FROM_NEQ_ENVFROM(0.00)[allan@archlinux.org,pacman-dev-bounces@lists.archlinux.org]; TO_DN_NONE(0.00)[]; FORGED_SENDER_MAILLIST(0.00)[] X-Rspamd-Server: mail.archlinux.org Add linked libraries to a packages dependency list. This is the partner to automatically generated library provides, and thus depends take the same format. To help with bootstrapping, library dependencies are only added if the relevant provide exists. Signed-off-by: Allan McRae --- .../libmakepkg/autodep/library_depends.sh.in | 75 +++++++++++++++++++ scripts/libmakepkg/autodep/meson.build | 2 +- 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 scripts/libmakepkg/autodep/library_depends.sh.in diff --git a/scripts/libmakepkg/autodep/library_depends.sh.in b/scripts/libmakepkg/autodep/library_depends.sh.in new file mode 100644 index 00000000..4c387241 --- /dev/null +++ b/scripts/libmakepkg/autodep/library_depends.sh.in @@ -0,0 +1,75 @@ +#!/bin/bash +# +# library_depends.sh - Automatically add library requirements to depends +# +# Copyright (c) 2021 Pacman Development Team +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +[[ -n "$LIBMAKEPKG_AUTODEP_LIBRARY_DEPENDS_SH" ]] && return +LIBMAKEPKG_AUTODEP_LIBRARY_DEPENDS_SH=1 + +LIBRARY=${LIBRARY:-'@libmakepkgdir@'} + +autodep_functions+=('library_depends') + +library_depends() { + if check_option "autodeps" "y"; then + local dep filename libdeps libdir libpath prefix sofile + declare -a libdeps + + while IFS= read -rd '' filename; do + for sofile in $(LC_ALL=C readelf -d $filename 2>/dev/null | sed -nr 's/.*Shared library: \[(.*)\].*/\1/p'); do + # get the full path of the library + libpath=$(ldd $filename | sed -nr "s/.$sofile => (.*) \(.*\)/\1/p") + + # if ldd can not find the library, it is likely part of the package and not in filesystem + if [[ -z $libpath ]]; then + continue + fi + + # skip if the library is part of the package + if [[ -e "$pkgdir/$libpath" ]]; then + continue + fi + + # find the prefix for the dependency + libpath=${libpath#/} + libpath=${libpath%/*} + + unset prefix + for libdir in ${LIB_DIRS[@]}; do + if [[ ${libdir/*:} == ${libpath} ]]; then + prefix=${libdir/:*} + fi + done + + if [[ -z ${prefix} ]]; then + continue + fi + + # only add library dependency if it exists - this helps bootstraping dependencies + if [[ $(run_pacman -T "$prefix:$sofile") ]]; then + continue + fi + + libdeps+=("$prefix:$sofile") + done + + done < <(find "$pkgdir" -type f -perm -u+x -print0) + + depends+=($(printf '%s\n' "${libdeps[@]}" | LC_ALL=C sort -u)) + fi +} diff --git a/scripts/libmakepkg/autodep/meson.build b/scripts/libmakepkg/autodep/meson.build index e0af26a6..08c4c818 100644 --- a/scripts/libmakepkg/autodep/meson.build +++ b/scripts/libmakepkg/autodep/meson.build @@ -1,8 +1,8 @@ libmakepkg_module = 'tidy' sources = [ + 'library_depends.sh.in', 'library_provides.sh.in', - ] foreach src : sources