shithub: mc

Download patch

ref: 2f5a88d9b79271f78ec71cf7f796ca5fb74de89e
parent: b612c54208eb92725f85f2521ba1a4be58fc7f44
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Apr 12 21:23:15 EDT 2015

Clean up some debug mess.

--- a/build.myr
+++ b/build.myr
@@ -17,7 +17,7 @@
 
 const buildall = {b
 	for tn in b.all
-		match gettarg(b._targs, tn)
+		match gettarg(b.targs, tn)
 		| `Bin bt:	buildbin(b, bt, false)
 		| `Lib lt:	buildlib(b, lt)
 		| `Test tt:	/* build on 'mbld test' by default */
@@ -30,7 +30,7 @@
 
 const genall = {b
 	for tn in b.all
-		match gettarg(b._targs, tn)
+		match gettarg(b.targs, tn)
 		| `Gen gt: run(gt.cmd)
 		| _:	/* skip */
 		;;
@@ -40,7 +40,7 @@
 }
 
 const build = {b, targ
-	match std.htget(b._targs, targ)
+	match std.htget(b.targs, targ)
 	| `std.Some (`Bin bt):	buildbin(b, bt, false)
 	| `std.Some (`Lib lt):	buildlib(b, lt)
 	| `std.Some (`Test tt):	buildbin(b, tt, false)
@@ -58,14 +58,8 @@
 		->
 	;;
 	setdir(b, targ.dir)
-	if targ.libdeps.len > 0
-		for (inc, lib, subtarg) in targ.libdeps
-			if !hasinc(targ.incpath, inc)
-				targ.incpath = std.slpush(targ.incpath, inc)
-			;;
-			build(b, subtarg)
-		;;
-	;;
+	addincludes(b, targ)
+	buildlibdeps(b, targ)
 	std.put("%s...\n", targ.name)
 	if !myrdeps(b, targ, false, false, addsrc, &dg)
 		std.fatal(1, "Could not load dependencies for %s\n", targ.name)
@@ -81,15 +75,6 @@
 	targ.built = true
 }
 
-const hasinc = {path, t
-	for e in path
-		if std.sleq(e, t)
-			-> true
-		;;
-	;;
-	-> false
-}
-
 const buildlib = {b, targ
 	var archive
 	var u, l
@@ -100,6 +85,8 @@
 		->
 	;;
 	setdir(b, targ.dir)
+	addincludes(b, targ)
+	buildlibdeps(b, targ)
 	lib = targ.name
 	std.put("lib%s.a...\n", lib)
 	archive = std.fmt("lib%s.a", lib)
@@ -125,10 +112,34 @@
 	for f in gt.out
 		if !std.fexists(f)
 			run(gt.cmd)
-			->
+			break
 		;;
 	;;
 }
