[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [33762] trunk/blender/source/blender/ makesrna/intern/makesrna.c: workaround for build system dependency hell, fixed for cmake + makefiles (probably other buildsystems too).

Campbell Barton ideasman42 at gmail.com
Sat Dec 18 10:27:08 CET 2010


Revision: 33762
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=33762
Author:   campbellbarton
Date:     2010-12-18 10:27:08 +0100 (Sat, 18 Dec 2010)

Log Message:
-----------
workaround for build system dependency hell, fixed for cmake + makefiles (probably other buildsystems too).

makesrna was often generating source every build, but not updating the files because the contents wasn't changed.

this happened because makefiles would check makesrna.c and rna_*.c files were newer then rna_*_gen.c and force a re-generation.

Now ensure updating the files even if they dont change when makesrna.c or rna_*.c are newer then rna_*_gen.c files.

Another solution for this would be to run makesrna program for each C file for finer grained deps.
or remove file comparison checks but that would mean a change to any rna_*.c file would rebuild all.

Modified Paths:
--------------
    trunk/blender/source/blender/makesrna/intern/makesrna.c

Modified: trunk/blender/source/blender/makesrna/intern/makesrna.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/makesrna.c	2010-12-18 09:18:39 UTC (rev 33761)
+++ trunk/blender/source/blender/makesrna/intern/makesrna.c	2010-12-18 09:27:08 UTC (rev 33762)
@@ -47,8 +47,21 @@
 /* Replace if different */
 #define TMP_EXT ".tmp"
 
-static int replace_if_different(char *tmpfile)
+
+/* copied from BLI_file_older */
+#include <sys/stat.h>
+static int file_older(const char *file1, const char *file2)
 {
+	struct stat st1, st2;
+	printf("comparing '%s' - '%s'\n", file1, file2);
+	if(stat(file1, &st1)) return 0;
+	if(stat(file2, &st2)) return 0;
+
+	return (st1.st_mtime < st2.st_mtime);
+}
+
+static int replace_if_different(char *tmpfile, const char *dep_files[])
+{
 	// return 0; // use for testing had edited rna
 
 #define REN_IF_DIFF \
@@ -78,6 +91,38 @@
 		REN_IF_DIFF;
 	}
 
+
+	/* XXX, trick to work around dependancy problem
+	 * assumes dep_files is in the same dir as makesrna.c, which is true for now. */
+
+	if(1) {
+		/* first check if makesrna.c is newer then generated files
+		 * for development on makesrna.c you may want to disable this */
+		if(file_older(orgfile, __FILE__)) {
+			REN_IF_DIFF;
+		}
+
+		/* now check if any files we depend on are newer then any generated files */
+		if(dep_files) {
+			int pass;
+			for(pass=0; dep_files[pass]; pass++) {
+				char from_path[4096]= __FILE__;
+				char *p1, *p2;
+
+				/* dir only */
+				p1= strrchr(from_path, '/');
+				p2= strrchr(from_path, '\\');
+				strcpy((p1 > p2 ? p1 : p2)+1, dep_files[pass]);
+				/* account for build deps, if makesrna.c (this file) is newer */
+				if(file_older(orgfile, from_path)) {
+					REN_IF_DIFF;
+				}
+			}
+		}
+	}
+	/* XXX end dep trick */
+
+
 	fp_new= fopen(tmpfile, "rb");
 
 	if(fp_new==NULL) {
@@ -2615,6 +2660,7 @@
 	FILE *file;
 	char deffile[4096];
 	int i, status;
+	const char *deps[3]; /* expand as needed */
 
 	/* define rna */
 	brna= RNA_create();
@@ -2655,7 +2701,7 @@
 		}
 	}
 
-	replace_if_different(deffile);
+	replace_if_different(deffile, NULL);
 
 	rna_sort(brna);
 
@@ -2683,7 +2729,12 @@
 			}
 		}
 
-		replace_if_different(deffile);
+		/* avoid unneeded rebuilds */
+		deps[0]= PROCESS_ITEMS[i].filename;
+		deps[1]= PROCESS_ITEMS[i].api_filename;
+		deps[2]= NULL;
+
+		replace_if_different(deffile, deps);
 	}
 
 	/* create RNA_blender.h */
@@ -2707,7 +2758,7 @@
 		}
 	}
 
-	replace_if_different(deffile);
+	replace_if_different(deffile, NULL);
 
 	/* free RNA */
 	RNA_define_free(brna);





More information about the Bf-blender-cvs mailing list