Implement controllable compression and docompress, bug #273633.
authorUlrich Mueller <ulm@gentoo.org>
Sat, 28 Aug 2010 07:20:23 +0000 (09:20 +0200)
committerZac Medico <zmedico@gentoo.org>
Sat, 28 Aug 2010 23:12:11 +0000 (16:12 -0700)
bin/ebuild-helpers/dodoc
bin/ebuild-helpers/ecompressdir
bin/ebuild-helpers/prepalldocs
bin/ebuild-helpers/prepallman
bin/ebuild-helpers/prepinfo
bin/ebuild-helpers/prepman
bin/ebuild.sh
bin/isolated-functions.sh
bin/misc-functions.sh

index 29b69011260dc7c376857913b8db6b8d0008eb95..99410ea85985560c307a1ec0b0097acfbe74bd01 100755 (executable)
@@ -18,7 +18,7 @@ ret=0
 for x in "$@" ; do
        if [ -s "${x}" ] ; then
                install -m0644 "${x}" "${dir}"
-               ecompress --queue "${dir}/${x##*/}"
+               hasq "${EAPI}" 0 1 2 3 && ecompress --queue "${dir}/${x##*/}"
        elif [ ! -e "${x}" ] ; then
                echo "!!! ${0##*/}: $x does not exist" 1>&2
                ((ret|=1))
index 90c26f9d5084951390fbb8b871ae1b40aeb52ea1..acdb1cd7f135053de9a94c690af4da3eeca5c337 100755 (executable)
@@ -13,7 +13,8 @@ case $1 in
        --ignore)
                shift
                for skip in "$@" ; do
-                       [[ -d ${D}${skip} ]] && touch "${D}${skip}.ecompress.skip"
+                       [[ -d ${D}${skip} || -f ${D}${skip} ]] \
+                               && touch "${D}${skip}.ecompress.skip"
                done
                exit 0
                ;;
@@ -74,7 +75,7 @@ funk_up_dir() {
 }
 
 # _relocate_skip_dirs(srctree, dsttree)