+
+const addincludes = {b, targ
+	for (inc, lib, subtarg) in targ.libdeps
+		if !hasinc(targ.incpath, inc)
+			targ.incpath = std.slpush(targ.incpath, inc)
+		;;
+	;;
+}
+
+const buildlibdeps = {b, targ
+	for (inc, lib, subtarg) in targ.libdeps
+		build(b, subtarg)
+	;;
+}
+
+const hasinc = {path, t
+	for e in path
+		if std.sleq(e, t)
+			-> true
+		;;
+	;;
+	-> false
+}
+
 
 const builddep = {b, dg, out, incs
 	var stale
--- a/clean.myr
+++ b/clean.myr
@@ -15,7 +15,7 @@
 
 const cleanall = {b
 	for tn in b.all
-		match gettarg(b._targs, tn)
+		match gettarg(b.targs, tn)
 		| `Bin bt:
 			cleanup(b, bt, bt.inputs, true)
 		| `Lib lt:
@@ -36,7 +36,7 @@
 
 const clean = {b, targ
 	for tn in b.all
-		match gettarg(b._targs, tn)
+		match gettarg(b.targs, tn)
 		| `Bin bt:
 			if std.sleq(bt.name, targ)
 				cleanup(b, bt, bt.inputs, true)
--- a/install.myr
+++ b/install.myr
@@ -27,7 +27,7 @@
 	var libarchive
 
 	for tn in b.all
-		match gettarg(b._targs, tn)
+		match gettarg(b.targs, tn)
 		| `Bin bt:
 			movefile(delete, bt.name, opt_instroot, opt_destdir, "bin", 0o755)
 		| `Lib lt:
--- a/main.myr
+++ b/main.myr
@@ -97,10 +97,10 @@
 	var b
 
 	b = std.zalloc()
-	b._targs = std.mkht(std.strhash, std.streq)
+	b.targs = std.mkht(std.strhash, std.streq)
 	b.gensrc = std.mkht(std.strhash, std.streq)
 	b.basedir = std.getcwd()
-	std.put("base dir = %s\n", b.basedir)
+	b.curdir = ""
 	-> b
 }
 
--- a/parse.myr
+++ b/parse.myr
@@ -363,7 +363,6 @@
 			match word(p)
 			| `std.Some l:
 				(dir, lib, targ) = libpath(p, l)
-				std.put("dir: %s, lib: %s, targ: %s\n", dir, lib, targ)
 				libs = std.slpush(libs, (dir, lib, targ))
 			| `std.None:
 				failparse(p, "expected lib name after 'lib'\n")
@@ -502,21 +501,21 @@
 	var tn
 
 	tn = std.fmt("%s:%s", p.fdir, name)
-	if std.hthas(b._targs, tn)
+	if std.hthas(b.targs, tn)
 		failparse(p, "duplicate target %s\n", tn)
 	;;
 	b.all = std.slpush(b.all, tn)
-	std.htput(b._targs, tn, targ)
+	std.htput(b.targs, tn, targ)
 }
 
 const libpath = {p, libpath
-	var dir, lib_, targ
+	var dir, lib, targ
 
 	match(std.strrfind(libpath, ":"))
 	| `std.None:
 		dir = std.sldup(".")
-		lib_ = std.sldup(libpath)
-		targ = std.fmt("%s:%s", p.fdir, lib_)
+		lib = std.sldup(libpath)
+		targ = std.fmt("%s:%s", p.fdir, lib)
 	| `std.Some idx:
 		if idx == libpath.len
 			std.fatal(1, "libdep %s missing library after ':'\n")
@@ -524,12 +523,12 @@
 		/* absolute path */
 		if std.hasprefix(libpath, "@/") || std.hasprefix(libpath, "@:")
 			dir = std.pathcat(p.basedir, libpath[2:idx])
-			lib_ = std.sldup(libpath[idx+1:])
+			lib = std.sldup(libpath[idx+1:])
 			targ = std.sldup(libpath[2:])
 		/* relative path */
 		else
 			dir = std.sldup(libpath[:idx])
-			lib_ = std.sldup(libpath[idx+1:])
+			lib = std.sldup(libpath[idx+1:])
 			targ = std.pathcat(p.fdir, libpath)
 			if std.hasprefix(targ, "../")
 				std.fatal(1, "library %s outside of project\n", libpath)
@@ -536,5 +535,5 @@
 			;;
 		;;
 	;;
-	-> (dir, lib_, targ)
+	-> (dir, lib, targ)
 }
--- a/test.myr
+++ b/test.myr
@@ -22,7 +22,7 @@
 	ok = true
 	if std.fexists("test")
 		for tn in b.all
-			match gettarg(b._targs, tn)
+			match gettarg(b.targs, tn)
 			| `Bin bt:
 				if !dotest(b, bt, ok)
 					ok = false
--- a/types.myr
+++ b/types.myr
@@ -5,9 +5,10 @@
 		cmd	: byte[:][:]	/* command that we ran */
 		/* build state */
 		basedir	: byte[:]
+		curdir	: byte[:]
 		/* build params */
 		all	: byte[:][:]
-		_targs	: std.htab(byte[:], targ)#	/* dir => target mapping */
+		targs	: std.htab(byte[:], targ)#	/* dir => target mapping */
 		tdeps	: std.htab(byte[:], byte[:][:])	/* targname => depname[:] mapping */
 		gensrc	: std.htab(byte[:], gentarg#)#	/* generated src => generating target mapping */
 		prefix	: byte[:]
--- a/util.myr
+++ b/util.myr
@@ -106,11 +106,18 @@
 const setdir = {b, dir
 	var p
 
-	p = std.pathcat(b.basedir, dir)
-	std.put("changing into '%s'\n", p)
-	if !std.chdir(p)
-		std.fatal(1, "could not cd into %s\n")
+	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("Entering directory '%s'\n", dir)
+		if !std.chdir(p)
+			std.fatal(1, "could not cd into %s\n")
+		;;
+		b.curdir = dir
+		std.slfree(p)
 	;;
-	std.slfree(p)
 }