On Fri, 20 May 2011 17:39:22 +0200
Jeroen Roovers <j...@gentoo.org> wrote:

> for a while now I've been wondering if all those sed scripts in all
> those ebuilds are really effective.

This took rather long to find some spare time for.

Plonk the attached bash script into /etc/portage/bashrc.d (which you
source in /etc/portage/bashrc or something) and you should probably be
on your merry way.

The script probably doesn't catch all cases, but sed use in most
ebuilds is pretty standard.


     jer
#!/bin/bash
SED=$(type -P sed)

sed() {
        case ${FUNCNAME[1]} in
                # we only care about direct calls in some ebuild phases
                src_prepare|src_configure|src_compile|src_install)
                        local arg args file files scripts
                        while [[ $# -gt 0 ]]; do
                                arg="${1}"
                                if [ -f "${arg}" ]; then
                                        files+=" ${arg}"
                                else
                                        case ${arg} in
                                                -e) : ;;
                                                --expression=*) scripts+=( 
"${arg/--expression=}" ) ;;
                                                -i*|--in-place=*) : ;;
                                                -f)
                                                        local 
scriptfile="${arg}"
                                                        shift
                                                        scriptfile+=" ${arg}"
                                                        scripts+=( 
"${scriptfile}" )
                                                ;;
                                                --file=*) scripts+=( 
"${arg/--file=}" ) ;;
                                                -*) args+=" ${arg}" ;;
                                                *) scripts+=( "${arg}" ) ;;
                                        esac
                                fi
                                shift
                        done

                        for file in ${files}; do
                                for idx in ${!scripts[@]}; do
                                        ${SED} ${args} -e 
"${scripts[@]:${idx}:1}" ${file} > ${file}.jer-qa-sed
                                        if cmp -s ${file}{,.jer-qa-sed}; then
                                                echo -e "\033[01;33m!!! JeR-QA: 
sed expression "${scripts[@]:${idx}:1}" did not change ${file}\033[00;00m" \
                                                        | tee -a ${T}/sed.log > 
/dev/stderr
                                        else
                                                mv ${file}{.jer-qa-sed,}
                                        fi
                                done
                        done
                ;;
                *) ${SED} "${@}"
                ;;
                esac
}

Reply via email to