public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH] ltprune.eclass: Split prune_libtool_files out of eutils
@ 2017-03-12 10:39 Michał Górny
  2017-03-12 11:00 ` [gentoo-dev] [PATCH v2] ltprune.eclass Michał Górny
  0 siblings, 1 reply; 9+ messages in thread
From: Michał Górny @ 2017-03-12 10:39 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

Move the prune_libtool_files into a dedicated ltprune.eclass.
The function is quite complex and depends on toolchain-funcs. It has
a separate maintainer, is not useful to non-autotools ebuilds, and even
there it is frequently replaced by the simpler 'find ... -delete' call.

Kill the unnecessary Prefix logic. There is no functional difference
between starting the find in ${D} and ${ED}, and the latter implies
unnecessary hackery for old EAPIs.

The new eclass is implicitly inherited by eutils in EAPI 6 and older
in order to preserve compatibility with existing ebuilds. However, all
ebuilds should switch to inheriting it directly.

The split has been suggested by Ulrich Müller.
---
 eclass/eutils.eclass  | 150 +--------------------------------------------
 eclass/ltprune.eclass | 166 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 167 insertions(+), 149 deletions(-)
 create mode 100644 eclass/ltprune.eclass

diff --git a/eclass/eutils.eclass b/eclass/eutils.eclass
index e036001dc5e1..c932d685c0e9 100644
--- a/eclass/eutils.eclass
+++ b/eclass/eutils.eclass
@@ -17,12 +17,10 @@
 if [[ -z ${_EUTILS_ECLASS} ]]; then
 _EUTILS_ECLASS=1
 
-inherit toolchain-funcs
-
 # implicitly inherited (now split) eclasses
 case ${EAPI:-0} in
 0|1|2|3|4|5|6)
-	inherit epatch estack multilib
+	inherit epatch estack ltprune multilib toolchain-funcs
 	;;
 esac
 
@@ -869,152 +867,6 @@ use_if_iuse() {
 	use $1
 }
 
-# @FUNCTION: prune_libtool_files
-# @USAGE: [--all|--modules]
-# @DESCRIPTION:
-# Locate unnecessary libtool files (.la) and libtool static archives
-# (.a) and remove them from installation image.
-#
-# By default, .la files are removed whenever the static linkage can
-# either be performed using pkg-config or doesn't introduce additional
-# flags.
-#
-# If '--modules' argument is passed, .la files for modules (plugins) are
-# removed as well. This is usually useful when the package installs
-# plugins and the plugin loader does not use .la files.
-#
-# If '--all' argument is passed, all .la files are removed without
-# performing any heuristic on them. You shouldn't ever use that,
-# and instead report a bug in the algorithm instead.
-#
-# The .a files are only removed whenever corresponding .la files state
-# that they should not be linked to, i.e. whenever these files
-# correspond to plugins.
-#
-# Note: if your package installs both static libraries and .pc files
-# which use variable substitution for -l flags, you need to add
-# pkg-config to your DEPEND.
-prune_libtool_files() {
-	debug-print-function ${FUNCNAME} "$@"
-
-	local removing_all removing_modules opt
-	_eutils_eprefix_init
-	for opt; do
-		case "${opt}" in
-			--all)
-				removing_all=1
-				removing_modules=1
-				;;
-			--modules)
-				removing_modules=1
-				;;
-			*)
-				die "Invalid argument to ${FUNCNAME}(): ${opt}"
-		esac
-	done
-
-	local f
-	local queue=()
-	while IFS= read -r -d '' f; do # for all .la files
-		local archivefile=${f/%.la/.a}
-
-		# The following check is done by libtool itself.
-		# It helps us avoid removing random files which match '*.la',
-		# see bug #468380.
-		if ! sed -n -e '/^# Generated by .*libtool/q0;4q1' "${f}"; then
-			continue
-		fi
-
-		[[ ${f} != ${archivefile} ]] || die 'regex sanity check failed'
-		local reason= pkgconfig_scanned=
-		local snotlink=$(sed -n -e 's:^shouldnotlink=::p' "${f}")
-
-		if [[ ${snotlink} == yes ]]; then
-
-			# Remove static libs we're not supposed to link against.
-			if [[ -f ${archivefile} ]]; then
-				einfo "Removing unnecessary ${archivefile#${D%/}} (static plugin)"
-				queue+=( "${archivefile}" )
-			fi
-
-			# The .la file may be used by a module loader, so avoid removing it
-			# unless explicitly requested.
-			if [[ ${removing_modules} ]]; then
-				reason='module'
-			fi
-
-		else
-
-			# Remove .la files when:
-			# - user explicitly wants us to remove all .la files,
-			# - respective static archive doesn't exist,
-			# - they are covered by a .pc file already,
-			# - they don't provide any new information (no libs & no flags).
-
-			if [[ ${removing_all} ]]; then
-				reason='requested'
-			elif [[ ! -f ${archivefile} ]]; then
-				reason='no static archive'
-			elif [[ ! $(sed -nre \
-					"s/^(dependency_libs|inherited_linker_flags)='(.*)'$/\2/p" \
-					"${f}") ]]; then
-				reason='no libs & flags'
-			else
-				if [[ ! ${pkgconfig_scanned} ]]; then
-					# Create a list of all .pc-covered libs.
-					local pc_libs=()
-					if [[ ! ${removing_all} ]]; then
-						local pc
-						local tf=${T}/prune-lt-files.pc
-						local pkgconf=$(tc-getPKG_CONFIG)
-
-						while IFS= read -r -d '' pc; do # for all .pc files
-							local arg libs
-
-							# Use pkg-config if available (and works),
-							# fallback to sed.
-							if ${pkgconf} --exists "${pc}" &>/dev/null; then
-								sed -e '/^Requires:/d' "${pc}" > "${tf}"
-								libs=$(${pkgconf} --libs "${tf}")
-							else
-								libs=$(sed -ne 's/^Libs://p' "${pc}")
-							fi
-
-							for arg in ${libs}; do
-								if [[ ${arg} == -l* ]]; then
-									if [[ ${arg} == '*$*' ]]; then
-										eqawarn "${FUNCNAME}: variable substitution likely failed in ${pc}"
-										eqawarn "(arg: ${arg})"
-										eqawarn "Most likely, you need to add virtual/pkgconfig to DEPEND."
-									fi
-
-									pc_libs+=( lib${arg#-l}.la )
-								fi
-							done
-						done < <(find "${D}" -type f -name '*.pc' -print0)
-
-						rm -f "${tf}"
-					fi
-
-					pkgconfig_scanned=1
-				fi # pkgconfig_scanned
-
-				has "${f##*/}" "${pc_libs[@]}" && reason='covered by .pc'
-			fi # removal due to .pc
-
-		fi # shouldnotlink==no
-
-		if [[ ${reason} ]]; then
-			einfo "Removing unnecessary ${f#${D%/}} (${reason})"
-			queue+=( "${f}" )
-		fi
-	done < <(find "${ED}" -xtype f -name '*.la' -print0)
-
-	if [[ ${queue[@]} ]]; then
-		rm -f "${queue[@]}"
-	fi
-}
-
 # @FUNCTION: optfeature
 # @USAGE: <short description> <package atom to match> [other atoms]
 # @DESCRIPTION:
diff --git a/eclass/ltprune.eclass b/eclass/ltprune.eclass
new file mode 100644
index 000000000000..731d233cc14e
--- /dev/null
+++ b/eclass/ltprune.eclass
@@ -0,0 +1,166 @@
+# Copyright 1999-2017 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: ltprune.eclass
+# @MAINTAINER:
+# Michał Górny <mgorny@gentoo.org>
+# @BLURB: Smart .la file pruning
+# @DESCRIPTION:
+# A function to locate and remove unnecessary .la files.
+#
+# Discouraged. Whenever possible, please use much simpler:
+# @CODE
+# find "${D}" -name '*.la' -delete || die
+# @CODE
+
+if [[ -z ${_LTPRUNE_ECLASS} ]]; then
+
+inherit toolchain-funcs
+
+# @FUNCTION: prune_libtool_files
+# @USAGE: [--all|--modules]
+# @DESCRIPTION:
+# Locate unnecessary libtool files (.la) and libtool static archives
+# (.a) and remove them from installation image.
+#
+# By default, .la files are removed whenever the static linkage can
+# either be performed using pkg-config or doesn't introduce additional
+# flags.
+#
+# If '--modules' argument is passed, .la files for modules (plugins) are
+# removed as well. This is usually useful when the package installs
+# plugins and the plugin loader does not use .la files.
+#
+# If '--all' argument is passed, all .la files are removed without
+# performing any heuristic on them. You shouldn't ever use that,
+# and instead report a bug in the algorithm instead.
+#
+# The .a files are only removed whenever corresponding .la files state
+# that they should not be linked to, i.e. whenever these files
+# correspond to plugins.
+#
+# Note: if your package installs both static libraries and .pc files
+# which use variable substitution for -l flags, you need to add
+# pkg-config to your DEPEND.
+prune_libtool_files() {
+	debug-print-function ${FUNCNAME} "$@"
+
+	local removing_all removing_modules opt
+	for opt; do
+		case "${opt}" in
+			--all)
+				removing_all=1
+				removing_modules=1
+				;;
+			--modules)
+				removing_modules=1
+				;;
+			*)
+				die "Invalid argument to ${FUNCNAME}(): ${opt}"
+		esac
+	done
+
+	local f
+	local queue=()
+	while IFS= read -r -d '' f; do # for all .la files
+		local archivefile=${f/%.la/.a}
+
+		# The following check is done by libtool itself.
+		# It helps us avoid removing random files which match '*.la',
+		# see bug #468380.
+		if ! sed -n -e '/^# Generated by .*libtool/q0;4q1' "${f}"; then
+			continue
+		fi
+
+		[[ ${f} != ${archivefile} ]] || die 'regex sanity check failed'
+		local reason= pkgconfig_scanned=
+		local snotlink=$(sed -n -e 's:^shouldnotlink=::p' "${f}")
+
+		if [[ ${snotlink} == yes ]]; then
+
+			# Remove static libs we're not supposed to link against.
+			if [[ -f ${archivefile} ]]; then
+				einfo "Removing unnecessary ${archivefile#${D%/}} (static plugin)"
+				queue+=( "${archivefile}" )
+			fi
+
+			# The .la file may be used by a module loader, so avoid removing it
+			# unless explicitly requested.
+			if [[ ${removing_modules} ]]; then
+				reason='module'
+			fi
+
+		else
+
+			# Remove .la files when:
+			# - user explicitly wants us to remove all .la files,
+			# - respective static archive doesn't exist,
+			# - they are covered by a .pc file already,
+			# - they don't provide any new information (no libs & no flags).
+
+			if [[ ${removing_all} ]]; then
+				reason='requested'
+			elif [[ ! -f ${archivefile} ]]; then
+				reason='no static archive'
+			elif [[ ! $(sed -nre \
+					"s/^(dependency_libs|inherited_linker_flags)='(.*)'$/\2/p" \
+					"${f}") ]]; then
+				reason='no libs & flags'
+			else
+				if [[ ! ${pkgconfig_scanned} ]]; then
+					# Create a list of all .pc-covered libs.
+					local pc_libs=()
+					if [[ ! ${removing_all} ]]; then
+						local pc
+						local tf=${T}/prune-lt-files.pc
+						local pkgconf=$(tc-getPKG_CONFIG)
+
+						while IFS= read -r -d '' pc; do # for all .pc files
+							local arg libs
+
+							# Use pkg-config if available (and works),
+							# fallback to sed.
+							if ${pkgconf} --exists "${pc}" &>/dev/null; then
+								sed -e '/^Requires:/d' "${pc}" > "${tf}"
+								libs=$(${pkgconf} --libs "${tf}")
+							else
+								libs=$(sed -ne 's/^Libs://p' "${pc}")
+							fi
+
+							for arg in ${libs}; do
+								if [[ ${arg} == -l* ]]; then
+									if [[ ${arg} == '*$*' ]]; then
+										eqawarn "${FUNCNAME}: variable substitution likely failed in ${pc}"
+										eqawarn "(arg: ${arg})"
+										eqawarn "Most likely, you need to add virtual/pkgconfig to DEPEND."
+									fi
+
+									pc_libs+=( lib${arg#-l}.la )
+								fi
+							done
+						done < <(find "${D}" -type f -name '*.pc' -print0)
+
+						rm -f "${tf}"
+					fi
+
+					pkgconfig_scanned=1
+				fi # pkgconfig_scanned
+
+				has "${f##*/}" "${pc_libs[@]}" && reason='covered by .pc'
+			fi # removal due to .pc
+
+		fi # shouldnotlink==no
+
+		if [[ ${reason} ]]; then
+			einfo "Removing unnecessary ${f#${D%/}} (${reason})"
+			queue+=( "${f}" )
+		fi
+	done < <(find "${D}" -xtype f -name '*.la' -print0)
+
+	if [[ ${queue[@]} ]]; then
+		rm -f "${queue[@]}"
+	fi
+}
+
+_LTPRUNE_ECLASS=1
+fi #_LTPRUNE_ECLASS
-- 
2.12.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [gentoo-dev] [PATCH v2] ltprune.eclass
  2017-03-12 10:39 [gentoo-dev] [PATCH] ltprune.eclass: Split prune_libtool_files out of eutils Michał Górny
@ 2017-03-12 11:00 ` Michał Górny
  2017-03-12 11:00   ` [gentoo-dev] [PATCH 1/3] eutils.eclass: prune_libtool_files, punt pointless Prefix logic Michał Górny
                     ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Michał Górny @ 2017-03-12 11:00 UTC (permalink / raw
  To: gentoo-dev

Changes in v2:
- now in split commits to ease review,
- removed eqawarn to avoid circ dep on eutils.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [gentoo-dev] [PATCH 1/3] eutils.eclass: prune_libtool_files, punt pointless Prefix logic
  2017-03-12 11:00 ` [gentoo-dev] [PATCH v2] ltprune.eclass Michał Górny
@ 2017-03-12 11:00   ` Michał Górny
  2017-03-12 11:00   ` [gentoo-dev] [PATCH 2/3] eutils.eclass: prune_libtool_files, make .pc subst errors fatal Michał Górny
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Michał Górny @ 2017-03-12 11:00 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

Remove the unnecessary Prefix logic from prune_libtool_files(). There is
no functional difference between starting a find in ${D} and ${ED}
(since ${D} is not supposed to contain other directories on a Prefix
system), and using the latter implies unnecessary hackery for older
EAPIs.
---
 eclass/eutils.eclass | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/eclass/eutils.eclass b/eclass/eutils.eclass
index e036001dc5e1..ab226b236a37 100644
--- a/eclass/eutils.eclass
+++ b/eclass/eutils.eclass
@@ -898,7 +898,6 @@ prune_libtool_files() {
 	debug-print-function ${FUNCNAME} "$@"
 
 	local removing_all removing_modules opt
-	_eutils_eprefix_init
 	for opt; do
 		case "${opt}" in
 			--all)
@@ -1008,7 +1007,7 @@ prune_libtool_files() {
 			einfo "Removing unnecessary ${f#${D%/}} (${reason})"
 			queue+=( "${f}" )
 		fi
-	done < <(find "${ED}" -xtype f -name '*.la' -print0)
+	done < <(find "${D}" -xtype f -name '*.la' -print0)
 
 	if [[ ${queue[@]} ]]; then
 		rm -f "${queue[@]}"
-- 
2.12.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [gentoo-dev] [PATCH 2/3] eutils.eclass: prune_libtool_files, make .pc subst errors fatal
  2017-03-12 11:00 ` [gentoo-dev] [PATCH v2] ltprune.eclass Michał Górny
  2017-03-12 11:00   ` [gentoo-dev] [PATCH 1/3] eutils.eclass: prune_libtool_files, punt pointless Prefix logic Michał Górny
@ 2017-03-12 11:00   ` Michał Górny
  2017-03-12 11:35     ` Alexis Ballier
  2017-03-12 11:00   ` [gentoo-dev] [PATCH 3/3] ltprune.eclass: Split prune_libtool_files out of eutils Michał Górny
  2017-03-18  7:35   ` [gentoo-dev] [PATCH v2] ltprune.eclass Michał Górny
  3 siblings, 1 reply; 9+ messages in thread
From: Michał Górny @ 2017-03-12 11:00 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

Make the substitution errors in prune_libtool_files logic fatal to avoid
the dependency of eqawarn. They're extremely unlikely to happen anyway.
---
 eclass/eutils.eclass | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/eclass/eutils.eclass b/eclass/eutils.eclass
index ab226b236a37..cb472caee1d4 100644
--- a/eclass/eutils.eclass
+++ b/eclass/eutils.eclass
@@ -982,9 +982,10 @@ prune_libtool_files() {
 							for arg in ${libs}; do
 								if [[ ${arg} == -l* ]]; then
 									if [[ ${arg} == '*$*' ]]; then
-										eqawarn "${FUNCNAME}: variable substitution likely failed in ${pc}"
-										eqawarn "(arg: ${arg})"
-										eqawarn "Most likely, you need to add virtual/pkgconfig to DEPEND."
+										eerror "${FUNCNAME}: variable substitution likely failed in ${pc}"
+										eerror "(arg: ${arg})"
+										eerror "Most likely, you need to add virtual/pkgconfig to DEPEND."
+										die "${FUNCNAME}: unsubstituted variable found in .pc"
 									fi
 
 									pc_libs+=( lib${arg#-l}.la )
-- 
2.12.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [gentoo-dev] [PATCH 3/3] ltprune.eclass: Split prune_libtool_files out of eutils
  2017-03-12 11:00 ` [gentoo-dev] [PATCH v2] ltprune.eclass Michał Górny
  2017-03-12 11:00   ` [gentoo-dev] [PATCH 1/3] eutils.eclass: prune_libtool_files, punt pointless Prefix logic Michał Górny
  2017-03-12 11:00   ` [gentoo-dev] [PATCH 2/3] eutils.eclass: prune_libtool_files, make .pc subst errors fatal Michał Górny
@ 2017-03-12 11:00   ` Michał Górny
  2017-03-18  7:35   ` [gentoo-dev] [PATCH v2] ltprune.eclass Michał Górny
  3 siblings, 0 replies; 9+ messages in thread
From: Michał Górny @ 2017-03-12 11:00 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

Move the prune_libtool_files into a dedicated ltprune.eclass.
The function is quite complex and depends on toolchain-funcs. It has
a separate maintainer, is not useful to non-autotools ebuilds, and even
there it is frequently replaced by the simpler 'find ... -delete' call.

The new eclass is implicitly inherited by eutils in EAPI 6 and older
in order to preserve compatibility with existing ebuilds. However, all
ebuilds should switch to inheriting it directly.

The split has been suggested by Ulrich Müller.
---
 eclass/eutils.eclass  | 150 +--------------------------------------------
 eclass/ltprune.eclass | 167 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 168 insertions(+), 149 deletions(-)
 create mode 100644 eclass/ltprune.eclass

diff --git a/eclass/eutils.eclass b/eclass/eutils.eclass
index cb472caee1d4..c932d685c0e9 100644
--- a/eclass/eutils.eclass
+++ b/eclass/eutils.eclass
@@ -17,12 +17,10 @@
 if [[ -z ${_EUTILS_ECLASS} ]]; then
 _EUTILS_ECLASS=1
 
-inherit toolchain-funcs
-
 # implicitly inherited (now split) eclasses
 case ${EAPI:-0} in
 0|1|2|3|4|5|6)
-	inherit epatch estack multilib
+	inherit epatch estack ltprune multilib toolchain-funcs
 	;;
 esac
 
@@ -869,152 +867,6 @@ use_if_iuse() {
 	use $1
 }
 
-# @FUNCTION: prune_libtool_files
-# @USAGE: [--all|--modules]
-# @DESCRIPTION:
-# Locate unnecessary libtool files (.la) and libtool static archives
-# (.a) and remove them from installation image.
-#
-# By default, .la files are removed whenever the static linkage can
-# either be performed using pkg-config or doesn't introduce additional
-# flags.
-#
-# If '--modules' argument is passed, .la files for modules (plugins) are
-# removed as well. This is usually useful when the package installs
-# plugins and the plugin loader does not use .la files.
-#
-# If '--all' argument is passed, all .la files are removed without
-# performing any heuristic on them. You shouldn't ever use that,
-# and instead report a bug in the algorithm instead.
-#
-# The .a files are only removed whenever corresponding .la files state
-# that they should not be linked to, i.e. whenever these files
-# correspond to plugins.
-#
-# Note: if your package installs both static libraries and .pc files
-# which use variable substitution for -l flags, you need to add
-# pkg-config to your DEPEND.
-prune_libtool_files() {
-	debug-print-function ${FUNCNAME} "$@"
-
-	local removing_all removing_modules opt
-	for opt; do
-		case "${opt}" in
-			--all)
-				removing_all=1
-				removing_modules=1
-				;;
-			--modules)
-				removing_modules=1
-				;;
-			*)
-				die "Invalid argument to ${FUNCNAME}(): ${opt}"
-		esac
-	done
-
-	local f
-	local queue=()
-	while IFS= read -r -d '' f; do # for all .la files
-		local archivefile=${f/%.la/.a}
-
-		# The following check is done by libtool itself.
-		# It helps us avoid removing random files which match '*.la',
-		# see bug #468380.
-		if ! sed -n -e '/^# Generated by .*libtool/q0;4q1' "${f}"; then
-			continue
-		fi
-
-		[[ ${f} != ${archivefile} ]] || die 'regex sanity check failed'
-		local reason= pkgconfig_scanned=
-		local snotlink=$(sed -n -e 's:^shouldnotlink=::p' "${f}")
-
-		if [[ ${snotlink} == yes ]]; then
-
-			# Remove static libs we're not supposed to link against.
-			if [[ -f ${archivefile} ]]; then
-				einfo "Removing unnecessary ${archivefile#${D%/}} (static plugin)"
-				queue+=( "${archivefile}" )
-			fi
-
-			# The .la file may be used by a module loader, so avoid removing it
-			# unless explicitly requested.
-			if [[ ${removing_modules} ]]; then
-				reason='module'
-			fi
-
-		else
-
-			# Remove .la files when:
-			# - user explicitly wants us to remove all .la files,
-			# - respective static archive doesn't exist,
-			# - they are covered by a .pc file already,
-			# - they don't provide any new information (no libs & no flags).
-
-			if [[ ${removing_all} ]]; then
-				reason='requested'
-			elif [[ ! -f ${archivefile} ]]; then
-				reason='no static archive'
-			elif [[ ! $(sed -nre \
-					"s/^(dependency_libs|inherited_linker_flags)='(.*)'$/\2/p" \
-					"${f}") ]]; then
-				reason='no libs & flags'
-			else
-				if [[ ! ${pkgconfig_scanned} ]]; then
-					# Create a list of all .pc-covered libs.
-					local pc_libs=()
-					if [[ ! ${removing_all} ]]; then
-						local pc
-						local tf=${T}/prune-lt-files.pc
-						local pkgconf=$(tc-getPKG_CONFIG)
-
-						while IFS= read -r -d '' pc; do # for all .pc files
-							local arg libs
-
-							# Use pkg-config if available (and works),
-							# fallback to sed.
-							if ${pkgconf} --exists "${pc}" &>/dev/null; then
-								sed -e '/^Requires:/d' "${pc}" > "${tf}"
-								libs=$(${pkgconf} --libs "${tf}")
-							else
-								libs=$(sed -ne 's/^Libs://p' "${pc}")
-							fi
-
-							for arg in ${libs}; do
-								if [[ ${arg} == -l* ]]; then
-									if [[ ${arg} == '*$*' ]]; then
-										eerror "${FUNCNAME}: variable substitution likely failed in ${pc}"
-										eerror "(arg: ${arg})"
-										eerror "Most likely, you need to add virtual/pkgconfig to DEPEND."
-										die "${FUNCNAME}: unsubstituted variable found in .pc"
-									fi
-
-									pc_libs+=( lib${arg#-l}.la )
-								fi
-							done
-						done < <(find "${D}" -type f -name '*.pc' -print0)
-
-						rm -f "${tf}"
-					fi
-
-					pkgconfig_scanned=1
-				fi # pkgconfig_scanned
-
-				has "${f##*/}" "${pc_libs[@]}" && reason='covered by .pc'
-			fi # removal due to .pc
-
-		fi # shouldnotlink==no
-
-		if [[ ${reason} ]]; then
-			einfo "Removing unnecessary ${f#${D%/}} (${reason})"
-			queue+=( "${f}" )
-		fi
-	done < <(find "${D}" -xtype f -name '*.la' -print0)
-
-	if [[ ${queue[@]} ]]; then
-		rm -f "${queue[@]}"
-	fi
-}
-
 # @FUNCTION: optfeature
 # @USAGE: <short description> <package atom to match> [other atoms]
 # @DESCRIPTION:
diff --git a/eclass/ltprune.eclass b/eclass/ltprune.eclass
new file mode 100644
index 000000000000..6b3e93921d96
--- /dev/null
+++ b/eclass/ltprune.eclass
@@ -0,0 +1,167 @@
+# Copyright 1999-2017 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: ltprune.eclass
+# @MAINTAINER:
+# Michał Górny <mgorny@gentoo.org>
+# @BLURB: Smart .la file pruning
+# @DESCRIPTION:
+# A function to locate and remove unnecessary .la files.
+#
+# Discouraged. Whenever possible, please use much simpler:
+# @CODE
+# find "${D}" -name '*.la' -delete || die
+# @CODE
+
+if [[ -z ${_LTPRUNE_ECLASS} ]]; then
+
+inherit toolchain-funcs
+
+# @FUNCTION: prune_libtool_files
+# @USAGE: [--all|--modules]
+# @DESCRIPTION:
+# Locate unnecessary libtool files (.la) and libtool static archives
+# (.a) and remove them from installation image.
+#
+# By default, .la files are removed whenever the static linkage can
+# either be performed using pkg-config or doesn't introduce additional
+# flags.
+#
+# If '--modules' argument is passed, .la files for modules (plugins) are
+# removed as well. This is usually useful when the package installs
+# plugins and the plugin loader does not use .la files.
+#
+# If '--all' argument is passed, all .la files are removed without
+# performing any heuristic on them. You shouldn't ever use that,
+# and instead report a bug in the algorithm instead.
+#
+# The .a files are only removed whenever corresponding .la files state
+# that they should not be linked to, i.e. whenever these files
+# correspond to plugins.
+#
+# Note: if your package installs both static libraries and .pc files
+# which use variable substitution for -l flags, you need to add
+# pkg-config to your DEPEND.
+prune_libtool_files() {
+	debug-print-function ${FUNCNAME} "$@"
+
+	local removing_all removing_modules opt
+	for opt; do
+		case "${opt}" in
+			--all)
+				removing_all=1
+				removing_modules=1
+				;;
+			--modules)
+				removing_modules=1
+				;;
+			*)
+				die "Invalid argument to ${FUNCNAME}(): ${opt}"
+		esac
+	done
+
+	local f
+	local queue=()
+	while IFS= read -r -d '' f; do # for all .la files
+		local archivefile=${f/%.la/.a}
+
+		# The following check is done by libtool itself.
+		# It helps us avoid removing random files which match '*.la',
+		# see bug #468380.
+		if ! sed -n -e '/^# Generated by .*libtool/q0;4q1' "${f}"; then
+			continue
+		fi
+
+		[[ ${f} != ${archivefile} ]] || die 'regex sanity check failed'
+		local reason= pkgconfig_scanned=
+		local snotlink=$(sed -n -e 's:^shouldnotlink=::p' "${f}")
+
+		if [[ ${snotlink} == yes ]]; then
+
+			# Remove static libs we're not supposed to link against.
+			if [[ -f ${archivefile} ]]; then
+				einfo "Removing unnecessary ${archivefile#${D%/}} (static plugin)"
+				queue+=( "${archivefile}" )
+			fi
+
+			# The .la file may be used by a module loader, so avoid removing it
+			# unless explicitly requested.
+			if [[ ${removing_modules} ]]; then
+				reason='module'
+			fi
+
+		else
+
+			# Remove .la files when:
+			# - user explicitly wants us to remove all .la files,
+			# - respective static archive doesn't exist,
+			# - they are covered by a .pc file already,
+			# - they don't provide any new information (no libs & no flags).
+
+			if [[ ${removing_all} ]]; then
+				reason='requested'
+			elif [[ ! -f ${archivefile} ]]; then
+				reason='no static archive'
+			elif [[ ! $(sed -nre \
+					"s/^(dependency_libs|inherited_linker_flags)='(.*)'$/\2/p" \
+					"${f}") ]]; then
+				reason='no libs & flags'
+			else
+				if [[ ! ${pkgconfig_scanned} ]]; then
+					# Create a list of all .pc-covered libs.
+					local pc_libs=()
+					if [[ ! ${removing_all} ]]; then
+						local pc
+						local tf=${T}/prune-lt-files.pc
+						local pkgconf=$(tc-getPKG_CONFIG)
+
+						while IFS= read -r -d '' pc; do # for all .pc files
+							local arg libs
+
+							# Use pkg-config if available (and works),
+							# fallback to sed.
+							if ${pkgconf} --exists "${pc}" &>/dev/null; then
+								sed -e '/^Requires:/d' "${pc}" > "${tf}"
+								libs=$(${pkgconf} --libs "${tf}")
+							else
+								libs=$(sed -ne 's/^Libs://p' "${pc}")
+							fi
+
+							for arg in ${libs}; do
+								if [[ ${arg} == -l* ]]; then
+									if [[ ${arg} == '*$*' ]]; then
+										eerror "${FUNCNAME}: variable substitution likely failed in ${pc}"
+										eerror "(arg: ${arg})"
+										eerror "Most likely, you need to add virtual/pkgconfig to DEPEND."
+										die "${FUNCNAME}: unsubstituted variable found in .pc"
+									fi
+
+									pc_libs+=( lib${arg#-l}.la )
+								fi
+							done
+						done < <(find "${D}" -type f -name '*.pc' -print0)
+
+						rm -f "${tf}"
+					fi
+
+					pkgconfig_scanned=1
+				fi # pkgconfig_scanned
+
+				has "${f##*/}" "${pc_libs[@]}" && reason='covered by .pc'
+			fi # removal due to .pc
+
+		fi # shouldnotlink==no
+
+		if [[ ${reason} ]]; then
+			einfo "Removing unnecessary ${f#${D%/}} (${reason})"
+			queue+=( "${f}" )
+		fi
+	done < <(find "${D}" -xtype f -name '*.la' -print0)
+
+	if [[ ${queue[@]} ]]; then
+		rm -f "${queue[@]}"
+	fi
+}
+
+_LTPRUNE_ECLASS=1
+fi #_LTPRUNE_ECLASS
-- 
2.12.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [gentoo-dev] [PATCH 2/3] eutils.eclass: prune_libtool_files, make .pc subst errors fatal
  2017-03-12 11:00   ` [gentoo-dev] [PATCH 2/3] eutils.eclass: prune_libtool_files, make .pc subst errors fatal Michał Górny
@ 2017-03-12 11:35     ` Alexis Ballier
  2017-03-12 12:20       ` Michał Górny
  0 siblings, 1 reply; 9+ messages in thread
From: Alexis Ballier @ 2017-03-12 11:35 UTC (permalink / raw
  To: gentoo-dev

On Sun, 12 Mar 2017 12:00:08 +0100
Michał Górny <mgorny@gentoo.org> wrote:

> Make the substitution errors in prune_libtool_files logic fatal to
> avoid the dependency of eqawarn. They're extremely unlikely to happen
> anyway. ---
>  eclass/eutils.eclass | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/eclass/eutils.eclass b/eclass/eutils.eclass
> index ab226b236a37..cb472caee1d4 100644
> --- a/eclass/eutils.eclass
> +++ b/eclass/eutils.eclass
> @@ -982,9 +982,10 @@ prune_libtool_files() {
>  							for arg in
> ${libs}; do if [[ ${arg} == -l* ]]; then
>  									if
> [[ ${arg} == '*$*' ]]; then
> -
> eqawarn "${FUNCNAME}: variable substitution likely failed in ${pc}"
> -
> eqawarn "(arg: ${arg})"
> -
> eqawarn "Most likely, you need to add virtual/pkgconfig to DEPEND."
> +
> eerror "${FUNCNAME}: variable substitution likely failed in ${pc}"
> +
> eerror "(arg: ${arg})"
> +
> eerror "Most likely, you need to add virtual/pkgconfig to DEPEND."
> +
> die "${FUNCNAME}: unsubstituted variable found in .pc" fi

If you go that way then it would be best if this function had a 
'has "virtual/pkgconfig" ${DEPEND} || die ...' kind of logic

the message is more intended towards package maintainer and i would
assume they have pkgconfig installed which means the failure will
be on user's throat


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [gentoo-dev] [PATCH 2/3] eutils.eclass: prune_libtool_files, make .pc subst errors fatal
  2017-03-12 11:35     ` Alexis Ballier
@ 2017-03-12 12:20       ` Michał Górny
  2017-03-12 12:34         ` Alexis Ballier
  0 siblings, 1 reply; 9+ messages in thread
From: Michał Górny @ 2017-03-12 12:20 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 1702 bytes --]

W dniu 12.03.2017, nie o godzinie 12∶35 +0100, użytkownik Alexis Ballier
napisał:
> On Sun, 12 Mar 2017 12:00:08 +0100
> Michał Górny <mgorny@gentoo.org> wrote:
> 
> > Make the substitution errors in prune_libtool_files logic fatal to
> > avoid the dependency of eqawarn. They're extremely unlikely to happen
> > anyway. ---
> >  eclass/eutils.eclass | 7 ++++---
> >  1 file changed, 4 insertions(+), 3 deletions(-)
> > 
> > diff --git a/eclass/eutils.eclass b/eclass/eutils.eclass
> > index ab226b236a37..cb472caee1d4 100644
> > --- a/eclass/eutils.eclass
> > +++ b/eclass/eutils.eclass
> > @@ -982,9 +982,10 @@ prune_libtool_files() {
> >  							for arg in
> > ${libs}; do if [[ ${arg} == -l* ]]; then
> >  									if
> > [[ ${arg} == '*$*' ]]; then
> > -
> > eqawarn "${FUNCNAME}: variable substitution likely failed in ${pc}"
> > -
> > eqawarn "(arg: ${arg})"
> > -
> > eqawarn "Most likely, you need to add virtual/pkgconfig to DEPEND."
> > +
> > eerror "${FUNCNAME}: variable substitution likely failed in ${pc}"
> > +
> > eerror "(arg: ${arg})"
> > +
> > eerror "Most likely, you need to add virtual/pkgconfig to DEPEND."
> > +
> > die "${FUNCNAME}: unsubstituted variable found in .pc" fi
> 
> If you go that way then it would be best if this function had a 
> 'has "virtual/pkgconfig" ${DEPEND} || die ...' kind of logic

You can't reliably query DEPEND in an ebuild.

> the message is more intended towards package maintainer and i would
> assume they have pkgconfig installed which means the failure will
> be on user's throat

...in the extremely unlikely case of not having pkg-config installed.

-- 
Best regards,
Michał Górny

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 963 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [gentoo-dev] [PATCH 2/3] eutils.eclass: prune_libtool_files, make .pc subst errors fatal
  2017-03-12 12:20       ` Michał Górny
@ 2017-03-12 12:34         ` Alexis Ballier
  0 siblings, 0 replies; 9+ messages in thread
From: Alexis Ballier @ 2017-03-12 12:34 UTC (permalink / raw
  To: gentoo-dev

On Sun, 12 Mar 2017 13:20:18 +0100
Michał Górny <mgorny@gentoo.org> wrote:

> > If you go that way then it would be best if this function had a 
> > 'has "virtual/pkgconfig" ${DEPEND} || die ...' kind of logic  
> 
> You can't reliably query DEPEND in an ebuild.

yeah i though so

> > the message is more intended towards package maintainer and i would
> > assume they have pkgconfig installed which means the failure will
> > be on user's throat  
> 
> ...in the extremely unlikely case of not having pkg-config installed.


... that has far greater chances to be hit by an user than a
developer :)


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [gentoo-dev] [PATCH v2] ltprune.eclass
  2017-03-12 11:00 ` [gentoo-dev] [PATCH v2] ltprune.eclass Michał Górny
                     ` (2 preceding siblings ...)
  2017-03-12 11:00   ` [gentoo-dev] [PATCH 3/3] ltprune.eclass: Split prune_libtool_files out of eutils Michał Górny
@ 2017-03-18  7:35   ` Michał Górny
  3 siblings, 0 replies; 9+ messages in thread
From: Michał Górny @ 2017-03-18  7:35 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 221 bytes --]

On nie, 2017-03-12 at 12:00 +0100, Michał Górny wrote:
> Changes in v2:
> - now in split commits to ease review,
> - removed eqawarn to avoid circ dep on eutils.
> 

Merged.

-- 
Best regards,
Michał Górny

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 963 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-03-18  7:38 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-12 10:39 [gentoo-dev] [PATCH] ltprune.eclass: Split prune_libtool_files out of eutils Michał Górny
2017-03-12 11:00 ` [gentoo-dev] [PATCH v2] ltprune.eclass Michał Górny
2017-03-12 11:00   ` [gentoo-dev] [PATCH 1/3] eutils.eclass: prune_libtool_files, punt pointless Prefix logic Michał Górny
2017-03-12 11:00   ` [gentoo-dev] [PATCH 2/3] eutils.eclass: prune_libtool_files, make .pc subst errors fatal Michał Górny
2017-03-12 11:35     ` Alexis Ballier
2017-03-12 12:20       ` Michał Górny
2017-03-12 12:34         ` Alexis Ballier
2017-03-12 11:00   ` [gentoo-dev] [PATCH 3/3] ltprune.eclass: Split prune_libtool_files out of eutils Michał Górny
2017-03-18  7:35   ` [gentoo-dev] [PATCH v2] ltprune.eclass Michał Górny

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox