Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 23 Mar 2008 16:17:14 +0100
From:      Ed Schouten <ed@80386.nl>
To:        Max Khon <fjoe@samodelkin.net>
Cc:        freebsd-arch@FreeBSD.org
Subject:   Re: make -k does not exit with appropriate error code if errors are encountered
Message-ID:  <20080323151714.GO51074@hoeg.nl>
In-Reply-To: <47E66591.2060804@samodelkin.net>
References:  <47E66591.2060804@samodelkin.net>

next in thread | previous in thread | raw e-mail | index | archive | help

--nWEzmRaGLXxZdI3i
Content-Type: multipart/mixed; boundary="ssZxAlvqSOvXAj81"
Content-Disposition: inline


--ssZxAlvqSOvXAj81
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

* Max Khon <fjoe@samodelkin.net> wrote:
> BSD make does not exit with appropriate error code (2) if it is run with=
=20
> "-k" and errors are encountered.
>
> Please review this patch that fixes this bug:
>
> http://people.freebsd.org/~fjoe/make.diff
>
> Sample BSDmakefile is:
>
> --- cut here ---
> all:    a b
>
> a:
>         exit 1
>
> b:
>         touch ${.TARGET}
> --- cut here ---
>
> I'd like to commit the to HEAD soon.
>
> /fjoe

Could you take at the attached patches as well? One patch adds support
for the -p flag, which is described in POSIX. The other patch adds a
small optimization, by ignoring execution when the command is a comment.

Thanks!

--=20
 Ed Schouten <ed@80386.nl>
 WWW: http://g-rave.nl/

--ssZxAlvqSOvXAj81
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="freebsd-make-graph-posix.diff"
Content-Transfer-Encoding: quoted-printable

--- src/usr.bin/make/main.c	Sun Jul  9 14:13:59 2006
+++ src/usr.bin/make/main.c	Sun Jul  9 14:16:59 2006
@@ -127,6 +127,7 @@
 Boolean		jobsRunning;	/* TRUE if the jobs might be running */
 Boolean		keepgoing;	/* -k flag */
 Boolean		noExecute;	/* -n flag */
+Boolean		printGraphOnly;	/* -p flag */
 Boolean		queryFlag;	/* -q flag */
 Boolean		touchFlag;	/* -t flag */
 Boolean		usePipes;	/* !-P flag */
@@ -335,7 +336,7 @@
 rearg:
 	optind =3D 1;	/* since we're called more than once */
 	optreset =3D 1;
