/[gentoo-x86]/eclass/eutils.eclass
Gentoo

Diff of /eclass/eutils.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.414 Revision 1.424
1# Copyright 1999-2013 Gentoo Foundation 1# Copyright 1999-2013 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.414 2013/03/11 00:13:16 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.424 2013/06/21 23:57:03 vapier Exp $
4 4
5# @ECLASS: eutils.eclass 5# @ECLASS: eutils.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# base-system@gentoo.org 7# base-system@gentoo.org
8# @BLURB: many extra (but common) functions that are used in ebuilds 8# @BLURB: many extra (but common) functions that are used in ebuilds
142 142
143 if [[ -n ${__estack_retvar} ]] ; then 143 if [[ -n ${__estack_retvar} ]] ; then
144 eval ${__estack_retvar}=\"\${${__estack_name}\[${__estack_i}\]}\" 144 eval ${__estack_retvar}=\"\${${__estack_name}\[${__estack_i}\]}\"
145 fi 145 fi
146 eval unset ${__estack_name}\[${__estack_i}\] 146 eval unset ${__estack_name}\[${__estack_i}\]
147}
148
149# @FUNCTION: evar_push
150# @USAGE: <variable to save> [more vars to save]
151# @DESCRIPTION:
152# This let's you temporarily modify a variable and then restore it (including
153# set vs unset semantics). Arrays are not supported at this time.
154#
155# This is meant for variables where using `local` does not work (such as
156# exported variables, or only temporarily changing things in a func).
157#
158# For example:
159# @CODE
160# evar_push LC_ALL
161# export LC_ALL=C
162# ... do some stuff that needs LC_ALL=C set ...
163# evar_pop
164#
165# # You can also save/restore more than one var at a time
166# evar_push BUTTERFLY IN THE SKY
167# ... do stuff with the vars ...
168# evar_pop # This restores just one var, SKY
169# ... do more stuff ...
170# evar_pop 3 # This pops the remaining 3 vars
171# @CODE
172evar_push() {
173 local var val
174 for var ; do
175 [[ ${!var+set} == "set" ]] \
176 && val=${!var} \
177 || val="${___ECLASS_ONCE_EUTILS}"
178 estack_push evar "${var}" "${val}"
179 done
180}
181
182# @FUNCTION: evar_push_set
183# @USAGE: <variable to save> [new value to store]
184# @DESCRIPTION:
185# This is a handy shortcut to save and temporarily set a variable. If a value
186# is not specified, the var will be unset.
187evar_push_set() {
188 local var=$1
189 evar_push ${var}
190 case $# in
191 1) unset ${var} ;;
192 2) printf -v "${var}" '%s' "$2" ;;
193 *) die "${FUNCNAME}: incorrect # of args: $*" ;;
194 esac
195}
196
197# @FUNCTION: evar_pop
198# @USAGE: [number of vars to restore]
199# @DESCRIPTION:
200# Restore the variables to the state saved with the corresponding
201# evar_push call. See that function for more details.
202evar_pop() {
203 local cnt=${1:-bad}
204 case $# in
205 0) cnt=1 ;;
206 1) isdigit "${cnt}" || die "${FUNCNAME}: first arg must be a number: $*" ;;
207 *) die "${FUNCNAME}: only accepts one arg: $*" ;;
208 esac
209
210 local var val
211 while (( cnt-- )) ; do
212 estack_pop evar val || die "${FUNCNAME}: unbalanced push"
213 estack_pop evar var || die "${FUNCNAME}: unbalanced push"
214 [[ ${val} == "${___ECLASS_ONCE_EUTILS}" ]] \
215 && unset ${var} \
216 || printf -v "${var}" '%s' "${val}"
217 done
147} 218}
148 219
149# @FUNCTION: eshopts_push 220# @FUNCTION: eshopts_push
150# @USAGE: [options to `set` or `shopt`] 221# @USAGE: [options to `set` or `shopt`]
151# @DESCRIPTION: 222# @DESCRIPTION:
216 local s 287 local s
217 estack_pop eumask s || die "${FUNCNAME}: unbalanced push" 288 estack_pop eumask s || die "${FUNCNAME}: unbalanced push"
218 umask ${s} || die "${FUNCNAME}: sanity: could not restore umask: ${s}" 289 umask ${s} || die "${FUNCNAME}: sanity: could not restore umask: ${s}"
219} 290}
220 291
292# @FUNCTION: isdigit
293# @USAGE: <number> [more numbers]
294# @DESCRIPTION:
295# Return true if all arguments are numbers.
296isdigit() {
297 local d
298 for d ; do
299 [[ ${d:-bad} == *[!0-9]* ]] && return 1
300 done
301 return 0
302}
303
221# @VARIABLE: EPATCH_SOURCE 304# @VARIABLE: EPATCH_SOURCE
222# @DESCRIPTION: 305# @DESCRIPTION:
223# Default directory to search for patches. 306# Default directory to search for patches.
224EPATCH_SOURCE="${WORKDIR}/patch" 307EPATCH_SOURCE="${WORKDIR}/patch"
225# @VARIABLE: EPATCH_SUFFIX 308# @VARIABLE: EPATCH_SUFFIX
259# @VARIABLE: EPATCH_FORCE 342# @VARIABLE: EPATCH_FORCE
260# @DESCRIPTION: 343# @DESCRIPTION:
261# Only require patches to match EPATCH_SUFFIX rather than the extended 344# Only require patches to match EPATCH_SUFFIX rather than the extended
262# arch naming style. 345# arch naming style.
263EPATCH_FORCE="no" 346EPATCH_FORCE="no"
347# @VARIABLE: EPATCH_USER_EXCLUDE
348# @DEFAULT_UNSET
349# @DESCRIPTION:
350# List of patches not to apply. Note this is only file names,
351# and not the full path. Globs accepted.
264 352
265# @FUNCTION: epatch 353# @FUNCTION: epatch
266# @USAGE: [options] [patches] [dirs of patches] 354# @USAGE: [options] [patches] [dirs of patches]
267# @DESCRIPTION: 355# @DESCRIPTION:
268# epatch is designed to greatly simplify the application of patches. It can 356# epatch is designed to greatly simplify the application of patches. It can
337 # Use the suffix from the single patch (localize it); the code 425 # Use the suffix from the single patch (localize it); the code
338 # below will find the suffix for us 426 # below will find the suffix for us
339 local EPATCH_SUFFIX=$1 427 local EPATCH_SUFFIX=$1
340 428
341 elif [[ -d $1 ]] ; then 429 elif [[ -d $1 ]] ; then
430 # We have to force sorting to C so that the wildcard expansion is consistent #471666.
431 evar_push_set LC_COLLATE C
342 # Some people like to make dirs of patches w/out suffixes (vim) 432 # Some people like to make dirs of patches w/out suffixes (vim).
343 set -- "$1"/*${EPATCH_SUFFIX:+."${EPATCH_SUFFIX}"} 433 set -- "$1"/*${EPATCH_SUFFIX:+."${EPATCH_SUFFIX}"}
434 evar_pop
344 435
345 elif [[ -f ${EPATCH_SOURCE}/$1 ]] ; then 436 elif [[ -f ${EPATCH_SOURCE}/$1 ]] ; then
346 # Re-use EPATCH_SOURCE as a search dir 437 # Re-use EPATCH_SOURCE as a search dir
347 epatch "${EPATCH_SOURCE}/$1" 438 epatch "${EPATCH_SOURCE}/$1"
348 return $? 439 return $?
403 eshopts_push -o noglob 494 eshopts_push -o noglob
404 495
405 local ex 496 local ex
406 for ex in ${EPATCH_EXCLUDE} ; do 497 for ex in ${EPATCH_EXCLUDE} ; do
407 if [[ ${patchname} == ${ex} ]] ; then 498 if [[ ${patchname} == ${ex} ]] ; then
499 einfo " Skipping ${patchname} due to EPATCH_EXCLUDE ..."
500 eshopts_pop
501 continue 2
502 fi
503 done
504
505 for ex in ${EPATCH_USER_EXCLUDE} ; do
506 if [[ ${patchname} == ${ex} ]] ; then
507 einfo " Skipping ${patchname} due to EPATCH_USER_EXCLUDE ..."
408 eshopts_pop 508 eshopts_pop
409 continue 2 509 continue 2
410 fi 510 fi
411 done 511 done
412 512
460 printf "NOTE: skipping -p0 due to absolute paths in patch:\n%s\n" "${abs_paths}" >> "${STDERR_TARGET}" 560 printf "NOTE: skipping -p0 due to absolute paths in patch:\n%s\n" "${abs_paths}" >> "${STDERR_TARGET}"
461 fi 561 fi
462 # Similar reason, but with relative paths. 562 # Similar reason, but with relative paths.
463 local rel_paths=$(egrep -n '^[-+]{3} [^ ]*[.][.]/' "${PATCH_TARGET}") 563 local rel_paths=$(egrep -n '^[-+]{3} [^ ]*[.][.]/' "${PATCH_TARGET}")
464 if [[ -n ${rel_paths} ]] ; then 564 if [[ -n ${rel_paths} ]] ; then
565 echo
566 eerror "Rejected Patch: ${patchname} !"
567 eerror " ( ${PATCH_TARGET} )"
568 eerror
465 eqawarn "QA Notice: Your patch uses relative paths '../'." 569 eerror "Your patch uses relative paths '../':"
466 eqawarn " In the future this will cause a failure."
467 eqawarn "${rel_paths}" 570 eerror "${rel_paths}"
571 echo
572 die "you need to fix the relative paths in patch"
468 fi 573 fi
469 574
470 # Dynamically detect the correct -p# ... i'm lazy, so shoot me :/ 575 # Dynamically detect the correct -p# ... i'm lazy, so shoot me :/
471 local patch_cmd 576 local patch_cmd
577 # Handle aliased patch command #404447 #461568
578 local patch="patch"
579 eval $(alias patch 2>/dev/null | sed 's:^alias ::')
472 while [[ ${count} -lt 5 ]] ; do 580 while [[ ${count} -lt 5 ]] ; do
473 patch_cmd="${BASH_ALIASES[patch]:-patch} -p${count} ${EPATCH_OPTS}" 581 patch_cmd="${patch} -p${count} ${EPATCH_OPTS}"
474 582
475 # Generate some useful debug info ... 583 # Generate some useful debug info ...
476 ( 584 (
477 _epatch_draw_line "***** ${patchname} *****" 585 _epatch_draw_line "***** ${patchname} *****"
478 echo 586 echo
1267# http://bugs.gentoo.org/73450 1375# http://bugs.gentoo.org/73450
1268epunt_cxx() { 1376epunt_cxx() {
1269 local dir=$1 1377 local dir=$1
1270 [[ -z ${dir} ]] && dir=${S} 1378 [[ -z ${dir} ]] && dir=${S}
1271 ebegin "Removing useless C++ checks" 1379 ebegin "Removing useless C++ checks"
1272 local f any_found 1380 local f p any_found
1273 while IFS= read -r -d '' f; do 1381 while IFS= read -r -d '' f; do
1274 patch --no-backup-if-mismatch -p0 "${f}" \ 1382 for p in "${PORTDIR}"/eclass/ELT-patches/nocxx/*.patch ; do
1275 "${PORTDIR}/eclass/ELT-patches/nocxx/nocxx.patch" > /dev/null \ 1383 if patch --no-backup-if-mismatch -p1 "${f}" "${p}" >/dev/null ; then
1276 && any_found=1 1384 any_found=1
1385 break
1386 fi
1387 done
1277 done < <(find "${dir}" -name configure -print0) 1388 done < <(find "${dir}" -name configure -print0)
1278 1389
1279# if [[ -z ${any_found} ]]; then 1390 if [[ -z ${any_found} ]]; then
1280# eqawarn "epunt_cxx called unnecessarily (no C++ checks to punt)." 1391 eqawarn "epunt_cxx called unnecessarily (no C++ checks to punt)."
1281# fi 1392 fi
1282 eend 0 1393 eend 0
1283} 1394}
1284 1395
1285# @FUNCTION: make_wrapper 1396# @FUNCTION: make_wrapper
1286# @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath] 1397# @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath]
1435 local f 1546 local f
1436 local queue=() 1547 local queue=()
1437 while IFS= read -r -d '' f; do # for all .la files 1548 while IFS= read -r -d '' f; do # for all .la files
1438 local archivefile=${f/%.la/.a} 1549 local archivefile=${f/%.la/.a}
1439 1550
1551 # The following check is done by libtool itself.
1552 # It helps us avoid removing random files which match '*.la',
1553 # see bug #468380.
1554 if ! sed -n -e '/^# Generated by .*libtool/q0;4q1' "${f}"; then
1555 continue
1556 fi
1557
1440 [[ ${f} != ${archivefile} ]] || die 'regex sanity check failed' 1558 [[ ${f} != ${archivefile} ]] || die 'regex sanity check failed'
1441
1442 local reason pkgconfig_scanned 1559 local reason pkgconfig_scanned
1560 local snotlink=$(sed -n -e 's:^shouldnotlink=::p' "${f}")
1443 1561
1562 if [[ ${snotlink} == yes ]]; then
1563
1444 # Remove static libs we're not supposed to link against. 1564 # Remove static libs we're not supposed to link against.
1445 if grep -q '^shouldnotlink=yes$' "${f}"; then
1446 if [[ -f ${archivefile} ]]; then 1565 if [[ -f ${archivefile} ]]; then
1447 einfo "Removing unnecessary ${archivefile#${D%/}} (static plugin)" 1566 einfo "Removing unnecessary ${archivefile#${D%/}} (static plugin)"
1448 queue+=( "${archivefile}" ) 1567 queue+=( "${archivefile}" )
1449 fi 1568 fi
1450 1569
1452 # unless explicitly requested. 1571 # unless explicitly requested.
1453 if [[ ${removing_modules} ]]; then 1572 if [[ ${removing_modules} ]]; then
1454 reason='module' 1573 reason='module'
1455 fi 1574 fi
1456 1575
1457 # Remove .la files when:
1458 # - user explicitly wants us to remove all .la files,
1459 # - respective static archive doesn't exist,
1460 # - they are covered by a .pc file already,
1461 # - they don't provide any new information (no libs & no flags).
1462
1463 elif [[ ${removing_all} ]]; then
1464 reason='requested'
1465 elif [[ ! -f ${archivefile} ]]; then
1466 reason='no static archive'
1467 elif [[ ! $(sed -nre \
1468 "s/^(dependency_libs|inherited_linker_flags)='(.*)'$/\2/p" \
1469 "${f}") ]]; then
1470 reason='no libs & flags'
1471 else 1576 else
1577
1578 # Remove .la files when:
1579 # - user explicitly wants us to remove all .la files,
1580 # - respective static archive doesn't exist,
1581 # - they are covered by a .pc file already,
1582 # - they don't provide any new information (no libs & no flags).
1583
1584 if [[ ${removing_all} ]]; then
1585 reason='requested'
1586 elif [[ ! -f ${archivefile} ]]; then
1587 reason='no static archive'
1588 elif [[ ! $(sed -nre \
1589 "s/^(dependency_libs|inherited_linker_flags)='(.*)'$/\2/p" \
1590 "${f}") ]]; then
1591 reason='no libs & flags'
1592 else
1472 if [[ ! ${pkgconfig_scanned} ]]; then 1593 if [[ ! ${pkgconfig_scanned} ]]; then
1473 # Create a list of all .pc-covered libs. 1594 # Create a list of all .pc-covered libs.
1474 local pc_libs=() 1595 local pc_libs=()
1475 if [[ ! ${removing_all} ]]; then 1596 if [[ ! ${removing_all} ]]; then
1476 local pc 1597 local pc
1477 local tf=${T}/prune-lt-files.pc 1598 local tf=${T}/prune-lt-files.pc
1478 local pkgconf=$(tc-getPKG_CONFIG) 1599 local pkgconf=$(tc-getPKG_CONFIG)
1479 1600
1480 while IFS= read -r -d '' pc; do # for all .pc files 1601 while IFS= read -r -d '' pc; do # for all .pc files
1481 local arg libs 1602 local arg libs
1482 1603
1483 # Use pkg-config if available (and works), 1604 # Use pkg-config if available (and works),
1484 # fallback to sed. 1605 # fallback to sed.
1485 if ${pkgconf} --exists "${pc}" &>/dev/null; then 1606 if ${pkgconf} --exists "${pc}" &>/dev/null; then
1486 sed -e '/^Requires:/d' "${pc}" > "${tf}" 1607 sed -e '/^Requires:/d' "${pc}" > "${tf}"
1487 libs=$(${pkgconf} --libs "${tf}") 1608 libs=$(${pkgconf} --libs "${tf}")
1488 else 1609 else
1489 libs=$(sed -ne 's/^Libs://p' "${pc}") 1610 libs=$(sed -ne 's/^Libs://p' "${pc}")
1490 fi 1611 fi
1491 1612
1492 for arg in ${libs}; do 1613 for arg in ${libs}; do
1493 if [[ ${arg} == -l* ]]; then 1614 if [[ ${arg} == -l* ]]; then
1494 if [[ ${arg} == '*$*' ]]; then 1615 if [[ ${arg} == '*$*' ]]; then
1495 eqawarn "${FUNCNAME}: variable substitution likely failed in ${pc}" 1616 eqawarn "${FUNCNAME}: variable substitution likely failed in ${pc}"
1496 eqawarn "(arg: ${arg})" 1617 eqawarn "(arg: ${arg})"
1497 eqawarn "Most likely, you need to add virtual/pkgconfig to DEPEND." 1618 eqawarn "Most likely, you need to add virtual/pkgconfig to DEPEND."
1619 fi
1620
1621 pc_libs+=( lib${arg#-l}.la )
1498 fi 1622 fi
1499
1500 pc_libs+=( lib${arg#-l}.la )
1501 fi
1502 done 1623 done
1503 done < <(find "${D}" -type f -name '*.pc' -print0) 1624 done < <(find "${D}" -type f -name '*.pc' -print0)
1504 1625
1505 rm -f "${tf}" 1626 rm -f "${tf}"
1506 fi 1627 fi
1507 1628
1508 pkgconfig_scanned=1 1629 pkgconfig_scanned=1
1509 fi 1630 fi # pkgconfig_scanned
1510 1631
1511 has "${f##*/}" "${pc_libs[@]}" && reason='covered by .pc' 1632 has "${f##*/}" "${pc_libs[@]}" && reason='covered by .pc'
1512 fi 1633 fi # removal due to .pc
1634
1635 fi # shouldnotlink==no
1513 1636
1514 if [[ ${reason} ]]; then 1637 if [[ ${reason} ]]; then
1515 einfo "Removing unnecessary ${f#${D%/}} (${reason})" 1638 einfo "Removing unnecessary ${f#${D%/}} (${reason})"
1516 queue+=( "${f}" ) 1639 queue+=( "${f}" )
1517 fi 1640 fi

Legend:
Removed from v.1.414  
changed lines
  Added in v.1.424

  ViewVC Help
Powered by ViewVC 1.1.20