Index: Scripts/check-stagedir.sh =================================================================== --- Scripts/check-stagedir.sh (revision 395246) +++ Scripts/check-stagedir.sh (working copy) @@ -70,7 +70,7 @@ done | sort -n | cut -d ' ' -f2- } -# Prepare sed(1) regex for PLIST_SUB_SED/PORTEXAMPLES/OPTIONS/... +# Prepare sed(1) regex for PLIST_SUB_CO/PORTEXAMPLES/OPTIONS/... setup_plist_seds() { ### HANDLE PORTDOCS/PORTEXAMPLES sed_portdocsexamples="/%%DOCSDIR%%/s!^!%%PORTDOCS%%!g; /%%EXAMPLESDIR%%/s!^!%%PORTEXAMPLES%%!g;" @@ -89,18 +89,17 @@ unset PORT_OPTIONS fi - sed_plist_sub=$(echo "${PLIST_SUB_SED}" | /bin/sh ${SCRIPTSDIR}/plist_sub_sed_sort.sh) - unset PLIST_SUB_SED + plist_sub="awk -v sorted=1 -f ${SCRIPTSDIR}/str_replace.awk ${PLIST_SUB_CO}" # Used for generate_plist - sed_files_gen="s!^${PREFIX}/!!g; ${sed_plist_sub} \ + sed_files_gen="s!^${PREFIX}/!!g; \ ${sed_portdocsexamples} /^share\/licenses/d;" - sed_dirs_gen="s!^${PREFIX}/!!g; ${sed_plist_sub} s,^,@dir ,; \ + sed_dirs_gen="s!^${PREFIX}/!!g; s,^,@dir ,; \ ${sed_portdocsexamples} \ /^@dir share\/licenses/d;" # These prevent ignoring DOCS/EXAMPLES dirs with sed_portdocsexamples - sed_files="s!^${PREFIX}/!!g; ${sed_plist_sub} /^share\/licenses/d;" - sed_dirs="s!^${PREFIX}/!!g; ${sed_plist_sub} s,^,@dir ,; \ + sed_files="s!^${PREFIX}/!!g; /^share\/licenses/d;" + sed_dirs="s!^${PREFIX}/!!g; s,^,@dir ,; \ /^@dir share\/licenses/d;" } @@ -113,7 +112,7 @@ find ${STAGEDIR} -type f -o -type l | sort | \ sed -e "s,${STAGEDIR},," >${WRKDIR}/.staged-files comm -13 ${WRKDIR}/.plist-files ${WRKDIR}/.staged-files | \ - sed -e "${sed_files_gen}" \ + sed -e "${sed_files_gen}" | ${plist_sub} \ >>${WRKDIR}/.staged-plist || : ### HANDLE DIRS @@ -130,7 +129,7 @@ >${WRKDIR}/.staged-dirs-dfs-sorted # Find all staged dirs and then sort them by depth-first (find -ds) comm -13 ${WRKDIR}/.traced-dirs ${WRKDIR}/.staged-dirs-sorted \ - | sort_dfs | sed "${sed_dirs_gen}" \ + | sort_dfs | sed "${sed_dirs_gen}" | ${plist_sub} \ >>${WRKDIR}/.staged-plist || : } @@ -184,7 +183,7 @@ echo "===> Checking for items in pkg-plist which are not in STAGEDIR" : >${WRKDIR}/.invalid-plist-missing comm -23 ${WRKDIR}/.plist-files-no-comments ${WRKDIR}/.staged-files | \ - sed -e "${sed_files}" \ + sed -e "${sed_files}" | ${plist_sub} \ >>${WRKDIR}/.invalid-plist-missing || : # Look for directories, then sort them by DFS. Must create the dirs @@ -202,7 +201,7 @@ sed -e "s,^${WRKDIR}/.missing-dirs,," | \ while read dir; do \ grep -x "${dir}" ${WRKDIR}/.missing-plist-dirs || :; done | \ - sed "${sed_dirs}" \ + sed "${sed_dirs}" | ${plist_sub} \ >>${WRKDIR}/.invalid-plist-missing || : rm -rf ${WRKDIR}/.missing-dirs if [ -s "${WRKDIR}/.invalid-plist-missing" ]; then @@ -225,7 +224,7 @@ # validate environment validate_env STAGEDIR PREFIX LOCALBASE WRKDIR WRKSRC MTREE_FILE \ - TMPPLIST PLIST_SUB_SED SCRIPTSDIR PORT_OPTIONS NO_PREFIX_RMDIR + TMPPLIST PLIST_SUB_CO SCRIPTSDIR PORT_OPTIONS NO_PREFIX_RMDIR set -u Index: Scripts/check_leftovers.sh =================================================================== --- Scripts/check_leftovers.sh (revision 395246) +++ Scripts/check_leftovers.sh (working copy) @@ -20,7 +20,7 @@ # same -/+/M format, but with files substituted, without approved # whitelisted files, and hides any directories already in plist. # -# The PLIST_SUB feature can be disabled by setting PLIST_SUB_SED= +# The PLIST_SUB feature can be disabled by setting PLIST_SUB_CO= # in environment. origin="$1" @@ -41,7 +41,7 @@ LOCALBASE=$(make -C ${portdir} -VLOCALBASE) fi homedirs=$(awk -F: -v users=$(make -C ${portdir} -V USERS|sed -e 's, ,|,g;/^$/d;s,^,^(,;s,$,)$,') 'users && $1 ~ users {print $9}' ${PORTSDIR}/UIDs|sort -u|sed -e "s|/usr/local|${PREFIX}|"|tr "\n" " ") -plistsub_sed=$(make -C ${portdir} -VPLIST_SUB_SED | /bin/sh ${PORTSDIR}/Mk/Scripts/plist_sub_sed_sort.sh) +plist_sub_co=$(make -C ${portdir} -VPLIST_SUB_CO) tmpplist=$(make -C ${portdir} -VTMPPLIST) while read modtype path extra; do @@ -64,7 +64,7 @@ esac ignore_path=0 - sub_path=$(echo "$path" | sed -e "s|^${PREFIX}/||" -e "${plistsub_sed}") + sub_path=$(echo "$path" | sed "s|${PREFIX}/||g" | awk -v sorted=1 -f ${PORTSDIR}/Mk/Scripts/str_replace.awk ${plist_sub_co}) orig_sub_path="${sub_path}" # If this is a directory, use @dir in output is_dir=0 Index: Scripts/str_replace.awk =================================================================== --- Scripts/str_replace.awk (revision 0) +++ Scripts/str_replace.awk (working copy) @@ -0,0 +1,119 @@ +# Taken from https://github.com/e36freak/awk-libs and modified to only fit our +# needs + +# Copyright Daniel Mills +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. + + +function __quicksort(array, left, right, piv, mid, tmp) { + # return if array contains one element or less + if ((right - left) <= 0) { + return; + } + + # choose random pivot + piv = int(rand() * (right - left + 1)) + left; + + # swap left and pivot + tmp = array[piv]; + array[piv] = array[left]; + array[left] = tmp; + + mid = left; + # iterate over each element from the second to the last, and compare + for (piv=left+1; piv<=right; piv++) { + if (length(array[piv]) < length(array[left])) { + # increment mid + mid++; + + # swap mid and pivot + tmp = array[piv]; + array[piv] = array[mid]; + array[mid] = tmp; + } + } + + # swap left and mid + tmp = array[mid]; + array[mid] = array[left]; + array[left] = tmp; + + # recursively sort the two halves + __quicksort(array, left, mid - 1); + __quicksort(array, mid + 1, right); +} + + +function qsorti(array, out, count, i) { + # loop over each index, and generate a new array with the original indices + # mapped to new numeric ones + count = 0; + for (i in array) { + out[++count] = i; + } + + # seed the random number generator + srand(); + + # actually sort + __quicksort(out, 1, count); +} +# end of awk libs + +BEGIN { + for (i = 1; i < ARGC; i++) { + if (index(ARGV[i], "=") > 1) { + key="%%"ARGV[i] + value=ARGV[i] + gsub(/=.*/, "%%", key) + gsub(/^[^=]+=/, "", value) + if (sorted) { + replace[value]=key + } else { + replace[key]=value + } + } + } + count=0 + if (sorted) { + qsorti(replace, search) + } else { + # while not needed it simplify the rest of the code to only + # use the "search" array + for (a in replace) search[count++] = a + } +} +{ + for (i in search) { + find = search[i] + if (index($0, find)) { + start = 1 + line = $0 + newline = "" + while (i=index(line, find)) { + newline = newline substr(line, 1, i-1) replace[find] + start += i + length(find) - 1 + line = substr($0, start) + } + $0 = newline line + } + } + print +} Property changes on: Scripts/str_replace.awk ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: bsd.port.mk =================================================================== --- bsd.port.mk (revision 395246) +++ bsd.port.mk (working copy) @@ -1512,7 +1512,7 @@ MTREE_FILE=${MTREE_FILE} \ TMPPLIST=${TMPPLIST} \ SCRIPTSDIR=${SCRIPTSDIR} \ - PLIST_SUB_SED="${PLIST_SUB_SED}" \ + PLIST_SUB_CO="${PLIST_SUB_CO}" \ PORT_OPTIONS="${PORT_OPTIONS}" \ PORTSDIR="${PORTSDIR}" @@ -1555,8 +1555,7 @@ # Remove @comment values # Remove quotes # Replace . with \. for later sed(1) usage -PLIST_SUB_SED_MIN?= 2 -PLIST_SUB_SED?= ${PLIST_SUB:C/.*=.{1,${PLIST_SUB_SED_MIN}}$//g:NEXTRACT_SUFX=*:NOSREL=*:NLIB32DIR=*:NPREFIX=*:NLOCALBASE=*:NRESETPREFIX=*:N*="":N*="@comment*:C/([^=]*)="?([^"]*)"?/s!\2!%%\1%%!g;/g:C/\./\\./g} +PLIST_SUB_CO?= ${PLIST_SUB:NEXTRACT_SUFX=*:NOSREL=*:NLIB32DIR=*:NPREFIX=*:NLOCALBASE=*:NRESETPREFIX=*:N*="":N*="@comment*} # kludge to strip trailing whitespace from CFLAGS; # sub-configure will not # survive double space @@ -4716,7 +4715,6 @@ .endif .endif -_SUB_LIST_TEMP= ${SUB_LIST:S/$/!g/:S/^/ -e s!%%/:S/=/%%!/} .if !target(apply-slist) apply-slist: .if defined(SUB_FILES) @@ -4724,7 +4722,7 @@ .if !exists(${FILESDIR}/${file}.in) @${ECHO_MSG} "** Missing ${FILESDIR}/${file}.in for ${PKGNAME}."; exit 1 .else - @${SED} ${_SUB_LIST_TEMP} -e '/^@comment /d' ${FILESDIR}/${file}.in > ${WRKDIR}/${file} + @${AWK} -f ${SCRIPTSDIR}/str_replace.awk ${SUB_LIST} ${FILESDIR}/${file}.in > ${WRKDIR}/${file} .endif .endfor .for i in pkg-message pkg-install pkg-deinstall pkg-req @@ -4745,15 +4743,15 @@ @if [ ! -f ${DESCR} ]; then ${ECHO_MSG} "** Missing pkg-descr for ${PKGNAME}."; exit 1; fi @>${TMPPLIST} @for file in ${PLIST_FILES}; do \ - ${ECHO_CMD} $${file} | ${SED} ${PLIST_SUB:S/$/!g/:S/^/ -e s!%%/:S/=/%%!/} >> ${TMPPLIST}; \ - done + ${ECHO_CMD} $${file} ; \ + done | ${AWK} -f ${SCRIPTSDIR}/str_replace.awk ${PLIST_SUB} >> ${TMPPLIST} @if [ -f ${PLIST} ]; then \ - ${SED} ${PLIST_SUB:S/$/!g/:S/^/ -e s!%%/:S/=/%%!/} ${PLIST} >> ${TMPPLIST}; \ + ${AWK} -f ${SCRIPTSDIR}/str_replace.awk ${PLIST_SUB} ${PLIST} >> ${TMPPLIST}; \ fi # Keep PLIST_DIRSTRY as compatibility .for dir in ${PLIST_DIRS} ${PLIST_DIRSTRY} - @${ECHO_CMD} ${dir} | ${SED} ${PLIST_SUB:S/$/!g/:S/^/ -e s!%%/:S/=/%%!/} -e 's,^,@dir ,' >> ${TMPPLIST} + @${ECHO_CMD} "@dir ${dir}" | ${AWK} -f ${SCRIPTSDIR}/str_replace.awk ${PLIST_SUB} >> ${TMPPLIST} .endfor .if defined(USE_LINUX_PREFIX)