Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 22 Nov 2015 11:41:33 -0500
From:      Ricky G <ricky1252@hotmail.com>
Cc:        "freebsd-testing@freebsd.org" <freebsd-testing@freebsd.org>, "freebsd-ports@freebsd.org" <freebsd-ports@freebsd.org>
Subject:   RE: Call for Help: need script for patching ports tree, building with poudriere
Message-ID:  <SNT146-W266F25359A8C2F8F92F021A1180@phx.gbl>
In-Reply-To: <SNT146-W4271A2597FBC1A75A972A6A11A0@phx.gbl>
References:  <CAG=rPVcOb4g9DD08c7vAsor8UMf3GnckAJ2wkO37p8Ao3G2GwA@mail.gmail.com>, , <SNT146-W8224851E20D3E1FDA17AD4A1150@phx.gbl>, , <CAG=rPVfZV4kZbhG5c-%2BrjFG4vGTzMmrRasSyBQ%2BgCtY8FBEtoA@mail.gmail.com>, , <SNT146-W629FAF58F79486179755FEA1100@phx.gbl>, , <564EDE98.9070508@toco-domains.de>, <SNT146-W4271A2597FBC1A75A972A6A11A0@phx.gbl>

index | next in thread | previous in thread | raw e-mail

[-- Attachment #1 --]
Portest version 0.0.2 
Changelog:
* Fixed Usage with incorrect description on some options* Added multiple patchfile/glob support* More failed patch output, Still working on formating. Ideas would be great.* Changed BUILT_LIST filter to fix unintended stripping of multiple ports* Changed revert (-R) to (-r) and added a new revert (-R) method.* Several changed to revert more explained below

 As pointed out to me, svn revert -R seems to somehow miss small filenames. This is an svn bug and as a workaround I decided to remove the -r option as it was unreliable altogether, move the -R to -r, and added a filtered revert for the smaller filenames. This solution works well on all my tests with 15+ large diff files, but of course more testing is needed. The new -R option will instead of reverting according to the diff, revert based on changed from the tree. This method is much slower but in the event -r may fail an -R will fix everything regardless of .diff. 		 	   		  
[-- Attachment #2 --]
#!/bin/sh
#
# Copyright (c) 2015, Ricky Gallamore <ultima1252@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
#    must display the following acknowledgement:
#    This product includes software developed by the <organization>.
# 4. Neither the name of the <organization> nor the
#    names of its contributors may be used to endorse or promote products
#    derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ''AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

PORTEST_VERSION="0.0.2"

usage() {
	cat << EOF
Usage: portest [-f bulkfile] [-apPrRtTv] file.diff file2.diff ...

Options:
    -a     --  Do everything except revert (-ptf build.ports.txt)
    -f     --  Generate a poudiere usable bulk file
    -p     --  Patch, will exit on fail with output
    -P     --  Patch, do not exit on failed patch
    -r     --  Revert the files listed in patchfile, fast and
               should be all thats required
    -R     --  Revert modifications according tree, slow but
               will guarantee tree integrity
    -t     --  Test with portlint
    -T     --  Test with port test, or poudriere depending on
               USE_POUDRIERE
    -v     --  Show version of portest

By default, (no options) portest does nothing
EOF
	exit 1
}

while getopts ":af:pPrRtTv" FLAG; do
	case "${FLAG}" in
	a)
		ALL="YES"
		;;
	f)
		POUDRIERE_BULK="YES"
		POUDRIERE_BULK_FILE="${OPTARG}"
		;;
	p)
		PATCH="YES"
		;;
	P)
		PATCH_FAILED_EXIT="NO"
		;;
	r)
		REVERT_SOFT="YES"
		;;
	R)
		REVERT_HARD="YES"
		;;
	t)
		TEST_PORTLINT="YES"
		;;
	T)
		TEST_BUILD="YES"
		;;
	v)
		echo "${PORTEST_VERSION}"
		exit 0
	esac
done

shift "$((OPTIND-1))"

