ports/93007: Add power of find utility to USE_DOS2UNIX

Dmitry Marakasov amdmi3 at mail.ru
Wed Feb 8 01:10:06 UTC 2006


>Number:         93007
>Category:       ports
>Synopsis:       Add power of find utility to USE_DOS2UNIX
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Feb 08 01:10:04 GMT 2006
>Closed-Date:
>Last-Modified:
>Originator:     Dmitry Marakasov
>Release:        FreeBSD 6.0-RELEASE-p4 i386
>Organization:
>Environment:
System: FreeBSD hades.panopticon 6.0-RELEASE-p4 FreeBSD 6.0-RELEASE-p4 #1: Fri Jan 27 12:07:19 MSK 2006 amdmi3 at hades.panopticon:/usr/obj/usr/src/sys/HADES i386

>Description:
Recently added USE_DOS2UNIX variable is useful feature, making it possible to replace ugly `${REINPLACE_CMD} -e "s|$$(${PRINTF} '\r')||g"' and `${REINPLACE_CMD} -e 's/[[:cntrl:]]*$$//` like constructions with one simple variable. But, it lacks some power of `find' utility (which is widely used along with above-mentioned sed calls). For example, if a port has many (nested) directories with source files, and all these files need to be converted, every directory should be specified in USE_DOS2UNIX variable, so it'll look like this:

USE_DOS2UNIX=	dir1/*.cpp dir1/*.h dir1/dir2/*.cpp dir1/dir2/*.h dir3/*.cpp dir3/*.h ...

I know of `USE_DOS2UNIX=YES', which converts all files, but it is not always possible to use it, as it may corrupt binary files that come with the port.

So, I think it's clever to make it possible to specify find patterns along with globs. That's exactly what the patch does. After it's applied, items defined in USE_DOS2UNIX are interpreted in different way, depending on whether they contain slash or not. If they do, they are interpreted as globs (as it is now). But if they don't, they are interpreted as find patterns, and find utility with corresponding arguments is applied to ${WRKSRC}.

For example, this:

USE_DOS2UNIX=	/Makefile /src/*.cpp /src/*.h

will covert Makefile in ${WRKSRC} and all source files in ${WRKSRC}/src (behavior not changed).

But now this:

USE_DOS2UNIX=	Makefile *.cpp *.h

will covert all makefiles and all source/header files under ${WRKSRC}/src and it's descendant directories, which is very useful if you need to convert may files and don't want to touch EVERY file.

I've also made version of a patch to use find's `-iregex' parameter instead of `-name'. Find's -iregex is used is many ports (see `find /usr/ports -name Makefile -exec cat {} \; | grep -EB1 "XARGS.*cntrl"`), but such strings

USE_DOS2UNIX=   .*\.(c|cpp|h|txt|php)

make Makefiles less readable. So I recommend first version of the patch.

>How-To-Repeat:
Get a port with many subdirectories which contain files you need to convert and try to use USE_DOS2UNIX.

>Fix:

--- patch-bsd.port.mk.name begins here ---
--- bsd.port.mk.orig	Sat Jan 28 05:11:05 2006
+++ bsd.port.mk	Wed Feb  8 03:47:59 2006
@@ -3236,7 +3236,12 @@
 .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}
+	@if ${ECHO_CMD} '${f}' | ${GREP} / > /dev/null 2>&1; then \
+		${REINPLACE_CMD} -i"" -e 's/[[:cntrl:]]*$$//' ${WRKSRC}/${f}; \
+	else \
+		${FIND} -E ${WRKSRC} -type f -name '${f}' -print0 | \
+		${XARGS} -0 ${REINPLACE_CMD} -i"" -e 's/[[:cntrl:]]*$$//'; \
+	fi
 .endfor
 .endif
 .else
--- patch-bsd.port.mk.name ends here ---

--- patch-bsd.port.mk.regex begins here ---
--- bsd.port.mk.orig	Sat Jan 28 05:11:05 2006
+++ bsd.port.mk	Wed Feb  8 03:41:56 2006
@@ -3236,7 +3236,12 @@
 .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}
+	@if ${ECHO_CMD} '${f}' | ${GREP} / > /dev/null 2>&1; then \
+		${REINPLACE_CMD} -i"" -e 's/[[:cntrl:]]*$$//' `echo '${WRKSRC}/${f}'`; \
+	else \
+		${FIND} -E ${WRKSRC} -type f -iregex '${f}' -print0 | \
+		${XARGS} -0 ${REINPLACE_CMD} -i"" -e 's/[[:cntrl:]]*$$//'; \
+	fi
 .endfor
 .endif
 .else
--- patch-bsd.port.mk.regex ends here ---
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the freebsd-ports-bugs mailing list