Bug 92688 - [PATCH] bsd.port.mk: add check to USE_DOS2UNIX
Summary: [PATCH] bsd.port.mk: add check to USE_DOS2UNIX
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: Normal Affects Only Me
Assignee: Port Management Team
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-02-01 16:30 UTC by Alejandro Pulver
Modified: 2006-12-29 21:55 UTC (History)
0 users

See Also:


Attachments
bsd.port.mk.diff (878 bytes, patch)
2006-02-01 16:30 UTC, Alejandro Pulver
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alejandro Pulver 2006-02-01 16:30:10 UTC

This patch adds DOS text files detection support for the "patch-dos2unix
target", and only removes the (one) trailing CR (\r) character.

This is because the conversion can (actually does) damage non-text files. Also
the current version will delete all control characters at the end of the line,
not only a CR (this can produce unexpected results).
Comment 1 Erwin Lansing freebsd_committer freebsd_triage 2006-02-01 16:45:28 UTC
Responsible Changed
From-To: freebsd-ports-bugs->portmgr

Portmgr territory
Comment 2 Alejandro Pulver 2006-02-01 23:06:51 UTC
>Submitter-Id:	current-users 
>Originator:	Alejandro Pulver 
>Organization:	 
>Confidential:	no 
>Synopsis:	Re: ports/92688: [PATCH] bsd.port.mk: add check to USE_DOS2UNIX 
>Severity:	non-critical 
>Priority:	low 
>Category:	ports 
>Class:		update 
>Release:	FreeBSD 5.4-RELEASE i386 
>Environment:


System: FreeBSD 5.4-RELEASE #0: Sat May 21 12:14:47 ART 2005
    root@ale.varnet.bsd:/usr/src/sys/i386/compile/ATHLON-ALE



>Description:


* Change -i"" to -i "" to avoid the next argument being interpreted as the backup suffix (that is -e).


>How-To-Repeat:





>Fix:


--- bsd.port.mk.diff begins here ---
--- /usr/ports/Mk/bsd.port.mk	Fri Jan 27 23:11:05 2006
+++ bsd.port.mk	Wed Feb  1 19:56:52 2006
@@ -3231,12 +3231,15 @@
 .if defined(USE_DOS2UNIX)
 .if ${USE_DOS2UNIX:U}=="YES"
 	@${ECHO_MSG} "===>   Converting DOS text files to UNIX text files"
-	@${FIND} -E ${WRKSRC} -type f -print0 | \
-			${XARGS} -0 ${REINPLACE_CMD} -i"" -e 's/[[:cntrl:]]*$$//'
+	@${FIND} ${WRKSRC} -type f -print0 | ${XARGS} -0 ${SH} -c \
+		'while [ $$# -gt 0 ]; do ${FILE} "$$1" | ${GREP} -q CRLF && \
+		${REINPLACE_CMD} -i "" -e "s/`${PRINTF} \"\r\"`$$//" "$$1"; \
+		shift; done' sep
 .else
 .for f in ${USE_DOS2UNIX}
 	@${ECHO_MSG} "===>   Converting DOS text file to UNIX text file: ${f}"
-	@${REINPLACE_CMD} -i"" -e 's/[[:cntrl:]]*$$//' ${WRKSRC}/${f}
+	@${FILE} "${WRKSRC}/${f}" | ${GREP} -q CRLF && \
+		${REINPLACE_CMD} -i "" -e "s/`${PRINTF} '\r'`$$//" "${WRKSRC}/${f}"
 .endfor
 .endif
 .else
--- bsd.port.mk.diff ends here ---
Comment 3 Mark Linimon freebsd_committer freebsd_triage 2006-02-02 03:20:29 UTC
State Changed
From-To: open->feedback

