shithub: mc

Download patch

ref: 9df78d333d4fcc74754e16ddf06c2fba58c9858a
parent: b7747c5a3d36f99514b1945efb05b9f04f7dc74a
author: Ori Bernstein <ori@eigenstate.org>
date: Thu Apr 16 10:13:47 EDT 2015

Push/pop directories appropriately.

    We had bugs because this was done by just setting dirs, without
    properly changing back at the end of a command. Ordering of build
    targets would break builds.

--- a/bld.proj
+++ b/bld.proj
@@ -1,7 +1,7 @@
 sub =
+	mbld
 	libstd
 	libbio
 	libregex
-	mbld
 ;;
 
--- a/mbld/build.myr
+++ b/mbld/build.myr
@@ -57,7 +57,7 @@
 	if targ.built
 		->
 	;;
-	setdir(b, targ.dir)
+	pushdir(b, targ.dir)
 	addincludes(b, targ)
 	buildlibdeps(b, targ)
 	std.put("%s...\n", targ.name)
@@ -73,6 +73,7 @@
 		std.slfree(src)
 	;;
 	targ.built = true
+	popdir(b)
 }
 
 const buildlib = {b, targ
@@ -84,7 +85,7 @@
 	if targ.built
 		->
 	;;
-	setdir(b, targ.dir)
+	pushdir(b, targ.dir)
 	addincludes(b, targ)
 	buildlibdeps(b, targ)
 	lib = targ.name
@@ -106,9 +107,11 @@
 	;;
 	std.slfree(archive)
 	targ.built = true
+	popdir(b)
 }
 
 const genfiles = {b, gt
+	pushdir(b, gt.dir)
 	for f in gt.out
 		if !std.fexists(f)
 			run(gt.cmd)
@@ -115,6 +118,7 @@
 			break
 		;;
 	;;
+	popdir(b)
 }
 
 const addincludes = {b, targ
--- a/mbld/clean.myr
+++ b/mbld/clean.myr
@@ -70,7 +70,7 @@
 	we want to automatically add 'clean' sources since otherwise,
 	mbld won't be able to clean code after changing a build file.
 	*/
-	setdir(b, targ.dir)
+	pushdir(b, targ.dir)
 	if !myrdeps(b, targ, islib, true, true, &dg)
 		std.fatal(1, "Could not load dependencies for %s\n", targ.name)
 	;;
@@ -85,5 +85,6 @@
 			std.put("\tclean %s\n", k)
 		;;
 	;;
+	popdir(b)
 }
 
--- a/mbld/install.myr
+++ b/mbld/install.myr
@@ -52,7 +52,7 @@
 const movefile = {b, delete, dir, file, instdir, destdir, prefix, perm
 	var path
 
-	setdir(b, dir)
+	pushdir(b, dir)
 	path = std.pathjoin([destdir, instdir, prefix, file][:])
 	if delete
 		std.put("\tdelete %s\n", path)
@@ -72,6 +72,7 @@
 		;;
 	;;
 	std.slfree(path)
+	popdir(b)
 }
 
 const moveman = {b, delete, dir, man
--- a/mbld/main.myr
+++ b/mbld/main.myr
@@ -10,6 +10,7 @@
 use "parse.use"
 use "test.use"
 use "types.use"
+use "util.use"
 
 const main = {args : byte[:][:]
 	var b : bld.build#
@@ -107,7 +108,7 @@
 	if !findbase(b, bldfile) || !std.chdir(b.basedir)
 		std.fatal(1, "could not find %s\n", bldfile)
 	;;
-	b.curdir = ""
+	bld.pushdir(b, "")
 	-> b
 }
 
--- a/mbld/test.myr
+++ b/mbld/test.myr
@@ -66,7 +66,7 @@
 	var tt, bin ,path, tests
 
 	tests = [][:]
-	setdir(b, targ.dir)
+	pushdir(b, targ.dir)
 	for s in targ.inputs
 		path = std.pathcat("./test", s)
 		if std.fexists(path)
@@ -96,6 +96,7 @@
 		std.slfree(t)
 	;;
 	std.slfree(tests)
+	popdir(b)
 	-> ok
 }
 
--- a/mbld/types.myr
+++ b/mbld/types.myr
@@ -6,6 +6,7 @@
 		/* build state */
 		basedir	: byte[:]
 		bldfile	: byte[:]
+		dirstk	: byte[:][:]
 		curdir	: byte[:]
 		/* build params */
 		all	: byte[:][:]
--- a/mbld/util.myr
+++ b/mbld/util.myr
@@ -11,7 +11,8 @@
 	const srcswapsuffix	: (f : byte[:], newsuff : byte[:] -> byte[:])
 	const strlistfree	: (sl : byte[:][:] -> void)
 	const gettarg	: (tab : std.htab(byte[:], targ)#, n : byte[:] -> targ)
-	const setdir	: (b : build#, dir : byte[:] -> void)
+	const pushdir	: (b : build#, dir : byte[:] -> void)
+	const popdir	: (b : build# -> void)
 ;;
 
 const run = {cmd
@@ -103,6 +104,16 @@
 	;;
 }
 
+const pushdir = {b, dir
+	b.dirstk = std.slpush(b.dirstk, dir)
+	setdir(b, dir)
+}
+
+const popdir = {b
+	b.dirstk = b.dirstk[:b.dirstk.len-1]
+	setdir(b, b.dirstk[b.dirstk.len-1])
+}
+
 const setdir = {b, dir
 	var p
 
@@ -109,7 +120,7 @@
 	if !std.sleq(b.curdir, dir)
 		p = std.pathcat(b.basedir, dir)
 		if b.curdir.len != 0
-			std.put("Leaving directory %s\n", b.curdir)
+			std.put("Leaving directory '%s'\n", b.curdir)
 		;;
 
 		std.put("Entering directory '%s'\n", dir)