build: introduce jailed ports build

This commit is contained in:
Franco Fichtner 2014-12-20 22:31:37 +01:00
parent 9ee95e10ab
commit 3971334486
2 changed files with 85 additions and 38 deletions

View File

@ -176,7 +176,11 @@ EOF
setup_stage()
{
rm -rf "${1}" 2>/dev/null ||
(chflags -R noschg "${1}"; rm -rf "${1}" 2>/dev/null)
mkdir -p "${1}"
# might have been a chroot
umount ${1}/dev 2> /dev/null || true
# remove base system files
rm -rf ${1} 2> /dev/null ||
(chflags -R noschg ${1}; rm -rf ${1} 2> /dev/null)
# revive directory for next run
mkdir -p ${1}
}

View File

@ -29,62 +29,85 @@ set -e
. ./common.sh
# unbreaks gettext-runtime
unset STAGEDIR
cp ${TOOLSDIR}/config/current/make.conf /etc/make.conf
PORT_LIST="${TOOLSDIR}/config/current/ports"
PORT_LIST=$(cat ${TOOLSDIR}/config/current/ports)
git_clear ${PORTSDIR}
# If `quick' is given, do not safely strip the system,
# so that we don't have to wait to rebuild any package.
[ "${1}" != "quick" ] && rm -rf ${PACKAGESDIR}
setup_stage ${STAGEDIR}
setup_base ${STAGEDIR}
mkdir -p ${PACKAGESDIR}
echo ">>> Setting up chroot in ${STAGEDIR}"
# make sure pkg(8) is installed or pull if from ports
if pkg -N; then
# no need to rebuild
else
echo ">>> Bootstrapping pkg(8)..."
rm -rf ${PACKAGESDIR}/pkg-*.txz
make -C "${PORTSDIR}/ports-mgmt/pkg" rmconfig-recursive
make -C "${PORTSDIR}/ports-mgmt/pkg" clean all install
cp /etc/resolv.conf ${STAGEDIR}/etc
mount -t devfs devfs ${STAGEDIR}/dev
chroot ${STAGEDIR} /etc/rc.d/ldconfig start
echo ">>> Setting up ports in ${STAGEDIR}"
MAKE_CONF="${TOOLSDIR}/config/current/make.conf"
if [ -f ${MAKE_CONF} ]; then
cp ${MAKE_CONF} ${STAGEDIR}/etc/make.conf
fi
tar -C/ -cf - --exclude=.${PORTSDIR}/.git .${PORTSDIR} | \
tar -C${STAGEDIR} -pxf -
# bootstrap all available packages to save time
mkdir -p ${PACKAGESDIR} ${STAGEDIR}${PACKAGESDIR}
cp ${PACKAGESDIR}/* ${STAGEDIR}${PACKAGESDIR} || true
for PACKAGE in "$(ls ${PACKAGESDIR}/*.txz)"; do
# may fail for missing dependencies and
# that's what we need: rebuild chain :)
pkg -c ${STAGEDIR} add ${PACKAGE} || true
done
rm -rf ${STAGEDIR}${PACKAGESDIR}/*
echo ">>> Building packages..."
# make sure pkg(8) is installed or pull if from ports
chroot ${STAGEDIR} /bin/sh -es <<EOF
if pkg -N; then
# no need to rebuild
else
make -C ${PORTSDIR}/ports-mgmt/pkg rmconfig-recursive
make -C ${PORTSDIR}/ports-mgmt/pkg clean all install
fi
EOF
chroot ${STAGEDIR} /bin/sh -es <<EOF
echo "${PORT_LIST}" | {
while read PORT_NAME PORT_CAT PORT_OPT; do
if [ "${PORT_NAME}" = "#" ]; then
if [ "\${PORT_NAME}" = "#" ]; then
continue
fi
echo -n ">>> Building ${PORT_NAME}... "
echo -n ">>> Building \${PORT_NAME}... "
if pkg query %n ${PORT_NAME} > /dev/null; then
if pkg query %n \${PORT_NAME} > /dev/null; then
echo "skipped."
continue
fi
# when ports are rebuilt clear them from PACKAGESDIR
rm -rf ${PACKAGESDIR}/${PORT_NAME}-*.txz
rm -rf ${PACKAGESDIR}/\${PORT_NAME}-*.txz
# user configs linger somewhere else and override the override :(
make -C "${PORTSDIR}/${PORT_CAT}/${PORT_NAME}" rmconfig-recursive
make -C "${PORTSDIR}/${PORT_CAT}/${PORT_NAME}" clean all install
make -C ${PORTSDIR}/\${PORT_CAT}/\${PORT_NAME} rmconfig-recursive
make -C ${PORTSDIR}/\${PORT_CAT}/\${PORT_NAME} clean all install
if pkg query %n ${PORT_NAME} > /dev/null; then
if pkg query %n \${PORT_NAME} > /dev/null; then
# ok
else
echo "${PORT_NAME}: package names don't match"
echo "\${PORT_NAME}: package names don't match"
exit 1
fi
done < ${PORT_LIST}
done
}
EOF
echo ">>> Creating binary packages..."
chroot ${STAGEDIR} /bin/sh -es <<EOF
pkg_resolve_deps()
{
local PORTS
@ -92,28 +115,48 @@ pkg_resolve_deps()
local PORT
local DEP
DEPS="$(pkg info -qd ${1})"
PORTS="${1} ${DEPS}"
DEPS="\$(pkg info -qd \${1})"
PORTS="\${1} \${DEPS}"
for DEP in $DEPS; do
for DEP in \${DEPS}; do
# recurse into hell and back
pkg_resolve_deps ${DEP}
pkg_resolve_deps \${DEP}
done
for PORT in $PORTS; do
pkg create -no ${PACKAGESDIR} -f txz ${PORT}
for PORT in \${PORTS}; do
pkg create -no ${PACKAGESDIR} -f txz \${PORT}
done
}
pkg_resolve_deps pkg
echo "${PORT_LIST}" | {
while read PORT_NAME PORT_CAT PORT_OPT; do
if [ "\${PORT_NAME}" = "#" ]; then
continue
fi
pkg_resolve_deps "\$(pkg info -E \${PORT_NAME})"
done
}
EOF
# in non-quick more we wipe all results
[ "${1}" != "quick" ] && rm -rf ${PACKAGESDIR}/*
echo "${PORT_LIST}" | {
while read PORT_NAME PORT_CAT PORT_OPT; do
if [ "${PORT_NAME}" = "#" ]; then
continue
fi
pkg_resolve_deps "$(pkg info -E ${PORT_NAME})"
done < ${PORT_LIST}
PORT_FILE=$(ls ${STAGEDIR}${PACKAGESDIR}/${PORT_NAME}-*.txz)
if [ -f ${PORT_FILE} ]; then
rm -rf ${PACKAGESDIR}/${PORT_NAME}-*.txz
mv ${PORT_FILE} ${PACKAGESDIR}
fi
done
}
# also build the meta-package
cd ${TOOLSDIR}/build && ./core.sh