| 1 | # Copyright 1999-2011 Gentoo Foundation |
1 | # Copyright 1999-2011 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.358 2011/07/08 11:35:01 ssuominen Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.363 2011/09/12 20:44:01 mgorny 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 |
| … | |
… | |
| 64 | fi |
64 | fi |
| 65 | |
65 | |
| 66 | # @FUNCTION: eqawarn |
66 | # @FUNCTION: eqawarn |
| 67 | # @USAGE: [message] |
67 | # @USAGE: [message] |
| 68 | # @DESCRIPTION: |
68 | # @DESCRIPTION: |
| 69 | # Proxy to einfo for package managers that don't provide eqawarn and use the PM |
69 | # Proxy to ewarn for package managers that don't provide eqawarn and use the PM |
| 70 | # implementation if available. |
70 | # implementation if available. Reuses PORTAGE_ELOG_CLASSES as set by the dev |
|
|
71 | # profile. |
| 71 | if ! declare -F eqawarn >/dev/null ; then |
72 | if ! declare -F eqawarn >/dev/null ; then |
| 72 | eqawarn() { |
73 | eqawarn() { |
| 73 | einfo "$@" |
74 | has qa ${PORTAGE_ELOG_CLASSES} && ewarn "$@" |
| 74 | } |
75 | } |
| 75 | fi |
76 | fi |
| 76 | |
77 | |
| 77 | # @FUNCTION: ecvs_clean |
78 | # @FUNCTION: ecvs_clean |
| 78 | # @USAGE: [list of dirs] |
79 | # @USAGE: [list of dirs] |
| … | |
… | |
| 250 | |
251 | |
| 251 | elif [[ -d $1 ]] ; then |
252 | elif [[ -d $1 ]] ; then |
| 252 | # Some people like to make dirs of patches w/out suffixes (vim) |
253 | # Some people like to make dirs of patches w/out suffixes (vim) |
| 253 | set -- "$1"/*${EPATCH_SUFFIX:+."${EPATCH_SUFFIX}"} |
254 | set -- "$1"/*${EPATCH_SUFFIX:+."${EPATCH_SUFFIX}"} |
| 254 | |
255 | |
|
|
256 | elif [[ -f ${EPATCH_SOURCE}/$1 ]] ; then |
|
|
257 | # Re-use EPATCH_SOURCE as a search dir |
|
|
258 | epatch "${EPATCH_SOURCE}/$1" |
|
|
259 | return $? |
|
|
260 | |
| 255 | else |
261 | else |
| 256 | # sanity check ... if it isn't a dir or file, wtf man ? |
262 | # sanity check ... if it isn't a dir or file, wtf man ? |
| 257 | [[ $# -ne 0 ]] && EPATCH_SOURCE=$1 |
263 | [[ $# -ne 0 ]] && EPATCH_SOURCE=$1 |
| 258 | echo |
264 | echo |
| 259 | eerror "Cannot find \$EPATCH_SOURCE! Value for \$EPATCH_SOURCE is:" |
265 | eerror "Cannot find \$EPATCH_SOURCE! Value for \$EPATCH_SOURCE is:" |
| … | |
… | |
| 375 | _epatch_draw_line "***** ${patchname} *****" |
381 | _epatch_draw_line "***** ${patchname} *****" |
| 376 | echo |
382 | echo |
| 377 | echo "PATCH COMMAND: patch -p${count} ${EPATCH_OPTS} < '${PATCH_TARGET}'" |
383 | echo "PATCH COMMAND: patch -p${count} ${EPATCH_OPTS} < '${PATCH_TARGET}'" |
| 378 | echo |
384 | echo |
| 379 | _epatch_draw_line "***** ${patchname} *****" |
385 | _epatch_draw_line "***** ${patchname} *****" |
|
|
386 | patch -p${count} ${EPATCH_OPTS} --dry-run -f < "${PATCH_TARGET}" 2>&1 |
|
|
387 | ret=$? |
|
|
388 | echo |
|
|
389 | echo "patch program exited with status ${ret}" |
|
|
390 | exit ${ret} |
| 380 | ) >> "${STDERR_TARGET}" |
391 | ) >> "${STDERR_TARGET}" |
| 381 | |
392 | |
| 382 | if (patch -p${count} ${EPATCH_OPTS} --dry-run -f < "${PATCH_TARGET}") >> "${STDERR_TARGET}" 2>&1 ; then |
393 | if [ $? -eq 0 ] ; then |
| 383 | ( |
394 | ( |
| 384 | _epatch_draw_line "***** ${patchname} *****" |
395 | _epatch_draw_line "***** ${patchname} *****" |
| 385 | echo |
396 | echo |
| 386 | echo "ACTUALLY APPLYING ${patchname} ..." |
397 | echo "ACTUALLY APPLYING ${patchname} ..." |
| 387 | echo |
398 | echo |
| 388 | _epatch_draw_line "***** ${patchname} *****" |
399 | _epatch_draw_line "***** ${patchname} *****" |
| 389 | patch -p${count} ${EPATCH_OPTS} < "${PATCH_TARGET}" 2>&1 |
400 | patch -p${count} ${EPATCH_OPTS} < "${PATCH_TARGET}" 2>&1 |
|
|
401 | ret=$? |
|
|
402 | echo |
|
|
403 | echo "patch program exited with status ${ret}" |
|
|
404 | exit ${ret} |
| 390 | ) >> "${STDERR_TARGET}" |
405 | ) >> "${STDERR_TARGET}" |
| 391 | |
406 | |
| 392 | if [ $? -ne 0 ] ; then |
407 | if [ $? -ne 0 ] ; then |
| 393 | echo |
408 | echo |
| 394 | eerror "A dry-run of patch command succeeded, but actually" |
409 | eerror "A dry-run of patch command succeeded, but actually" |
| … | |
… | |
| 425 | done |
440 | done |
| 426 | |
441 | |
| 427 | [[ ${SINGLE_PATCH} == "no" ]] && einfo "Done with patching" |
442 | [[ ${SINGLE_PATCH} == "no" ]] && einfo "Done with patching" |
| 428 | : # everything worked |
443 | : # everything worked |
| 429 | } |
444 | } |
|
|
445 | |
|
|
446 | # @FUNCTION: epatch_user |
|
|
447 | # @USAGE: |
|
|
448 | # @DESCRIPTION: |
|
|
449 | # Applies user-provided patches to the source tree. The patches are |
|
|
450 | # taken from /etc/portage/patches/<CATEGORY>/<PF|P|PN>/, where the first |
|
|
451 | # of these three directories to exist will be the one to use, ignoring |
|
|
452 | # any more general directories which might exist as well. |
|
|
453 | # |
|
|
454 | # User patches are intended for quick testing of patches without ebuild |
|
|
455 | # modifications, as well as for permanent customizations a user might |
|
|
456 | # desire. Obviously, there can be no official support for arbitrarily |
|
|
457 | # patched ebuilds. So whenever a build log in a bug report mentions that |
|
|
458 | # user patches were applied, the user should be asked to reproduce the |
|
|
459 | # problem without these. |
|
|
460 | # |
|
|
461 | # Not all ebuilds do call this function, so placing patches in the |
|
|
462 | # stated directory might or might not work, depending on the package and |
|
|
463 | # the eclasses it inherits and uses. It is safe to call the function |
|
|
464 | # repeatedly, so it is always possible to add a call at the ebuild |
|
|
465 | # level. The first call is the time when the patches will be |
|
|
466 | # applied. |
|
|
467 | # |
|
|
468 | # Ideally, this function should be called after gentoo-specific patches |
|
|
469 | # have been applied, so that their code can be modified as well, but |
|
|
470 | # before calls to e.g. eautoreconf, as the user patches might affect |
|
|
471 | # autotool input files as well. |
| 430 | epatch_user() { |
472 | epatch_user() { |
| 431 | [[ $# -ne 0 ]] && die "epatch_user takes no options" |
473 | [[ $# -ne 0 ]] && die "epatch_user takes no options" |
|
|
474 | |
|
|
475 | # Allow multiple calls to this function; ignore all but the first |
|
|
476 | local applied="${T}/epatch_user.applied" |
|
|
477 | [[ -e ${applied} ]] && return 2 |
| 432 | |
478 | |
| 433 | # don't clobber any EPATCH vars that the parent might want |
479 | # don't clobber any EPATCH vars that the parent might want |
| 434 | local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches |
480 | local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches |
| 435 | for check in {${CATEGORY}/${PF},${CATEGORY}/${P},${CATEGORY}/${PN}}; do |
481 | for check in {${CATEGORY}/${PF},${CATEGORY}/${P},${CATEGORY}/${PN}}; do |
| 436 | EPATCH_SOURCE=${base}/${CTARGET}/${check} |
482 | EPATCH_SOURCE=${base}/${CTARGET}/${check} |
| … | |
… | |
| 440 | EPATCH_SOURCE=${EPATCH_SOURCE} \ |
486 | EPATCH_SOURCE=${EPATCH_SOURCE} \ |
| 441 | EPATCH_SUFFIX="patch" \ |
487 | EPATCH_SUFFIX="patch" \ |
| 442 | EPATCH_FORCE="yes" \ |
488 | EPATCH_FORCE="yes" \ |
| 443 | EPATCH_MULTI_MSG="Applying user patches from ${EPATCH_SOURCE} ..." \ |
489 | EPATCH_MULTI_MSG="Applying user patches from ${EPATCH_SOURCE} ..." \ |
| 444 | epatch |
490 | epatch |
|
|
491 | echo "${EPATCH_SOURCE}" > "${applied}" |
| 445 | return 0 |
492 | return 0 |
| 446 | fi |
493 | fi |
| 447 | done |
494 | done |
|
|
495 | echo "none" > "${applied}" |
| 448 | return 1 |
496 | return 1 |
| 449 | } |
497 | } |
| 450 | |
498 | |
| 451 | # @FUNCTION: emktemp |
499 | # @FUNCTION: emktemp |
| 452 | # @USAGE: [temp dir] |
500 | # @USAGE: [temp dir] |