From nobody@FreeBSD.org  Fri Nov 22 12:58:49 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1])
	(using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by hub.freebsd.org (Postfix) with ESMTPS id 308888C8
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 22 Nov 2013 12:58:49 +0000 (UTC)
Received: from oldred.freebsd.org (oldred.freebsd.org [8.8.178.121])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mx1.freebsd.org (Postfix) with ESMTPS id 072F82303
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 22 Nov 2013 12:58:49 +0000 (UTC)
Received: from oldred.freebsd.org ([127.0.1.6])
	by oldred.freebsd.org (8.14.5/8.14.7) with ESMTP id rAMCwl8A045041
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 22 Nov 2013 12:58:47 GMT
	(envelope-from nobody@oldred.freebsd.org)
Received: (from nobody@localhost)
	by oldred.freebsd.org (8.14.5/8.14.5/Submit) id rAMCwlvp045038;
	Fri, 22 Nov 2013 12:58:47 GMT
	(envelope-from nobody)
Message-Id: <201311221258.rAMCwlvp045038@oldred.freebsd.org>
Date: Fri, 22 Nov 2013 12:58:47 GMT
From: Dominic Fandrey <kamikaze@bsdforen.de>
To: freebsd-gnats-submit@FreeBSD.org
Subject: fix ports DESTDIR support with FreeBSD 10 make
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         184170
>Category:       ports
>Synopsis:       [bsd.destdir.mk] fix ports DESTDIR support with FreeBSD 10 make
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    portmgr
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Nov 22 13:00:00 UTC 2013
>Closed-Date:    
>Last-Modified:  Mon Nov 25 10:00:00 UTC 2013
>Originator:     Dominic Fandrey
>Release:        stable/10
>Organization:
private
>Environment:
FreeBSD mobileKamikaze.norad 10.0-BETA3 FreeBSD 10.0-BETA3 #1 r258147: Thu Nov 14 23:56:36 CET 2013     root@mobileKamikaze.norad:/usr/obj/HP6510b-10/amd64/usr/src/sys/HP6510b-10  amd64
>Description:
# make DESTDIR=/root/tmpdest install
===>  Creating some important subdirectories
realpath: /root/tmpdest/___temp___: No such file or directory

*** Error code 1
Stop.
make: stopped in /usr/ports/ports-mgmt/pkg


The cause for this problem is that bsd.destdir.mk gets a list of mount directories, containing of triplets:
<path variable>:<path>:<mountdir in the chroot>

The list is usually just PORTSDIR and DISTDIR, which is then automatically
completed to a triplet. If the triplet is not predefined ___temp___ is used
as the mount dir, which is handled later in the code to call "mktemp -d"
(line 147).

However before it is handled, the path is accessed by realpath (line 143),
which causes make to fail, because the new BSD make in FreeBSD 10 invokes
/bin/sh with the -e argument by default (see the .SHELL target in the manual
page).

The attached patch prevents shell failure by silencing the error and appending
||: to the realpath call (in case of failure call :, which simply returns 0).

This allows proper handling of the ___temp___ case later in the code.
>How-To-Repeat:
Create a FreeBSD environment:
# cd /usr/src
# make installworld distdribution DESTDIR=/root/tmpdest
# chroot /root/tmpdest
# /etc/rc.d/ldconfig start
# exit

Afterwards try installing something from ports.
# cd /usr/ports/ports-mgmt/pkg
# make DESTDIR=/root/tmpdest install

>Fix:


Patch attached with submission follows:

Index: Mk/bsd.destdir.mk
===================================================================
--- Mk/bsd.destdir.mk	(revision 334509)
+++ Mk/bsd.destdir.mk	(working copy)
@@ -140,7 +140,7 @@
 		_tp=$${_entry#*:}; \
 		_host_path=`${REALPATH} $${_tp%:*}`; \
 		_dest_path=$${_entry##*:}; \
-		_full_dest_path=`${REALPATH} $${_destdir}/$${_dest_path}`; \
+		_full_dest_path=`${REALPATH} -q $${_destdir}/$${_dest_path} ||:`; \
 		_entry_was_created=0; \
 		_entry_should_mount=0; \
 		${DEBUG_MSG} "$${_mount_var}:$${_host_path}:$${_full_dest_path}"; \


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-ports-bugs->portmgr 
Responsible-Changed-By: antoine 
Responsible-Changed-When: Sat Nov 23 19:12:59 UTC 2013 
Responsible-Changed-Why:  
Over to maintainer 

http://www.freebsd.org/cgi/query-pr.cgi?pr=184170 

From: Dominic Fandrey <kamikaze@bsdforen.de>
To: bug-followup@FreeBSD.org, kamikaze@bsdforen.de
Cc:  
Subject: Re: ports/184170: [bsd.destdir.mk] fix ports DESTDIR support with
 FreeBSD 10 make
Date: Mon, 25 Nov 2013 10:58:50 +0100

 This is a multi-part message in MIME format.
 --------------030208040706060800030608
 Content-Type: text/plain; charset=ascii
 Content-Transfer-Encoding: 7bit
 
 I found that using DESTDIR litters my ports tree with work directories,
 because WRKDIRPREFIX is not used within the chroot.
 
 So I added a fix for that.
 
 -- 
 A: Because it fouls the order in which people normally read text.
 Q: Why is top-posting such a bad thing?
 A: Top-posting.
 Q: What is the most annoying thing on usenet and in e-mail? 
 
 --------------030208040706060800030608
 Content-Type: text/plain; charset=UTF-8;
  name="patch-ports-Mk-bsd.destdir.mk.txt"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
  filename="patch-ports-Mk-bsd.destdir.mk.txt"
 
 Index: Mk/bsd.destdir.mk
 ===================================================================
 --- Mk/bsd.destdir.mk	(revision 334826)
 +++ Mk/bsd.destdir.mk	(working copy)
 @@ -85,7 +85,7 @@
  # VAR:HOST_PATH:DEST_PATH
  # VAR -> VAR:${VAR}:TMP
  # VAR:HOST_PATH -> VAR:HOST_PATH:TMP
 -DESTDIR_MOUNT_LIST?=	PORTSDIR DISTDIR
 +DESTDIR_MOUNT_LIST?=	PORTSDIR DISTDIR ${WRKDIRPREFIX:DWRKDIRPREFIX}
  _DESTDIR_MOUNT_LIST=
  .for _entry in ${DESTDIR_MOUNT_LIST}
  __entry=${_entry}
 @@ -140,7 +140,7 @@
  		_tp=$${_entry#*:}; \
  		_host_path=`${REALPATH} $${_tp%:*}`; \
  		_dest_path=$${_entry##*:}; \
 -		_full_dest_path=`${REALPATH} $${_destdir}/$${_dest_path}`; \
 +		_full_dest_path=`${REALPATH} -q $${_destdir}/$${_dest_path} ||:`; \
  		_entry_was_created=0; \
  		_entry_should_mount=0; \
  		${DEBUG_MSG} "$${_mount_var}:$${_host_path}:$${_full_dest_path}"; \
 
 --------------030208040706060800030608--
>Unformatted:
