Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 14 Nov 2015 16:33:52 -0500
From:      Ricky G <ricky1252@hotmail.com>
To:        Craig Rodrigues <rodrigc@freebsd.org>
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-W629FAF58F79486179755FEA1100@phx.gbl>
In-Reply-To: <CAG=rPVfZV4kZbhG5c-%2BrjFG4vGTzMmrRasSyBQ%2BgCtY8FBEtoA@mail.gmail.com>
References:  <CAG=rPVcOb4g9DD08c7vAsor8UMf3GnckAJ2wkO37p8Ao3G2GwA@mail.gmail.com>, <SNT146-W8224851E20D3E1FDA17AD4A1150@phx.gbl>, <CAG=rPVfZV4kZbhG5c-%2BrjFG4vGTzMmrRasSyBQ%2BgCtY8FBEtoA@mail.gmail.com>

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

[-- Attachment #1 --]
 Hello, 
 Decided to not add a config file to keep it simpler, so you'll need to edit the variables to your needs below the options. The only packages that it may need is portlint, porttools and/or poudriere. Let me know what you think or needs improvement. 		 	   		  
[-- 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.1"

usage() {
	cat << EOF
Usage: portest [-f bulkfile] [-apPrRtv] patchfile

Options:
    -a     --  Do everything except revert (-ptf build.ports.txt)
    -f     --  Generate a poudiere usable bulk file
    -p     --  Patch and give output
    -P     --  Do not exit on failed patch
    -r     --  Revert the files listed in patchfile
    -R     --  Paranoid revert, will remove and restore anything and
               everything the patchfile may have changed or added
    -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="default"
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 1>2 2>/dev/null
[ $? -eq 1 ] && echo "PORTSDIR is not an svn tree" && exit 1

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

### Patch Tree ###
if [ "$PATCH" == "YES" ] || [ "$PATCH_FAILED_EXIT" == "NO" ] || [ "$ALL" == "YES" ]; then
	SVN_OUTPUT=`${SVN} ${SVN_PATCH_ARGS} "${PATCH_FILE}"`
	if [ $? -ne 0 ] && [ "${PATCH_FAILED_EXIT}" != "NO" ] || [ "`echo "${SVN_OUTPUT}" | grep -m 1 -o rejected`" == "rejected" ] && [ "${PATCH_FAILED_EXIT}" != "NO" ]; then
		echo "${SVN_OUTPUT}"
		echo "Patch Failed"
		exit 1
	else
		echo "${SVN_OUTPUT}" | grep "Skipped[ ].*"
		echo "${SVN_OUTPUT}" | grep -B 1 rejected
		echo "${SVN_OUTPUT}" | grep -A 99 conflicts
	fi
fi

# Generate a list of ports for poudriere to build #
BUILD_LIST="`(cat ${PATCH_FILE} | grep -o '^Index:[ ].*' | sed 's/Index: // ; s/Mk.*// ; s/Tools.*// ; s/Templates.*// ; s/Keywords.*//' | grep -o -e '.*\/.*\/' | 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 -r "`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 ###
# Generate a list of files that were patched #
PATCH_FILES_LIST="`(cat ${PATCH_FILE} | grep -o '^Index:[ ].*' | sed 's/Index: //')`"

cd ${PORTSDIR}
if [ "$REVERT_SOFT" == "YES" ] && [ "$REVERT_HARD" != "YES" ]; then
	${SVN} ${SVN_REVERT_ARGS} ${PATCH_FILES_LIST}
elif [ "$REVERT_HARD"  == "YES" ]; then
	for file in ${PATCH_FILES_LIST}; do
		rm -rf "${PORTSDIR}/$file"
	done
	for file in ${BUILD_LIST}; do
		rm -rf "${PORTSDIR}/$file"
	done
	${SVN} ${SVN_REVERT_ARGS} ${BUILD_LIST}
	${SVN} ${SVN_REVERT_ARGS} ${PATCH_FILES_LIST}
fi

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