[ $# -lt 1 ] && usage


SVN="svnlite"
SVN_PATCH_ARGS="patch"
SVN_REVERT_ARGS="revert -R"
PORTLINT="portlint"
PORTLINT_ARGS="-A"
PORT="port"
PORT_ARGS="test"
PORTSDIR="/usr/ports"
BULK_FILE="build.ports.txt"

USE_POUDRIERE="YES"
POUDRIERE_JAILS="102amd64 102i386 93amd64 93i386"
POUDRIERE_PORTSDIR="/usr/local/poudriere/ports"
POUDRIERE_PORT="test"
POUDRIERE="poudriere"
POUDRIERE_ARGS="bulk -t -C -p ${POUDRIERE_PORT}"

# Set poudriere ports dir if being used #
if [ "${USE_POUDRIERE}" == "YES" ]; then
PORTSDIR="${POUDRIERE_PORTSDIR}/${POUDRIERE_PORT}"
fi


CURDIR="`pwd`"

# Check PORTSDIR #
if [ -d "${PORTSDIR}" ]; then
else
	echo "PORTSDIR not set or incorrect directory"
	exit 1
fi
if [ "head/Makefile" != "`head -1 "${PORTSDIR}/Makefile" | grep -o head/Makefile`" ]; then
	echo "PORTSDIR is set to an incorrect directory"
	exit 1
fi

# Check PORTSDIR is an svn tree #
cd ${PORTSDIR}
${SVN} info >/dev/null 2>&1
[ $? -eq 1 ] && echo "PORTSDIR is not an svn tree" && exit 1

# Set patchfile path #
cd "${PORTSDIR}"
for file in $@; do
	if [ -f "$file" ]; then
		PATCH_FILE="${PATCH_FILE} $file"
	elif [ -f "${CURDIR}/$file" ]; then
		PATCH_FILE="${PATCH_FILE} ${CURDIR}/$file"
	else
		echo "$file not found"
		exit 1
	fi
done

### Patch Tree ###
if [ "${PATCH}" == "YES" ] || [ "${PATCH_FAILED_EXIT}" == "NO" ] || [ "${ALL}" == "YES" ]; then
	for file in ${PATCH_FILE}; do
		SVN_OUTPUT="${SVN_OUTPUT}
"`${SVN} ${SVN_PATCH_ARGS} "$file"`
		done
	if [ $? -ne 0 ] && [ "${PATCH_FAILED_EXIT}" != "NO" ] || [ "`echo "${SVN_OUTPUT}" | grep -m 1 -o rejected`" == "rejected" ] && [ "${PATCH_FAILED_EXIT}" != "NO" ]; then
		for file in `echo "${SVN_OUTPUT}" | grep -B 1 "rejected" | grep -v ">" | awk '{ print $2 }'`; do
			echo "${SVN_OUTPUT}" | grep -A 1 "$file"
			cat "${PORTSDIR}/$file.svnpatch.rej"
		done
		echo "${SVN_OUTPUT}"
		echo "Patch Failed"
		exit 1
	else
		for file in `echo "${SVN_OUTPUT}" | grep -B 1 "rejected" | grep -v ">" | awk '{ print $2 }'`; do
			echo "${SVN_OUTPUT}" | grep -A 1 "$file"
			cat "${PORTSDIR}/$file.svnpatch.rej"
		done
		echo "${SVN_OUTPUT}"
	fi
fi

# Generate a list of ports for poudriere to build #
BUILD_LIST="`(cat ${PATCH_FILE} | grep '^Index:[ ].*' | sed 's/^Index: // ; s/^[MTK].*//' | grep -o '^.*\/.*\/' | sed 's/^.*\/.*\/files\/$// ; s/\/$//' | sort | awk '!a[$0]++')`"

### Bulk File ###
cd ${CURDIR}
if [ "$POUDRIERE_BULK" == "YES" ]; then
echo "${BUILD_LIST}" >"${POUDRIERE_BULK_FILE}"
elif [ "${ALL}" == "YES" ]; then
echo "${BUILD_LIST}" >"${BULK_FILE}"
fi

### Portlint ###
if [ "${TEST_PORTLINT}" == "YES" ] || [ "${ALL}" == "YES" ]; then
	for port in ${BUILD_LIST}; do
		cd "${PORTSDIR}/$port"
		echo "$port"
		${PORTLINT} ${PORTLINT_ARGS}
	done
fi

### Port test and Poudriere testing ###
if [ "${TEST_BUILD}" == "YES" ] && [ "${USE_POUDRIERE}" == "NO" ]; then
	rm -rf "`find ${PORTSDIR} -type directory -name "work" -maxdepth 3`"
	for port in ${BUILD_LIST}; do
		cd "${PORTSDIR}/$port"
		make depends BATCH=yes
		${PORT} ${PORT_ARGS}
	done
elif [ "${TEST_BUILD}" == "YES" ] && [ "${USE_POUDRIERE}" == "YES" ]; then
	for jail in ${POUDRIERE_JAILS}; do
		${POUDRIERE} ${POUDRIERE_ARGS} -j $jail ${BUILD_LIST}
	done
fi

### Revert Patch ###
cd ${PORTSDIR}
if [ "${REVERT_SOFT}" == "YES" ] && [ "${REVERT_HARD}" != "YES" ]; then
# Generate a list of files that were patched #
	PATCH_FILES_LIST="`cat ${PATCH_FILE} | grep '^Index:[ ].*' | awk '{ print $2 }' | sort`"
# Wierd cases where svn won't see short filenames in list.    #
# This seems to be an svn bug, this list helps in those cases #
	PATCH_FILES_FILTERED=`echo "${PATCH_FILES_LIST}" | grep -v '^[a-z].*\/.*\/.*'`
	for file in ${BUILD_LIST}; do
		rm -rf "${PORTSDIR}/$file"
	done
	for file in ${PATCH_FILES_LIST}; do
		rm -rf "${PORTSDIR}/$file"
	done
	${SVN} ${SVN_REVERT_ARGS} ${BUILD_LIST}
	${SVN} ${SVN_REVERT_ARGS} ${PATCH_FILES_LIST}
	${SVN} ${SVN_REVERT_ARGS} ${PATCH_FILES_FILTERED}
elif [ "${REVERT_HARD}"  == "YES" ]; then
	for file in `${SVN} status | awk '{ print $2 }'`; do
		rm -rf "${PORTSDIR}/$file"
	done
	${SVN} ${SVN_REVERT_ARGS} ${PORTSDIR}
fi
help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?SNT146-W266F25359A8C2F8F92F021A1180>