shithub: mc

Download patch

ref: 25fa643fa08fd1a2101fd961ce192d96db5ca017
parent: 1cb2922cb4086434fa0adb6c7a697db14cbdba26
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Apr 19 15:04:46 EDT 2015

Add support for 'dep=' in mbld gen

    This means that mbld code will regenerate generated targets
    if the inputs aren't up to date.

--- a/mbld/build.myr
+++ b/mbld/build.myr
@@ -104,8 +104,8 @@
 
 const genfiles = {b, gt
 	setdir(b, gt.dir)
-	for f in gt.out
-		if !std.fexists(f)
+	for out in gt.out
+		if !std.fexists(out) || !allfresh(gt.deps, out)
 			run(gt.cmd)
 			break
 		;;
@@ -145,11 +145,15 @@
 			if builddep(b, dg, d, incs)
 				stale = true
 			;;
-			if !std.fexists(d)
-				match std.htget(b.gensrc, d)
-				| `std.Some gt:	run(gt.cmd)
-				| `std.None:	std.fatal(1, "no input file %s\n", d)
+			match std.htget(b.gensrc, d)
+			| `std.Some gt:	
+				if !std.fexists(d) || !allfresh(gt.deps, d)
+					run(gt.cmd)
 				;;
+			| `std.None:
+				if !std.fexists(d)
+					std.fatal(1, "no input file %s\n", d)
+				;;
 			;;
 			if !isfresh(d, out)
 				stale = true
@@ -372,6 +376,15 @@
 		;;
 	;;
 	std.slfree(libs)
+	-> true
+}
+
+const allfresh = {deps, out
+	for d in deps
+		if !isfresh(d, out)
+			-> false
+		;;
+	;;
 	-> true
 }
 
--- a/mbld/parse.myr
+++ b/mbld/parse.myr
@@ -223,7 +223,7 @@
 
 /* gentarget: wordlist {attrs} = wordlist ;; */
 const gentarget = {b, p
-	var outlist, cmdlist
+	var outlist, deplist, cmdlist
 	var durable
 	var attrs
 	var gt
@@ -260,10 +260,13 @@
 	;;
 
 	durable = false
+	deplist = [][:]
 	for elt in attrs
 		match elt
 		| ("durable", ""):	durable = true
 		| ("durable", val):	failparse(p, "durable attr does not take argument\n")
+		| ("dep", depname):	deplist = std.slpush(deplist, depname)
+		| (attrname, val):	failparse(p, "attribute %s not valid on gen targets\n")
 		;;
 	;;
 
@@ -271,6 +274,7 @@
 		.dir=std.sldup(p.fdir),
 		.out=outlist,
 		.durable=durable,
+		.deps=deplist,
 		.cmd=cmdlist
 	])
 	for o in outlist
--- a/mbld/types.myr
+++ b/mbld/types.myr
@@ -41,6 +41,7 @@
 		dir	: byte[:]
 		out	: byte[:][:]
 		cmd	: byte[:][:] 
+		deps	: byte[:][:] 
 		durable	: bool
 		/* we can have multiple outputs, but we only want to run once for each */
 		done	: bool
--- a/parse/tok.c
+++ b/parse/tok.c
@@ -623,7 +623,7 @@
                   break;
     }
     return mktok(tt);
-};
+}
 
 static Tok *number(int base)
 {