-#define OPTFLAGS "ABC:D:E:I:PSV:Xd:ef:ij:km:nqrstvx:"
+#define OPTFLAGS "ABC:D:E:I:PSV:Xd:ef:ij:km:npqrstvx:"
 	for (;;) {
 		if ((optind < argc) && strcmp(argv[optind], "--") =3D=3D 0) {
 			found_dd =3D TRUE;
@@ -477,6 +478,10 @@
 			noExecute =3D TRUE;
 			MFLAGS_append("-n", NULL);
 			break;
+		case 'p':
+			printGraphOnly =3D TRUE;
+			debug |=3D DEBUG_GRAPH1;
+			break;
 		case 'q':
 			queryFlag =3D TRUE;
 			/* Kind of nonsensical, wot? */
@@ -685,6 +690,7 @@
 	beSilent =3D FALSE;		/* Print commands as executed */
 	ignoreErrors =3D FALSE;		/* Pay attention to non-zero returns */
 	noExecute =3D FALSE;		/* Execute all commands */
+	printGraphOnly =3D FALSE;		/* Do not print processed output */
 	keepgoing =3D FALSE;		/* Stop on error */
 	allPrecious =3D FALSE;		/* Remove targets when interrupted */
 	queryFlag =3D FALSE;		/* This is not just a check-run */
@@ -1026,7 +1032,7 @@
 		Targ_PrintGraph(1);
=20
 	/* print the values of any variables requested by the user */
-	if (Lst_IsEmpty(&variables)) {
+	if (Lst_IsEmpty(&variables) && !printGraphOnly) {
 		/*
 		 * Since the user has not requested that any variables
 		 * be printed, we can build targets.
@@ -1069,7 +1075,7 @@
 		}
 		Lst_Destroy(&targs, NOFREE);
=20
-	} else {
+	} else if (!printGraphOnly) {
 		Var_Print(&variables, expandVars);
 	}
=20
--- src/usr.bin/make/make.1	Sun Jul  9 14:14:02 2006
+++ src/usr.bin/make/make.1	Sun Jul  9 14:22:53 2006
@@ -40,7 +40,7 @@
 .Nd maintain program dependencies
 .Sh SYNOPSIS
 .Nm
-.Op Fl ABPSXeiknqrstv
+.Op Fl ABPSXeiknpqrstv
 .Op Fl C Ar directory
 .Op Fl D Ar variable
 .Op Fl d Ar flags
@@ -242,6 +242,15 @@
 This option has no effect unless
 .Fl j
 is used too.
+.It Fl p
+Only print the input graph, do not executing any commands. The output is t=
he
+same as
+.Fl d Ar g1 .
+When combined with
+.Fl f Pa /dev/null ,
+only the builtin rules of
+.Nm
+are displayed.
 .It Fl q
 Do not execute any commands, but exit 0 if the specified targets are
 up-to-date and 1, otherwise.

--ssZxAlvqSOvXAj81
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="freebsd-make-comment.diff"
Content-Transfer-Encoding: quoted-printable

Index: job.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /datadump/cvs/freebsd/src/usr.bin/make/job.c,v
retrieving revision 1.126
diff -u -r1.126 job.c
--- job.c	8 Mar 2007 09:16:10 -0000	1.126
+++ job.c	10 Jun 2007 11:39:45 -0000
@@ -2817,6 +2817,24 @@
 }
=20
 /**
+ * shellskip
+ *
+ * Results:
+ *      Returns a non-zero value if execution of the command wouldn't
+ *      have an effect at all, which allows us to skip this line. This
+ *      is useful for lines starting with '#'.
+ */
+static int
+shellskip(char *cmd)
+{
+	if (commandShell->skipfirst !=3D NULL &&
+	    strchr(commandShell->skipfirst, cmd[0]) !=3D NULL)
+		return (1);
+
+	return (0);
+}
+
+/**
  * shellneed
  *
  * Results:
@@ -2958,6 +2976,13 @@
 		return (0);
 	}
=20
+	/*
+	 * Don't execute the command if it's just a comment.
+	 */
+	if (shellskip(cmd)) {
+		return (0);
+	}
+
 	ps.in =3D STDIN_FILENO;
 	ps.out =3D STDOUT_FILENO;
 	ps.err =3D STDERR_FILENO;
Index: shell.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /datadump/cvs/freebsd/src/usr.bin/make/shell.c,v
retrieving revision 1.1
diff -u -r1.1 shell.c
--- shell.c	24 May 2005 15:30:03 -0000	1.1
+++ shell.c	10 Jun 2007 11:51:31 -0000
@@ -82,7 +82,7 @@
 	"name=3Dcsh path=3D'" PATH_DEFSHELLDIR "/csh' "
 	"quiet=3D'unset verbose' echo=3D'set verbose' filter=3D'unset verbose' "
 	"hasErrCtl=3DN check=3D'echo \"%s\"\n' ignore=3D'csh -c \"%s || exit 0\"'=
 "
-	"echoFlag=3Dv errFlag=3De "
+	"echoFlag=3Dv errFlag=3De skipfirst=3D# "
 	"meta=3D'" CSH_META "' builtins=3D'" CSH_BUILTINS "'",
=20
 	/*
@@ -92,7 +92,7 @@
 	"name=3Dsh path=3D'" PATH_DEFSHELLDIR "/sh' "
 	"quiet=3D'set -' echo=3D'set -v' filter=3D'set -' "
 	"hasErrCtl=3DY check=3D'set -e' ignore=3D'set +e' "
-	"echoFlag=3Dv errFlag=3De "
+	"echoFlag=3Dv errFlag=3De skipfirst=3D# "
 	"meta=3D'" SH_META "' builtins=3D'" SH_BUILTINS "'",
=20
 	/*
@@ -103,7 +103,7 @@
 	"name=3Dksh path=3D'" PATH_DEFSHELLDIR "/ksh' "
 	"quiet=3D'set -' echo=3D'set -v' filter=3D'set -' "
 	"hasErrCtl=3DY check=3D'set -e' ignore=3D'set +e' "
-	"echoFlag=3Dv errFlag=3De "
+	"echoFlag=3Dv errFlag=3De skipfirst=3D# "
 	"meta=3D'" SH_META "' builtins=3D'" SH_BUILTINS "' unsetenv=3DT",
=20
 	NULL
@@ -150,6 +150,7 @@
 		free(sh->echo);
 		free(sh->exit);
 		ArgArray_Done(&sh->builtins);
+		free(sh->skipfirst);
 		free(sh->meta);
 		free(sh);
 	}
@@ -174,7 +175,8 @@
 	fprintf(stderr, "  builtins=3D%d\n", sh->builtins.argc - 1);
 	for (i =3D 1; i < sh->builtins.argc; i++)
 		fprintf(stderr, " '%s'", sh->builtins.argv[i]);
-	fprintf(stderr, "\n  meta=3D'%s'\n", sh->meta);
+	fprintf(stderr, "\n  skipfirst=3D'%s'\n", sh->skipfirst);
+	fprintf(stderr, "  meta=3D'%s'\n", sh->meta);
 	fprintf(stderr, "  unsetenv=3D%d\n", sh->unsetenv);
 }
=20
@@ -260,6 +262,10 @@
 			qsort(sh->builtins.argv + 1, sh->builtins.argc - 1,
 			    sizeof(char *), sort_builtins);
 			*fullSpec =3D TRUE;
+		} else if (strcmp(keyw, "skipfirst") =3D=3D 0) {
+			free(sh->skipfirst);
+			sh->skipfirst =3D estrdup(eq);
+			*fullSpec =3D TRUE;
 		} else if (strcmp(keyw, "meta") =3D=3D 0) {
 			free(sh->meta);
 			sh->meta =3D estrdup(eq);
@@ -379,6 +385,8 @@
  *			    execute the command directly. If this list is empty
  *			    it is assumed, that the command must always be
  *			    handed over to the shell.
+ *	    skipfirst	    Skip execution of the command if the first
+ *	    		    character has a certain value.
  *	    meta	    The shell meta characters. If this is not specified
  *			    or empty, commands are alway passed to the shell.
  *			    Otherwise they are not passed when they contain
Index: shell.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /datadump/cvs/freebsd/src/usr.bin/make/shell.h,v
retrieving revision 1.1
diff -u -r1.1 shell.h
--- shell.h	24 May 2005 15:30:03 -0000	1.1
+++ shell.h	10 Jun 2007 11:39:45 -0000
@@ -96,6 +96,7 @@
 	char	*exit;	/* command line flag: exit on error */
=20
 	ArgArray builtins;	/* ordered list of shell builtins */
+	char	*skipfirst;	/* characters that determine if we can skip the line */
 	char	*meta;		/* shell meta characters */
=20
 	Boolean	unsetenv;	/* unsetenv("ENV") before exec */

--ssZxAlvqSOvXAj81--

--nWEzmRaGLXxZdI3i
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (FreeBSD)

iEYEARECAAYFAkfmdHoACgkQ52SDGA2eCwVwaACfc+REXUn8H298o0gQoqKVnm9h
0dUAnjVM7fww74UaBZvKV1UIOQwcH8im
=drjK
-----END PGP SIGNATURE-----

--nWEzmRaGLXxZdI3i--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080323151714.GO51074>