Bug 159946

Summary: [PATCH] [bsd.port.mk] Add support for make search license=
Product: Ports & Packages Reporter: Chris Rees <crees>
Component: Ports FrameworkAssignee: Port Management Team <portmgr>
Status: Closed Feedback Timeout    
Severity: Affects Only Me CC: bapt, cperciva
Priority: Normal    
Version: Latest   
Hardware: Any   
OS: Any   

Description Chris Rees 2011-08-20 20:50:10 UTC
It has been suggested recently [1] that we should be able to search by license for ports -- I took this task on as I was curious about delphij's suggestion of modifying INDEX.

The code has added a field at the end of INDEX (so unless programs are stupid and backtrack from the end nothing should break), and to my (pleasant) surprise it actually works:

[crees@zeus]/usr/ports% make search license=EULA | grep '^Path:' | cut -d '     ' -f 2 | xargs -n 1 make -V LICENSE -C
EULA
EULA
EULA
GPLv2 CCbyNCSA3 EULA
ASL EULA
EULA
[crees@zeus]/usr/ports%

Can anyone see any serious problems with the code?

[1] http://groups.google.com/group/mailing.freebsd.ports/browse_thread/thread/0ee74faf111ebe7b?pli=1

Portsnap maintainer duly CC'd.

Fix: 

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.--jc9yF3fxoYPyW06ELvDkubmT4YmYSU0WBTRgWBzs8tCOwckG
Content-Type: text/plain; name="index-license.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="index-license.diff"

Index: Mk/bsd.port.mk
===================================================================
RCS file: /home/pcvs/ports/Mk/bsd.port.mk,v
retrieving revision 1.692
diff -u -r1.692 bsd.port.mk
--- Mk/bsd.port.mk	12 Aug 2011 16:39:23 -0000	1.692
+++ Mk/bsd.port.mk	20 Aug 2011 19:41:14 -0000
@@ -5468,7 +5468,7 @@
 #
 # distribution-name|port-path|installation-prefix|comment| \
 #  description-file|maintainer|categories|extract-depends| \
-#  patch-depends|fetch-depends|build-depends|run-depends|www site
+#  patch-depends|fetch-depends|build-depends|run-depends|www site|license
 #
 # If this ever changes, portmgr should contact the portsnap maintainer
 # first to avoid gratuitous breakage.
@@ -5505,7 +5505,8 @@
 			break; \
 			;; \
 		esac; \
-	done < ${DESCR}; ${ECHO_CMD}) >>${INDEX_OUT}
+	done < ${DESCR}; \
+	${ECHO_CMD} -n "|${LICENSE}" ; ${ECHO_CMD}) >>${INDEX_OUT}
 . endif
 
 www-site:
Index: Mk/bsd.port.subdir.mk
===================================================================
RCS file: /home/pcvs/ports/Mk/bsd.port.subdir.mk,v
retrieving revision 1.79
diff -u -r1.79 bsd.port.subdir.mk
--- Mk/bsd.port.subdir.mk	21 Jul 2011 05:04:39 -0000	1.79
+++ Mk/bsd.port.subdir.mk	20 Aug 2011 19:41:14 -0000
@@ -378,7 +378,7 @@
 	_JAVA_PORTS_INSTALLED="${_JAVA_PORTS_INSTALLED}"
 .endif
 
-PORTSEARCH_DISPLAY_FIELDS?=name,path,info,maint,index,bdeps,rdeps,www
+PORTSEARCH_DISPLAY_FIELDS?=name,path,info,maint,index,bdeps,rdeps,www,license
 PORTSEARCH_KEYLIM?=0
 PORTSEARCH_XKEYLIM?=0
 PORTSEARCH_IGNORECASE?=1
@@ -398,7 +398,8 @@
 	     -z "$$cat"   -a -z "$$xcat"   -a \
 	     -z "$$bdeps" -a -z "$$xbdeps" -a \
 	     -z "$$rdeps" -a -z "$$xrdeps" -a \
-	     -z "$$www"   -a -z "$$xwww"   ]; \
+	     -z "$$www"   -a -z "$$xwww"   -a \
+	     -z "$$license" -a -z "$$xlicense" ]; \
 	then \
 	  ${ECHO_MSG} "The ${.TARGET} target requires a keyword parameter or name parameter,"; \
 	  ${ECHO_MSG} "e.g.: \"make ${.TARGET} key=somekeyword\""; \
@@ -415,6 +416,7 @@
 	    -v bdeps="$$bdeps"      -v xbdeps="$$xbdeps" \
 	    -v rdeps="$$rdeps"      -v xrdeps="$$xrdeps" \
 	    -v www="$$www"          -v xwww="$$xwww" \
+	    -v license="$$license"	-v xlicense="$$xlicense" \
 	    -v icase="$${icase:-${PORTSEARCH_IGNORECASE}}" \
 	    -v keylim="$${keylim:-${PORTSEARCH_KEYLIM}}" \
 	    -v xkeylim="$${xkeylim:-${PORTSEARCH_XKEYLIM}}" \
@@ -440,6 +442,7 @@
 	    if (length(bdeps)) parms[8]  = tolower(bdeps); if (length(xbdeps)) xparms[8]  = tolower(xbdeps); \
 	    if (length(rdeps)) parms[9]  = tolower(rdeps); if (length(xrdeps)) xparms[9]  = tolower(xrdeps); \
 	    if (length(www))   parms[10] = tolower(www);   if (length(xwww))   xparms[10] = tolower(xwww); \
