Module Name:    src
Committed By:   sjg
Date:           Sat Nov 27 05:02:35 UTC 2010

Modified Files:
        src/usr.bin/make: dir.c meta.c

Log Message:
When a source file moves, make will ignore the stale dependency,
but if the file in question is one that needs to be compiled (.c or .cc),
it still hands the bogus name to the compiler.

If Dir_MTime() cannot find such a file (gn->iParents is not empty),
see if the basename can be found via .PATH, and if so set gn->path to
the found file.   This prevents the stale path being given to the
compiler.

In meta_oodate(), if a referenced file no longer exists, consider the
target out-of-date.

Also, if meta_oodate() decides a target is out-of-date, and it
it uses .OODATE in its commands, we need .OODATE recomputed.
Undo our call to Make_DoAllVar() so that the call from Make_OODate()
will do the right thing.


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/usr.bin/make/dir.c
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/meta.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/dir.c
diff -u src/usr.bin/make/dir.c:1.61 src/usr.bin/make/dir.c:1.62
--- src/usr.bin/make/dir.c:1.61	Sat Jan 24 10:59:09 2009
+++ src/usr.bin/make/dir.c	Sat Nov 27 05:02:35 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.c,v 1.61 2009/01/24 10:59:09 dsl Exp $	*/
+/*	$NetBSD: dir.c,v 1.62 2010/11/27 05:02:35 sjg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: dir.c,v 1.61 2009/01/24 10:59:09 dsl Exp $";
+static char rcsid[] = "$NetBSD: dir.c,v 1.62 2010/11/27 05:02:35 sjg Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)dir.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: dir.c,v 1.61 2009/01/24 10:59:09 dsl Exp $");
+__RCSID("$NetBSD: dir.c,v 1.62 2010/11/27 05:02:35 sjg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1434,6 +1434,31 @@
 	    fullName = NULL;
 	else {
 	    fullName = Dir_FindFile(gn->name, Suff_FindPath(gn));
+	    if (fullName == NULL && gn->flags & FROM_DEPEND &&
+		!Lst_IsEmpty(gn->iParents)) {
+		char *cp;
+
+		cp = strrchr(gn->name, '/');
+		if (cp) {
+		    /*
+		     * This is an implied source, and it may have moved,
+		     * see if we can find it via the current .PATH
+		     */
+		    cp++;
+			
+		    fullName = Dir_FindFile(cp, Suff_FindPath(gn));
+		    if (fullName) {
+			/*
+			 * Put the found file in gn->path
+			 * so that we give that to the compiler.
+			 */
+			gn->path = bmake_strdup(fullName);
+			fprintf(stdout,
+				"%s: ignoring stale %s for %s, found %s\n",
+				progname, makeDependfile, gn->name, fullName);
+		    }
+		}
+	    }
 	    if (DEBUG(DIR))
 		fprintf(debug_file, "Found '%s' as '%s'\n",
 			gn->name, fullName ? fullName : "(not found)" );

Index: src/usr.bin/make/meta.c
diff -u src/usr.bin/make/meta.c:1.3 src/usr.bin/make/meta.c:1.4
--- src/usr.bin/make/meta.c:1.3	Mon Sep 13 21:31:59 2010
+++ src/usr.bin/make/meta.c	Sat Nov 27 05:02:35 2010
@@ -707,6 +707,9 @@
     FILE *fp;
     Boolean ignoreOODATE = FALSE;
 
+    if (oodate)
+	return oodate;		/* we're done */
+
     /*
      * We need to check if the target is out-of-date. This includes
      * checking if the expanded command has changed. This in turn
@@ -715,9 +718,6 @@
      */
     Make_DoAllVar(gn);
 
-    if (oodate)
-	return oodate;		/* we're done */
-
     if (getcwd(latestdir, sizeof(latestdir)) == NULL)
 	err(1, "Could not get current working directory");
 
@@ -809,11 +809,16 @@
 			p = fname1;
 		    }
 
-		    if (stat(p, &fs) == 0 &&
-			!S_ISDIR(fs.st_mode) &&
-			fs.st_mtime > gn->mtime) {
+		    if (stat(p, &fs) == 0) {
+			if (!S_ISDIR(fs.st_mode) &&
+			    fs.st_mtime > gn->mtime) {
+			    if (DEBUG(META))
+				fprintf(debug_file, "%s: %d: file '%s' is newer than the target...\n", fname, lineno, p);
+			    oodate = TRUE;
+			}
+		    } else if (errno == ENOENT) {
 			if (DEBUG(META))
-			    fprintf(debug_file, "%s: %d: file '%s' is newer than the target...\n", fname, lineno, p);
+			    fprintf(debug_file, "%s: %d: file '%s' may have moved?...\n", fname, lineno, p);
 			oodate = TRUE;
 		    }
 		    break;
@@ -904,6 +909,15 @@
 
 	fclose(fp);
     }
+    if (oodate && ignoreOODATE) {
+	/*
+	 * Target uses .OODATE, so we need to re-compute it.
+	 * We need to clean up what Make_DoAllVar() did.
+	 */
+	Var_Delete(ALLSRC, gn);
+	Var_Delete(OODATE, gn);
+	gn->flags &= ~DONE_ALLSRC;
+    }
     return oodate;
 }
 

Reply via email to