-# Move all the directories we want to skip running compression
+# Move all files and directories we want to skip running compression
 # on from srctree to dsttree.
 _relocate_skip_dirs() {
        local srctree="$1" dsttree="$2"
index 6705f5e791ccd50d32c2d41ade005d5e07e2bb1b..f7026c6796fe229877e61d382e7291a047e1e4dc 100755 (executable)
@@ -4,6 +4,11 @@
 
 source "${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"/isolated-functions.sh
 
+if ! hasq "${EAPI}" 0 1 2 3; then
+       eqawarn "QA Notice: Deprecated call to 'prepalldocs'"
+       exit 0
+fi
+
 if [[ -n $1 ]] ; then
        vecho "${0##*/}: invalid usage; takes no arguments" 1>&2
 fi
index f41bcb81677116068b23e6fe91718bfa85a5c9e1..71b79a0ef5f4d4baa7312817bee8575aba2b1ddc 100755 (executable)
@@ -4,6 +4,9 @@
 
 source "${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"/isolated-functions.sh
 
+# replaced by controllable compression in EAPI 4
+hasq "${EAPI}" 0 1 2 3 || exit 0
+
 ret=0
 
 find "${D}" -type d -name man > "${T}"/prepallman.filelist
index 1d8c7d1f0311e120877303fbebe5444477b9e7a0..cb39ab86c98606e890396c1051de78fe17163245 100755 (executable)
@@ -27,4 +27,5 @@ find "${D}${infodir}" -type d -print0 | while read -d $'\0' x ; do
        rm -f "${x}"/dir{,.info}{,.gz,.bz2}
 done
 
+hasq "${EAPI}" 0 1 2 3 || exit 0
 exec ecompressdir --queue "${infodir}"
index cfbcdd41a8da3a32eafa6c14905b32b15da72e0c..97f2fbf7e725a9a847709e4a3197ddb7cc628411 100755 (executable)
@@ -15,6 +15,9 @@ if [[ ! -d ${mandir} ]] ; then
        exit 0
 fi
 
+# replaced by controllable compression in EAPI 4
+hasq "${EAPI}" 0 1 2 3 || exit 0
+
 shopt -s nullglob
 
 really_is_mandir=0
index b2ac5b419174bc0296da87ce91900d396b309795..393c82ebdf252681195d48f3f4280e68e7eae1cd 100755 (executable)
@@ -303,6 +303,8 @@ export EXEOPTIONS="-m0755"
 export LIBOPTIONS="-m0644"
 export DIROPTIONS="-m0755"
 export MOPREFIX=${PN}
+declare -a PORTAGE_DOCOMPRESS=( /usr/share/{doc,info,man} )
+declare -a PORTAGE_DOCOMPRESS_SKIP=( /usr/share/doc/${PF}/html )
 
 # adds ".keep" files so that dirs aren't auto-cleaned
 keepdir() {
@@ -860,6 +862,32 @@ libopts() {
        hasq -s ${LIBOPTIONS} && die "Never call libopts() with -s"
 }
 
+docompress() {
+       hasq "${EAPI}" 0 1 2 3 && die "'docompress' not supported in this EAPI"
+
+       local f g
+       if [[ $1 = "-x" ]]; then
+               shift
+               for f; do
+                       f=$(strip_duplicate_slashes "${f}"); f=${f%/}
+                       [[ ${f:0:1} = / ]] || f="/${f}"
+                       for g in "${PORTAGE_DOCOMPRESS_SKIP[@]}"; do
+                               [[ ${f} = ${g} ]] && continue 2
+                       done
+                       PORTAGE_DOCOMPRESS_SKIP[${#PORTAGE_DOCOMPRESS_SKIP[@]}]=${f}
+               done
+       else
+               for f; do
+                       f=$(strip_duplicate_slashes "${f}"); f=${f%/}
+                       [[ ${f:0:1} = / ]] || f="/${f}"
+                       for g in "${PORTAGE_DOCOMPRESS[@]}"; do
+                               [[ ${f} = ${g} ]] && continue 2
+                       done
+                       PORTAGE_DOCOMPRESS[${#PORTAGE_DOCOMPRESS[@]}]=${f}
+               done
+       fi
+}
+
 abort_handler() {
        local msg
        if [ "$2" != "fail" ]; then
index 3df18b53c31b9c7c98570004f1ffcc979ec3d07b..cd1039b07e6636eac9dd3864bab0c718562d85c6 100644 (file)
@@ -572,7 +572,7 @@ save_ebuild_env() {
                        best_version use_with use_enable register_die_hook \
                        keepdir unpack strip_duplicate_slashes econf einstall \
                        dyn_setup dyn_unpack dyn_clean into insinto exeinto docinto \
-                       insopts diropts exeopts libopts \
+                       insopts diropts exeopts libopts docompress \
                        abort_handler abort_prepare abort_configure abort_compile \
                        abort_test abort_install dyn_prepare dyn_configure \
                        dyn_compile dyn_test dyn_install \
index d8754cd3aef15edf46df562a06b1db30906747ba..50799976c254a61841ab1062a3e95e0fd5a1a3dc 100755 (executable)
@@ -40,6 +40,102 @@ install_symlink_html_docs() {
        fi
 }
 
+# similar to readlink -f, but only expands symlinks up to the last
+# directory component of the path
+canonicalise_dir() {
+       local ret wd=$(pwd)
+       if [[ -d $1 ]]; then
+               cd -P "$1" 2>/dev/null && pwd -P
+               ret=$?
+       else
+               cd -P "${1%"${1##*/}"}" 2>/dev/null && echo "$(pwd -P)/${1##*/}"
+               ret=$?
+       fi
+       cd "${wd}"
+       return ${ret}
+}
+
+prepcompress() {
+       local -a include exclude incl_d incl_f
+       local f g i real_f real_d
+
+       # Canonicalise path names and check for their existence.
+       real_d=$(canonicalise_dir "${D}")
+       for (( i = 0; i < ${#PORTAGE_DOCOMPRESS[@]}; i++ )); do
+               real_f=$(canonicalise_dir "${D}${PORTAGE_DOCOMPRESS[i]}")
+               f=${real_f#"${real_d}"}
+               if [[ ${real_f} != "${f}" ]] && [[ -d ${real_f} || -f ${real_f} ]]
+               then
+                       include[${#include[@]}]=${f:-/}
+               elif [[ ${i} -ge 3 ]]; then
+                       ewarn "prepcompress:" \
+                               "ignoring nonexistent path '${PORTAGE_DOCOMPRESS[i]}'"
+               fi
+       done
+       for (( i = 0; i < ${#PORTAGE_DOCOMPRESS_SKIP[@]}; i++ )); do
+               real_f=$(canonicalise_dir "${D}${PORTAGE_DOCOMPRESS_SKIP[i]}")
+               f=${real_f#"${real_d}"}
+               if [[ ${real_f} != "${f}" ]] && [[ -d ${real_f} || -f ${real_f} ]]
+               then
+                       exclude[${#exclude[@]}]=${f:-/}
+               elif [[ ${i} -ge 1 ]]; then
+                       ewarn "prepcompress:" \
+                               "ignoring nonexistent path '${PORTAGE_DOCOMPRESS_SKIP[i]}'"
+               fi
+       done
+
+       # Remove redundant entries from lists.
+       # For the include list, remove any entries that are
+       # contained in a directory in the include or exclude lists.
+       for (( i = ${#include[@]} - 1; i >= 0; i-- )); do
+               f=${include[i]}
+               for g in "${include[@]}"; do
+                       if [[ ${f} == "${g%/}"/* ]]; then
+                               unset include[i]
+                               continue 2
+                       fi
+               done
+               for g in "${exclude[@]}"; do
+                       if [[ ${f} = ${g} || ${f} == "${g%/}"/* ]]; then
+                               unset include[i]
+                               continue 2
+                       fi
+               done
+       done
+       # For the exclude list, remove any entries that are:
+       # a) contained in a directory in the exclude list, or
+       # b) _not_ contained in a directory in the include list.
+       for (( i = ${#exclude[@]} - 1; i >= 0; i-- )); do
+               f=${exclude[i]}
+               for g in "${exclude[@]}"; do
+                       if [[ ${f} == "${g%/}"/* ]]; then
+                               unset exclude[i]
+                               continue 2
+                       fi
+               done
+               for g in "${include[@]}"; do
+                       [[ ${f} == "${g%/}"/* ]] && continue 2
+               done
+               unset exclude[i]
+       done
+
+       # Split the include list into directories and files
+       for f in "${include[@]}"; do
+               if [[ -d ${D}${f} ]]; then
+                       incl_d[${#incl_d[@]}]=${f}
+               else
+                       incl_f[${#incl_f[@]}]=${f}
+               fi
+       done
+
+       # Queue up for compression.
+       # ecompress{,dir} doesn't like to be called with empty argument lists.
+       [[ ${#incl_d[@]} -gt 0 ]] && ecompressdir --queue "${incl_d[@]}"
+       [[ ${#incl_f[@]} -gt 0 ]] && ecompress --queue "${incl_f[@]/#/${D}}"
+       [[ ${#exclude[@]} -gt 0 ]] && ecompressdir --ignore "${exclude[@]}"
+       return 0
+}
+
 install_qa_check() {
        local f
 
@@ -47,6 +143,7 @@ install_qa_check() {
 
        export STRIP_MASK
        prepall
+       hasq "${EAPI}" 0 1 2 3 || prepcompress
        ecompressdir --dequeue
        ecompress --dequeue