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

Diff of /eclass/eutils.eclass

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

Revision 1.377 Revision 1.383
1# Copyright 1999-2011 Gentoo Foundation 1# Copyright 1999-2012 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.377 2012/01/03 08:45:36 jlec Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.383 2012/02/16 00:27:17 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
212# @FUNCTION: eumask_pop 212# @FUNCTION: eumask_pop
213# @USAGE: 213# @USAGE:
214# @DESCRIPTION: 214# @DESCRIPTION:
215# Restore the previous umask state. 215# Restore the previous umask state.
216eumask_pop() { 216eumask_pop() {
217 [[ $# -eq 0 ]] || die "${FUNCNAME}: we take no options"
217 local s 218 local s
218 estack_pop eumask s || die "${FUNCNAME}: unbalanced push" 219 estack_pop eumask s || die "${FUNCNAME}: unbalanced push"
219 umask ${s} || die "${FUNCNAME}: sanity: could not restore umask: ${s}" 220 umask ${s} || die "${FUNCNAME}: sanity: could not restore umask: ${s}"
220} 221}
221 222
439 eqawarn " In the future this will cause a failure." 440 eqawarn " In the future this will cause a failure."
440 eqawarn "${rel_paths}" 441 eqawarn "${rel_paths}"
441 fi 442 fi
442 443
443 # Dynamically detect the correct -p# ... i'm lazy, so shoot me :/ 444 # Dynamically detect the correct -p# ... i'm lazy, so shoot me :/
445 local patch_cmd
444 while [[ ${count} -lt 5 ]] ; do 446 while [[ ${count} -lt 5 ]] ; do
447 patch_cmd="patch -p${count} ${EPATCH_OPTS}"
448
445 # Generate some useful debug info ... 449 # Generate some useful debug info ...
446 ( 450 (
447 _epatch_draw_line "***** ${patchname} *****" 451 _epatch_draw_line "***** ${patchname} *****"
448 echo 452 echo
449 echo "PATCH COMMAND: patch -p${count} ${EPATCH_OPTS} < '${PATCH_TARGET}'" 453 echo "PATCH COMMAND: ${patch_cmd} < '${PATCH_TARGET}'"
450 echo 454 echo
451 _epatch_draw_line "***** ${patchname} *****" 455 _epatch_draw_line "***** ${patchname} *****"
452 patch -p${count} ${EPATCH_OPTS} --dry-run -f < "${PATCH_TARGET}" 2>&1 456 ${patch_cmd} --dry-run -f < "${PATCH_TARGET}" 2>&1
453 ret=$? 457 ret=$?
454 echo 458 echo
455 echo "patch program exited with status ${ret}" 459 echo "patch program exited with status ${ret}"
456 exit ${ret} 460 exit ${ret}
457 ) >> "${STDERR_TARGET}" 461 ) >> "${STDERR_TARGET}"
461 _epatch_draw_line "***** ${patchname} *****" 465 _epatch_draw_line "***** ${patchname} *****"
462 echo 466 echo
463 echo "ACTUALLY APPLYING ${patchname} ..." 467 echo "ACTUALLY APPLYING ${patchname} ..."
464 echo 468 echo
465 _epatch_draw_line "***** ${patchname} *****" 469 _epatch_draw_line "***** ${patchname} *****"
466 patch -p${count} ${EPATCH_OPTS} < "${PATCH_TARGET}" 2>&1 470 ${patch_cmd} < "${PATCH_TARGET}" 2>&1
467 ret=$? 471 ret=$?
468 echo 472 echo
469 echo "patch program exited with status ${ret}" 473 echo "patch program exited with status ${ret}"
470 exit ${ret} 474 exit ${ret}
471 ) >> "${STDERR_TARGET}" 475 ) >> "${STDERR_TARGET}"
498 eerror " ${STDERR_TARGET}" 502 eerror " ${STDERR_TARGET}"
499 echo 503 echo
500 die "Failed Patch: ${patchname}!" 504 die "Failed Patch: ${patchname}!"
501 fi 505 fi
502 506
503 # if everything worked, delete the patch log 507 # if everything worked, delete the full debug patch log
504 rm -f "${STDERR_TARGET}" 508 rm -f "${STDERR_TARGET}"
509
510 # then log away the exact stuff for people to review later
511 cat <<-EOF >> "${T}/epatch.log"
512 PATCH: ${x}
513 CMD: ${patch_cmd}
514 PWD: ${PWD}
515
516 EOF
505 eend 0 517 eend 0
506 done 518 done
507 519
508 [[ ${SINGLE_PATCH} == "no" ]] && einfo "Done with patching" 520 [[ ${SINGLE_PATCH} == "no" ]] && einfo "Done with patching"
509 : # everything worked 521 : # everything worked
537# autotool input files as well. 549# autotool input files as well.
538epatch_user() { 550epatch_user() {
539 [[ $# -ne 0 ]] && die "epatch_user takes no options" 551 [[ $# -ne 0 ]] && die "epatch_user takes no options"
540 552
541 # Allow multiple calls to this function; ignore all but the first 553 # Allow multiple calls to this function; ignore all but the first
542 local applied="${T}/epatch_user.applied" 554 local applied="${T}/epatch_user.log"
543 [[ -e ${applied} ]] && return 2 555 [[ -e ${applied} ]] && return 2
544 556
545 # don't clobber any EPATCH vars that the parent might want 557 # don't clobber any EPATCH vars that the parent might want
546 local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches 558 local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches
547 for check in {${CATEGORY}/${PF},${CATEGORY}/${P},${CATEGORY}/${PN}}; do 559 for check in ${CATEGORY}/{${P}-${PR},${P},${PN}}; do
548 EPATCH_SOURCE=${base}/${CTARGET}/${check} 560 EPATCH_SOURCE=${base}/${CTARGET}/${check}
549 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${CHOST}/${check} 561 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${CHOST}/${check}
550 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${check} 562 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${check}
551 if [[ -d ${EPATCH_SOURCE} ]] ; then 563 if [[ -d ${EPATCH_SOURCE} ]] ; then
552 EPATCH_SOURCE=${EPATCH_SOURCE} \ 564 EPATCH_SOURCE=${EPATCH_SOURCE} \
940 # wrap the env here so that the 'insinto' call 952 # wrap the env here so that the 'insinto' call
941 # doesn't corrupt the env of the caller 953 # doesn't corrupt the env of the caller
942 insinto /usr/share/pixmaps 954 insinto /usr/share/pixmaps
943 newins "$@" 955 newins "$@"
944 ) 956 )
945}
946
947# for internal use only (unpack_pdv and unpack_makeself)
948find_unpackable_file() {
949 local src=$1
950 if [[ -z ${src} ]] ; then
951 src=${DISTDIR}/${A}
952 else
953 if [[ -e ${DISTDIR}/${src} ]] ; then
954 src=${DISTDIR}/${src}
955 elif [[ -e ${PWD}/${src} ]] ; then
956 src=${PWD}/${src}
957 elif [[ -e ${src} ]] ; then
958 src=${src}
959 fi
960 fi
961 [[ ! -e ${src} ]] && return 1
962 echo "${src}"
963}
964
965# @FUNCTION: unpack_pdv
966# @USAGE: <file to unpack> <size of off_t>
967# @DESCRIPTION:
968# Unpack those pesky pdv generated files ...
969# They're self-unpacking programs with the binary package stuffed in
970# the middle of the archive. Valve seems to use it a lot ... too bad
971# it seems to like to segfault a lot :(. So lets take it apart ourselves.
972#
973# You have to specify the off_t size ... I have no idea how to extract that
974# information out of the binary executable myself. Basically you pass in
975# the size of the off_t type (in bytes) on the machine that built the pdv
976# archive.
977#
978# One way to determine this is by running the following commands:
979#
980# @CODE
981# strings <pdv archive> | grep lseek
982# strace -elseek <pdv archive>
983# @CODE
984#
985# Basically look for the first lseek command (we do the strings/grep because
986# sometimes the function call is _llseek or something) and steal the 2nd
987# parameter. Here is an example:
988#
989# @CODE
990# vapier@vapier 0 pdv_unpack # strings hldsupdatetool.bin | grep lseek
991# lseek
992# vapier@vapier 0 pdv_unpack # strace -elseek ./hldsupdatetool.bin
993# lseek(3, -4, SEEK_END) = 2981250
994# @CODE
995#
996# Thus we would pass in the value of '4' as the second parameter.
997unpack_pdv() {
998 local src=$(find_unpackable_file "$1")
999 local sizeoff_t=$2
1000
1001 [[ -z ${src} ]] && die "Could not locate source for '$1'"
1002 [[ -z ${sizeoff_t} ]] && die "No idea what off_t size was used for this pdv :("
1003
1004 local shrtsrc=$(basename "${src}")
1005 echo ">>> Unpacking ${shrtsrc} to ${PWD}"
1006 local metaskip=$(tail -c ${sizeoff_t} "${src}" | hexdump -e \"%i\")
1007 local tailskip=$(tail -c $((${sizeoff_t}*2)) "${src}" | head -c ${sizeoff_t} | hexdump -e \"%i\")
1008
1009 # grab metadata for debug reasons
1010 local metafile=$(emktemp)
1011 tail -c +$((${metaskip}+1)) "${src}" > "${metafile}"
1012
1013 # rip out the final file name from the metadata
1014 local datafile=$(tail -c +$((${metaskip}+1)) "${src}" | strings | head -n 1)
1015 datafile=$(basename "${datafile}")
1016
1017 # now lets uncompress/untar the file if need be
1018 local tmpfile=$(emktemp)
1019 tail -c +$((${tailskip}+1)) ${src} 2>/dev/null | head -c 512 > ${tmpfile}
1020
1021 local iscompressed=$(file -b "${tmpfile}")
1022 if [[ ${iscompressed:0:8} == "compress" ]] ; then
1023 iscompressed=1
1024 mv ${tmpfile}{,.Z}
1025 gunzip ${tmpfile}
1026 else
1027 iscompressed=0
1028 fi
1029 local istar=$(file -b "${tmpfile}")
1030 if [[ ${istar:0:9} == "POSIX tar" ]] ; then
1031 istar=1
1032 else
1033 istar=0
1034 fi
1035
1036 #for some reason gzip dies with this ... dd cant provide buffer fast enough ?
1037 #dd if=${src} ibs=${metaskip} count=1 \
1038 # | dd ibs=${tailskip} skip=1 \
1039 # | gzip -dc \
1040 # > ${datafile}
1041 if [ ${iscompressed} -eq 1 ] ; then
1042 if [ ${istar} -eq 1 ] ; then
1043 tail -c +$((${tailskip}+1)) ${src} 2>/dev/null \
1044 | head -c $((${metaskip}-${tailskip})) \
1045 | tar -xzf -
1046 else
1047 tail -c +$((${tailskip}+1)) ${src} 2>/dev/null \
1048 | head -c $((${metaskip}-${tailskip})) \
1049 | gzip -dc \
1050 > ${datafile}
1051 fi
1052 else
1053 if [ ${istar} -eq 1 ] ; then
1054 tail -c +$((${tailskip}+1)) ${src} 2>/dev/null \
1055 | head -c $((${metaskip}-${tailskip})) \
1056 | tar --no-same-owner -xf -
1057 else
1058 tail -c +$((${tailskip}+1)) ${src} 2>/dev/null \
1059 | head -c $((${metaskip}-${tailskip})) \
1060 > ${datafile}
1061 fi
1062 fi
1063 true
1064 #[ -s "${datafile}" ] || die "failure unpacking pdv ('${metaskip}' '${tailskip}' '${datafile}')"
1065 #assert "failure unpacking pdv ('${metaskip}' '${tailskip}' '${datafile}')"
1066}
1067
1068# @FUNCTION: unpack_makeself
1069# @USAGE: [file to unpack] [offset] [tail|dd]
1070# @DESCRIPTION:
1071# Unpack those pesky makeself generated files ...
1072# They're shell scripts with the binary package tagged onto
1073# the end of the archive. Loki utilized the format as does
1074# many other game companies.
1075#
1076# If the file is not specified, then ${A} is used. If the
1077# offset is not specified then we will attempt to extract
1078# the proper offset from the script itself.
1079unpack_makeself() {
1080 local src_input=${1:-${A}}
1081 local src=$(find_unpackable_file "${src_input}")
1082 local skip=$2
1083 local exe=$3
1084
1085 [[ -z ${src} ]] && die "Could not locate source for '${src_input}'"
1086
1087 local shrtsrc=$(basename "${src}")
1088 echo ">>> Unpacking ${shrtsrc} to ${PWD}"
1089 if [[ -z ${skip} ]] ; then
1090 local ver=$(grep -m1 -a '#.*Makeself' "${src}" | awk '{print $NF}')
1091 local skip=0
1092 exe=tail
1093 case ${ver} in
1094 1.5.*|1.6.0-nv) # tested 1.5.{3,4,5} ... guessing 1.5.x series is same
1095 skip=$(grep -a ^skip= "${src}" | cut -d= -f2)
1096 ;;
1097 2.0|2.0.1)
1098 skip=$(grep -a ^$'\t'tail "${src}" | awk '{print $2}' | cut -b2-)
1099 ;;
1100 2.1.1)
1101 skip=$(grep -a ^offset= "${src}" | awk '{print $2}' | cut -b2-)
1102 (( skip++ ))
1103 ;;
1104 2.1.2)
1105 skip=$(grep -a ^offset= "${src}" | awk '{print $3}' | head -n 1)
1106 (( skip++ ))
1107 ;;
1108 2.1.3)
1109 skip=`grep -a ^offset= "${src}" | awk '{print $3}'`
1110 (( skip++ ))
1111 ;;
1112 2.1.4|2.1.5)
1113 skip=$(grep -a offset=.*head.*wc "${src}" | awk '{print $3}' | head -n 1)
1114 skip=$(head -n ${skip} "${src}" | wc -c)
1115 exe="dd"
1116 ;;
1117 *)
1118 eerror "I'm sorry, but I was unable to support the Makeself file."
1119 eerror "The version I detected was '${ver}'."
1120 eerror "Please file a bug about the file ${shrtsrc} at"
1121 eerror "http://bugs.gentoo.org/ so that support can be added."
1122 die "makeself version '${ver}' not supported"
1123 ;;
1124 esac
1125 debug-print "Detected Makeself version ${ver} ... using ${skip} as offset"
1126 fi
1127 case ${exe} in
1128 tail) exe="tail -n +${skip} '${src}'";;
1129 dd) exe="dd ibs=${skip} skip=1 if='${src}'";;
1130 *) die "makeself cant handle exe '${exe}'"
1131 esac
1132
1133 # lets grab the first few bytes of the file to figure out what kind of archive it is
1134 local filetype tmpfile=$(emktemp)
1135 eval ${exe} 2>/dev/null | head -c 512 > "${tmpfile}"
1136 filetype=$(file -b "${tmpfile}") || die
1137 case ${filetype} in
1138 *tar\ archive*)
1139 eval ${exe} | tar --no-same-owner -xf -
1140 ;;
1141 bzip2*)
1142 eval ${exe} | bzip2 -dc | tar --no-same-owner -xf -
1143 ;;
1144 gzip*)
1145 eval ${exe} | tar --no-same-owner -xzf -
1146 ;;
1147 compress*)
1148 eval ${exe} | gunzip | tar --no-same-owner -xf -
1149 ;;
1150 *)
1151 eerror "Unknown filetype \"${filetype}\" ?"
1152 false
1153 ;;
1154 esac
1155 assert "failure unpacking (${filetype}) makeself ${shrtsrc} ('${ver}' +${skip})"
1156} 957}
1157 958
1158# @FUNCTION: cdrom_get_cds 959# @FUNCTION: cdrom_get_cds
1159# @USAGE: <file on cd1> [file on cd2] [file on cd3] [...] 960# @USAGE: <file on cd1> [file on cd2] [file on cd3] [...]
1160# @DESCRIPTION: 961# @DESCRIPTION:

Legend:
Removed from v.1.377  
changed lines
  Added in v.1.383

  ViewVC Help
Powered by ViewVC 1.1.20