When I apply this patch and try to make e.g. textproc/silvercity, no 
substitution is done.  Without this patch, it works.
Comment 4 Alejandro Pulver 2006-02-04 01:41:09 UTC
>Submitter-Id:	current-users 
>Originator:	Alejandro Pulver 
>Organization:	 
>Confidential:	no 
>Synopsis:	Re: ports/92688: [PATCH] bsd.port.mk: add check to USE_DOS2UNIX 
>Severity:	non-critical 
>Priority:	low 
>Category:	ports 
>Class:		update 
>Release:	FreeBSD 5.4-RELEASE i386 
>Environment:


System: FreeBSD 5.4-RELEASE #0: Sat May 21 12:14:47 ART 2005
    root@ale.varnet.bsd:/usr/src/sys/i386/compile/ATHLON-ALE



>Description:


Here is a summary of the changes:
- Change -i"" to -i "" so the "-e" argument isn't interpreted as a backup suffix.
- Remove useless "-E" parameter to ${FIND}.
- Change the regexp so it only removes one CR character.
- Check the files are text files before patching them (on FreeBSD >= 5.X  the
  files are also checked for being DOS text files).


>How-To-Repeat:





>Fix:


--- bsd.port.mk.diff begins here ---
--- /usr/ports/Mk/bsd.port.mk	Fri Jan 27 23:11:05 2006
+++ bsd.port.mk	Fri Feb  3 22:33:59 2006
@@ -1505,6 +1505,14 @@
 CONFIGURE_ENV+=	MAKE=${GMAKE}
 .endif
 
+.if defined(USE_DOS2UNIX)
+.if ${OSVERSION} < 500000
+DOS2UNIX_FP=	text
+.else
+DOS2UNIX_FP=	CRLF
+.endif
+.endif
+
 .if defined(USE_GCC)
 .include "${PORTSDIR}/Mk/bsd.gcc.mk"
 .endif
@@ -3231,12 +3239,15 @@
 .if defined(USE_DOS2UNIX)
 .if ${USE_DOS2UNIX:U}=="YES"
 	@${ECHO_MSG} "===>   Converting DOS text files to UNIX text files"
-	@${FIND} -E ${WRKSRC} -type f -print0 | \
-			${XARGS} -0 ${REINPLACE_CMD} -i"" -e 's/[[:cntrl:]]*$$//'
+	@${FIND} ${WRKSRC} -type f -print0 | ${XARGS} -0 ${SH} -c \
+		'while [ $$# -gt 0 ]; do ${FILE} "$$1" | ${GREP} -q ${DOS2UNIX_FP} && \
+		${REINPLACE_CMD} -i "" -e "s/`${PRINTF} \"\r\"`$$//" "$$1"; \
+		shift; done' sep
 .else
 .for f in ${USE_DOS2UNIX}
 	@${ECHO_MSG} "===>   Converting DOS text file to UNIX text file: ${f}"
-	@${REINPLACE_CMD} -i"" -e 's/[[:cntrl:]]*$$//' ${WRKSRC}/${f}
+	@${FILE} "${WRKSRC}/${f}" | ${GREP} -q ${DOS2UNIX_FP} && \
+		${REINPLACE_CMD} -i "" -e "s/`${PRINTF} '\r'`$$//" "${WRKSRC}/${f}"
 .endfor
 .endif
 .else
--- bsd.port.mk.diff ends here ---
Comment 5 Mark Linimon freebsd_committer freebsd_triage 2006-06-20 07:39:16 UTC
State Changed
From-To: feedback->open

Force notify.
Comment 6 Mark Linimon freebsd_committer freebsd_triage 2006-06-20 07:40:21 UTC
State Changed
From-To: open->feedback

As of the commit to bsd.port.mk in 1.525, this patch no longer applies. 
That patch fixed at least one error, but does not add the use of file(1) 
as this one does. 

Please work with edwin to see if you can agree on a corrected patch that 
adds the file(1) check (if necessary?), and incorporates the other, existing, 
change.  Thanks.
Comment 7 Erwin Lansing freebsd_committer freebsd_triage 2006-12-29 21:54:57 UTC
State Changed
From-To: feedback->closed

Patch no longer applies and is partly already implemented and 
the last feature is waiting to be tested in ports/106029. 

Thanks for your submission!