+	    if (length(license)) parms[14] = tolower(license); if (length(xlicense)) xparms[14] = tolower(xlicense); \
 	  } else { \
 	    if (length(name))  parms[1]  = name;  if (length(xname))  xparms[1]  = xname; \
 	    if (length(path))  parms[2]  = path;  if (length(xpath))  xparms[2]  = xpath; \
@@ -449,6 +452,7 @@
 	    if (length(bdeps)) parms[8]  = bdeps; if (length(xbdeps)) xparms[8]  = xbdeps; \
 	    if (length(rdeps)) parms[9]  = rdeps; if (length(xrdeps)) xparms[9]  = xrdeps; \
 	    if (length(www))   parms[10] = www;   if (length(xwww))   xparms[10] = xwww; \
+	    if (length(license)) parms[14] = license; if (length(xlicense)) xparms[14] = xlicense; \
 	  } \
 	    fields["name"]  = 1;  names[1]  = "Port"; \
 	    fields["path"]  = 2;  names[2]  = "Path"; \
@@ -458,6 +462,7 @@
 	    fields["bdeps"] = 8;  names[8]  = "B-deps"; \
 	    fields["rdeps"] = 9;  names[9]  = "R-deps"; \
 	    fields["www"]   = 10; names[10] = "WWW"; \
+	    fields["license"] = 14; names[14] = "license"; \
 	    split(display, d, /,[ \t]*/); \
 	    split(xdisplay, xd, /,[ \t]*/); \
 	    for (i in d) { \
@@ -483,7 +488,7 @@
 	      if ((icase ? tolower($$i) : $$i) ~ xparms[i]) \
 	        next; \
 	    found = 0; \
-	    for (i = 1; i < 11; i++) \
+	    for (i = 1; i < 14; i++) \
 	      if (i in disp) { \
 	        if (xkeylim && (icase ? tolower($$i) : $$i) ~ xkey) \
 	          next; \
@@ -492,7 +497,7 @@
 	      } \
 	    if (keylim && !found) \
 	      next; \
-	    for (i = 1; i < 11; i++) \
+	    for (i = 1; i < 14; i++) \
 	      if (i in disp) \
 	        printf("%s:\t%s\n", names[i], $$i); \
 	    print(""); \
Index: Tools/make_index
===================================================================
RCS file: /home/pcvs/ports/Tools/make_index,v
retrieving revision 1.14
diff -u -r1.14 make_index
--- Tools/make_index	19 Jul 2008 17:59:41 -0000	1.14
+++ Tools/make_index	20 Aug 2011 19:41:14 -0000
@@ -117,7 +117,8 @@
 	'fdep'		=> [split(/ /, $f[9])],
 	'bdep'		=> [split(/ /, $f[10])],
 	'rdep'		=> [split(/ /, $f[11])],
-	'rest'		=> join('|', splice(@f, 12)),
+	'www'		=> $f[12],
+	'license'	=> $f[13],
 	'text'		=> join('|', splice(@f, 0, 7))
     };
     $index{$name} = $pkg;
@@ -168,12 +169,13 @@
 	print join(' ', sort(@{$pkg->{bdep}})) if @{$pkg->{bdep}};
 	print "|";
 	print join(' ', sort(@{$pkg->{rdep}})) if @{$pkg->{rdep}};
-	print "|$pkg->{rest}|";
+	print "|$pkg->{www}|";
 	print join(' ', sort(@{$pkg->{edep}})) if @{$pkg->{edep}};
 	print "|";
 	print join(' ', sort(@{$pkg->{pdep}})) if @{$pkg->{pdep}};
 	print "|";
 	print join(' ', sort(@{$pkg->{fdep}})) if @{$pkg->{fdep}};
+	print "|$pkg->{license}";
 	print "\n";
 	++$pkg->{'PRINTED'};
     }
Comment 1 Edwin Groothuis freebsd_committer freebsd_triage 2011-08-20 20:50:41 UTC
Responsible Changed
From-To: freebsd-ports-bugs->portmgr

bsd.port.mk is portmgr territory (via the GNATS Auto Assign Tool)
Comment 2 Colin Percival freebsd_committer freebsd_triage 2011-08-20 21:08:21 UTC
This would break portsnap's make_index utility, since it expects each line of
describes output to have exactly 13 fields.  There are two workarounds for this:
1. In 9.0 I could change make_index to accept the extra field (subject to re@
approving the change).
2. I can make the portsnap buildbox strip the extra field before distributing
describes output for earlier stable branches.

This does mean, however, that FreeBSD [78] users will not get the license data
in the INDEX if they use portsnap; I don't think there's anything we could do
about that.

-- 
Colin Percival
Security Officer, FreeBSD | freebsd.org | The power to serve
Founder / author, Tarsnap | tarsnap.com | Online backups for the truly paranoid
Comment 3 Chris Rees freebsd_committer freebsd_triage 2011-08-20 21:35:58 UTC
Probably not really a big deal, I could write in a warning if make search
license is used with wrong portsnap..  I'll look. Thanks for the prompt
reply!
Comment 4 Mark Linimon freebsd_committer freebsd_triage 2014-06-02 02:55:42 UTC
Infrastructure PR.
Comment 5 Baptiste Daroussin freebsd_committer freebsd_triage 2014-06-15 23:23:52 UTC
I really don't see any value for make search license=