PERFORCE change 124056 for review
Andrew Pantyukhin
sat at FreeBSD.org
Tue Jul 24 21:18:13 UTC 2007
http://perforce.freebsd.org/chv.cgi?CH=124056
Change 124056 by sat at sat_amilo on 2007/07/24 21:17:24
- Correct a typo in comment
Submitted by: remko the spellchecker :-)
Affected files ...
.. //depot/projects/soc2006/gabor_destdir/Mk/bsd.destdir.mk#24 edit
Differences ...
==== //depot/projects/soc2006/gabor_destdir/Mk/bsd.destdir.mk#24 (text+ko) ====
@@ -32,23 +32,49 @@
# work for the chrooted build if necessary. At
# default, this target is empty.
#
+# DESTDIR_ENV_LIST
+# - Contains names of the variables in host environ(7),
+# which should be imported into the chrooted environ
+# along with their values.
+# Default: empty.
+#
+# You can use something like this in host /etc/make.conf to
+# customize per-chroot environment:
+# .if ${DESTDIR}=/foo/bar
+# PREFIX=/opt
+# CFLAGS=-O3 -pipe
+# DESTDIR_ENV_LIST=PREFIX CFLAGS
+# .endif
+#
.if !defined(_DESTDIRMKINCLUDED)
_DESTDIRMKINCLUDED= yes
-# Place variable names into DESTDIR_ENV_LIST, which you want to override in
-# the DESTDIR environment from outside. E.g.:
-#
-# make DESTDIR=/foo/bar PREFIX=/opt DESTDIR_ENV_LIST=PREFIX
-#
-
DESTDIR_ENV_LIST?=
+DESTDIR_ENV= DESTDIR= CHROOTED=YES
+.for _var in ${DESTDIR_ENV_LIST:NDESTDIR:NCHROOTED:NPORTSDIR}
+DESTDIR_ENV+= ${_var}="${${_var}}"
+.endfor
-DESTDIR_ENV= DESTDIR= CHROOTED=YES PORTSDIR=${PORTSDIR_TMP_REL}
+WITH_EXPERIMENTAL_DESTDIR?= no
-.for _var in ${DESTDIR_ENV_LIST:NDESTDIR:NCHROOTED:NPORTSDIR}
-DESTDIR_ENV+= ${_var}="${${_var}}"
+# Processing DESTDIR_MOUNT_LIST into something more machine-readable
+# VAR:HOST_PATH:DEST_PATH
+# If HOST_PATH is not a dir
+DESTDIR_MOUNT_LIST?= PORTSDIR WRKDIR:/123 WRKSRC:/567:/789 ABC
+_DESTDIR_MOUNT_LIST=
+.for _entry in ${DESTDIR_MOUNT_LIST}
+__entry=${_entry}
+.if ${__entry:M*\:*\:*}
+_DESTDIR_MOUNT_LIST+= ${_entry}
+.elif ${__entry:M*\:*}
+_DESTDIR_MOUNT_LIST+= ${_entry}:___temp___
+.else
+.if defined(${_entry}) && !empty(${_entry})
+_DESTDIR_MOUNT_LIST+= ${_entry}:${${_entry}}:___temp___
+.endif
+.endif
.endfor
.MAIN: all
@@ -63,71 +89,94 @@
.endif
.if !target(do-chroot)
-
-PORTSDIR_TMP!= ${MKTEMP} -d ${DESTDIR}/tmp/portsdir.XXXXXX
-PORTSDIR_TMP_REL= ${PORTSDIR_TMP:S,^${DESTDIR},,}
-BUILDDIR= ${.CURDIR:S,^${PORTSDIR},,:S,^,${PORTSDIR_TMP_REL},}
-
-.if defined(WITH_EXPERIMENTAL_DESTDIR)
do-chroot:
- @if [ ! -d ${DESTDIR} ]; then \
+ @if [ "${WITH_EXPERIMENTAL_DESTDIR}" = "no" ]; then \
+ ${ECHO_CMD} "===> DESTDIR is experimental, set WITH_EXPERIMENTAL_DESTDIR"; \
+ ${ECHO_CMD} "===> if you want to use it."; \
+ exit 0; \
+ fi; \
+ if [ ! -d ${DESTDIR} ]; then \
${ECHO_MSG} "===> Directory ${DESTDIR} does not exist"; \
${ECHO_MSG} "=> Please set DESTDIR to a valid jail environment."; \
exit 1; \
fi; \
- if [ ! -d ${DESTDIR}/tmp ]; then \
+ _destdir=`realpath ${DESTDIR}`; \
+ if [ ! -d $${_destdir}/tmp ]; then \
${ECHO_MSG} "===> Directory ${DESTDIR}/tmp does not exist"; \
- if mkdir ${DESTDIR}/tmp; then \
- ${ECHO_MSG} "=> tmp subdirectory has been successfully created"; \
+ if mkdir $${_destdir}/tmp; then \
+ ${ECHO_MSG} "=> /tmp subdirectory has been successfully created"; \
else \
- ${ECHO_MSG} "=> tmp subdirectory could not be created"; \
+ ${ECHO_MSG} "=> /tmp subdirectory could not be created"; \
exit 2; \
fi; \
fi; \
- for _entry in ${DESTDIR_MOUNT_LIST}; do \
- _var= `${ECHO_CMD} $${_entry} | ${SED} -e 's/:.*//'`; \
- _path1= `${ECHO_CMD} $${_entry} | ${SED} -e 's/[^:]*://'`; \
- _path2= `${ECHO_CMD} $${_path1} | ${SED} -e 's/.*://'`; \
- echo "$${_var} $${_path1} $${_path2}"; \
- if [ $${_path1} = $${_path2} ]; then \
- _tmpdir= `${MKTEMP} -d ${DESTDIR}/tmp/tmpdir.XXXXXX`; \
- _tmpdir_rel= `${ECHO_CMD} $${_tmpdir} | ${SED} -e 's|^${DESTDIR}||'`; \
- if [ $${_var} = PORTSDIR ]; then \
- _builddir= `${ECHO_CMD} ${.CURDIR} | ${SED} -e 's|^${PORTSDIR}||' -e 's|^|$${_tmpdir_rel}|'`; \
+ ${ECHO_MSG} "_DESTDIR_MOUNT_LIST=${_DESTDIR_MOUNT_LIST}"; \
+ for _entry in ${_DESTDIR_MOUNT_LIST}; do \
+ ${ECHO_MSG} "==> Processing $${_entry}"; \
+ _mount_var=$${_entry%%:*}; \
+ _tp=$${_entry#*:}; \
+ _host_path=`realpath $${_tp%:*}`; \
+ _dest_path=$${_entry##*:}; \
+ _full_dest_path=`realpath $${_destdir}/$${_dest_path}`; \
+ _mounted_entries_list=""; \
+ _created_mountpoints_list=""; \
+ _entry_was_created=0; \
+ _entry_should_mount=0; \
+ echo "$${_mount_var}:$${_host_path}:$${_full_dest_path}"; \
+ if [ "$${_dest_path}" = "___temp___" ]; then \
+ echo "Creating temporary mount point"; \
+ if _full_dest_path=`${MKTEMP} -d $${_destdir}/tmp/mountpoint.XXXXXX`; then \
+ echo "Temporary mount point $${_full_dest_path} created successfully"; \
+ _entry_was_created=1; \
+ _entry_should_mount=1; \
+ _dest_path=$${_full_dest_path#$${_destdir}/}; \
+ _created_mountpoints_list="$${_created_mountpoints_list} ${_full_dest_path}"; \
+ else \
+ echo "Failed to create temporary mount point"; \
+ exit 9; \
fi; \
- _tmp= "$${_destdir_env}"; \
- _destdir_env= "$${_tmp} $${_var}=$${_tmpdir_rel}"; \
- echo "$${_destdir_env}"; \
- ${MOUNT_NULLFS} $${_path1} ${DESTDIR}${_tmpdir_rel}; \
else \
- if [ $${_var} = PORTSDIR ]; then \
- _builddir= `${ECHO_CMD} ${.CURDIR} | ${SED} -e 's|^${PORTSDIR}||' -e 's|^|$${_tmpdir_rel}|'`; \
+ echo "Checking if already mounted"; \
+ if ${MOUNT}|grep -qs "^$${_host_path} on $${_full_dest_path} ("; then \
+ echo "$${_host_path} is already mounted on $${_full_dest_path}"; \
+ else \
+ echo "$${_host_path} is not mounted on $${_full_dest_path}"; \
+ _entry_should_mount=1; \
+ fi; \
fi; \
- _tmp= "$${_destdir_env}"; \
- _destdir_env= "$${_tmp} $${_var}=$${_path2}"; \
- ${MOUNT_NULLFS} $${_path1} ${DESTDIR}/$${_path2}; \
- fi; \
+ [ -d $${_full_dest_path} ] || \
+ if mkdir $${_full_dest_path}; then \
+ echo "Mount point $${_full_dest_path} created"; \
+ _entry_was_created=1; \
+ _created_mountpoints_list="$${_created_mountpoints_list} ${_full_dest_path}"; \
+ else \
+ echo "Mount point $${_full_dest_path} could not be created"; \
+ exit 7; \
+ fi; \
+ [ "$${_entry_should_mount}" = "0" ] || \
+ if ${MOUNT_NULLFS} $${_host_path} $${_full_dest_path}; then \
+ echo "Dir $${_host_path} mounted"; \
+ _mounted_entries_list="$${_mounted_entries_list} $${_full_dest_path}"; \
+ else \
+ echo "Dir $${_host_path} could not be mounted"; \
+ [ "$${_entry_was_created}" = "0" ]||rmdir $${_full_dest_path}; \
+ exit 8; \
+ fi; \
done; \
echo "$${_destdir_env}"; \
- found=0; \
- for _entry in `${MOUNT} | ${GREP} devfs | ${AWK} {'print $$3'}`; do \
- if [ `${REALPATH} $${_entry}` = `${REALPATH} ${DESTDIR}/dev` ]; then \
- found=1; \
- fi; \
+ ${ECHO_CMD} "Things we mounted: $${_mounted_entries_list};" \
+ ${ECHO_CMD} "Things we created: $${_created_mountpoints_list};" \
+ ${ECHO_CMD} "===> Starting chrooted make in ${DESTDIR}..."; \
+ ${CHROOT} $${_destdir} ${SH} -c "(cd $${_builddir}; \
+ ${SETENV} -i ${DESTDIR_ENV} $${_destdir_env} ${MAKE} ${.TARGETS})"; \
+ ${ECHO_CMD} "===> Chrooted make in ${DESTDIR} finished. Cleaning up..."; \
+ for _entry in $${_mounted_entries_list}; do \
+ umount -f $${_entry}; \
+ done; \
+ for _entry in $${_created_mountpoints_list}; do \
+ rmdir $${_entry}; \
done; \
- if [ $${found} = 0 ]; then \
- ${ECHO_CMD} "===> Mounting devfs into ${DESTDIR}..."; \
- ${MOUNT_DEVFS} ${DESTDIR}/dev; \
- fi; \
- ${ECHO_CMD} "===> Starting chrooted make in ${DESTDIR}..."; \
- ${CHROOT} ${DESTDIR} ${SH} -c "(cd $${_builddir}; ${SETENV} -i ${DESTDIR_ENV} $${_destdir_env} ${MAKE} ${.TARGETS})"
-.else
-do-chroot:
- @${ECHO_CMD} "===> DESTDIR is experimental, set WITH_EXPERIMENTAL_DESTDIR"; \
- ${ECHO_CMD} "===> if you want to use it."; \
- ${FALSE}
-.endif
-
-.endif
-
-.endif
+ ${ECHO_CMD} "===> Congratulations!"; \
+ exit 0
+.endif # !target(do-chroot)
+.endif # !defined(_DESTDIRMKINCLUDED)
More information about the p4-projects
mailing list