Subject: bin/1204: [dM] tsort is noisy
To: None <gnats-admin@sun-lamp.pc.cs.cmu.edu>
From: der Mouse <mouse@Collatz.McRCIM.McGill.EDU>
List: netbsd-bugs
Date: 07/10/1995 16:05:05
>Number:         1204
>Category:       bin
>Synopsis:       [dM] tsort is noisy
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Mon Jul 10 16:05:02 1995
>Originator:     der Mouse
>Organization:
	Dis-
>Release:        NetBSD/sparc -current as of this morning (10 July 1995)
>Environment:
	NetBSD/sparc on an IPC...but it doesn't matter.
>Description:
	tsort complains about cycles in its input and cannot be made to
	shut up.  But the commonest use of tsort is probably with ar,
	where you don't really care about cycles because of ranlib,
	making these messages pure noise in the build process.  The
	patch below adds a flag to tsort to shut off the messages,
	documents it, and tweaks bsd.man.mk to use it.
>How-To-Repeat:
	Build almost any library using bsd.man.mk, and notice the
	useless and borderline meaningless messages from tsort about
	cycles in its input data.
>Fix:
	--- /sources/supped/netbsd/src/./usr.bin/tsort/tsort.1	Thu Dec  8 06:24:29 1994
	+++ /usr/src/./usr.bin/tsort/tsort.1	Fri Jul  7 15:52:20 1995
	@@ -45,6 +45,7 @@
	 .Sh SYNOPSIS
	 .Nm tsort
	 .Op Fl l
	+.Op Fl q
	 .Op Ar file
	 .Sh DESCRIPTION
	 .Nm Tsort
	@@ -68,9 +69,26 @@
	 .Pp
	 The options are as follows:
	 .Bl -tag -width Ds
	-.It Fl l 
	+.It Fl l
	 Search for and display the longest cycle.
	 Can take a very long time.
	+.It Fl q
	+Be quiet: don't print any cycles found.  This is suitable when you want
	+a
	+.So
	+best effort
	+.Sc
	+sort but don't really care about cycles, such as in the common idiom
	+using
	+.Nm tsort
	+with
	+.Xr lorder 1
	+and
	+.Xr ar 1
	+(where
	+.Xr ranlib 1
	+is normally run anyway, so cycles don't really matter much).  This
	+option suppresses nothing but cycle reports.
	 .El
	 .Sh SEE ALSO
	 .Xr ar 1
	--- /sources/supped/netbsd/src/./usr.bin/tsort/tsort.c	Thu Dec  8 06:24:29 1994
	+++ /usr/src/./usr.bin/tsort/tsort.c	Fri Jul  7 15:52:22 1995
	@@ -102,7 +102,7 @@
	 
	 DB *db;
	 NODE *graph, **cycle_buf, **longest_cycle;
	-int debug, longest;
	+int debug, longest, quiet;
	 
	 void	 add_arc __P((char *, char *));
	 int	 find_cycle __P((NODE *, NODE *, int, int));
	@@ -123,7 +123,7 @@
	 	int bsize, ch, nused;
	 	BUF bufs[2];
	 
	-	while ((ch = getopt(argc, argv, "dl")) != EOF)
	+	while ((ch = getopt(argc, argv, "dlq")) != EOF)
	 		switch (ch) {
	 		case 'd':
	 			debug = 1;
	@@ -131,6 +131,9 @@
	 		case 'l':
	 			longest = 1;
	 			break;
	+		case 'q':
	+			quiet = 1;
	+			break;
	 		case '?':
	 		default:
	 			usage();
	@@ -340,10 +343,11 @@
	 		for (n = graph; n != NULL; n = n->n_next)
	 			if (!(n->n_flags & NF_ACYCLIC))
	 				if (cnt = find_cycle(n, n, 0, 0)) {
	-					warnx("cycle in data");
	-					for (i = 0; i < cnt; i++)
	-						warnx("%s", 
	-						    longest_cycle[i]->n_name);
	+					if (! quiet) {
	+						warnx("cycle in data");
	+						for (i = 0; i < cnt; i++)
	+							warnx("%s", longest_cycle[i]->n_name);
	+					}
	 					remove_node(n);
	 					clear_cycle();
	 					break;
	--- /sources/supped/netbsd/src/./share/mk/bsd.lib.mk	Fri Jun 30 03:01:04 1995
	+++ /usr/src/./share/mk/bsd.lib.mk	Fri Jul  7 15:52:27 1995
	@@ -98,21 +98,21 @@
	 lib${LIB}.a:: ${OBJS}
	 	@echo building standard ${LIB} library
	 	@rm -f lib${LIB}.a
	-	@${AR} cq lib${LIB}.a `lorder ${OBJS} | tsort`
	+	@${AR} cq lib${LIB}.a `lorder ${OBJS} | tsort -q`
	 	${RANLIB} lib${LIB}.a
	 
	 POBJS+=	${OBJS:.o=.po}
	 lib${LIB}_p.a:: ${POBJS}
	 	@echo building profiled ${LIB} library
	 	@rm -f lib${LIB}_p.a
	-	@${AR} cq lib${LIB}_p.a `lorder ${POBJS} | tsort`
	+	@${AR} cq lib${LIB}_p.a `lorder ${POBJS} | tsort -q`
	 	${RANLIB} lib${LIB}_p.a
	 
	 SOBJS+=	${OBJS:.o=.so}
	 lib${LIB}_pic.a:: ${SOBJS}
	 	@echo building shared object ${LIB} library
	 	@rm -f lib${LIB}_pic.a
	-	@${AR} cq lib${LIB}_pic.a `lorder ${SOBJS} | tsort`
	+	@${AR} cq lib${LIB}_pic.a `lorder ${SOBJS} | tsort -q`
	 	${RANLIB} lib${LIB}_pic.a
	 
	 lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: lib${LIB}_pic.a ${DPADD}

					der Mouse

			    mouse@collatz.mcrcim.mcgill.edu
>Audit-Trail:
>Unformatted: