shithub: mc

Download patch

ref: d470a28bf8c0b730b9dbf8e73ba7856fed338084
parent: 5a4946bb577b755df6ddb543bccd0573de7cf2bd
author: Ori Bernstein <ori@eigenstate.org>
date: Mon Jul 24 19:06:02 EDT 2017

Fix running tests.

--- a/mbld/deps.myr
+++ b/mbld/deps.myr
@@ -68,8 +68,8 @@
 	if mt.islib
 		u = std.fmt("lib{}.use", mt.name)
 		o = std.fmt("lib{}.a", mt.name)
-		tu = std.pathjoin([b.objdir, mt.dir, u][:])
-		to = std.pathjoin([b.objdir, mt.dir, o][:])
+		tu = std.pathjoin([opt_objdir, mt.dir, u][:])
+		to = std.pathjoin([opt_objdir, mt.dir, o][:])
 
 		gu = node(g, tu)
 		go = node(g, to)
@@ -90,8 +90,8 @@
 		std.slfree(u)
 	else
 		u = std.fmt("{}.use", mt.name)
-		tu = std.pathjoin([b.objdir, mt.dir, u][:])
-		to = std.pathjoin([b.objdir, mt.dir, mt.name][:])
+		tu = std.pathjoin([opt_objdir, mt.dir, u][:])
+		to = std.pathjoin([opt_objdir, mt.dir, mt.name][:])
 
 		go = node(g, to)
 		gu = node(g, tu)
@@ -104,7 +104,7 @@
 			addnode(g, "test", n)
 
 			n.wdir = std.sldup(mt.dir)
-			std.slpush(&n.cmd, std.fmt("./{}", mt.name))
+			std.slpush(&n.cmd, std.pathjoin([b.basedir, opt_objdir, mt.dir, mt.name][:]))
 		else
 			addnode(g, "all", go)
 			go.instdir = config.Binpath
@@ -121,11 +121,11 @@
 		leaf(g, p)
 		if std.hassuffix(f, ".myr")
 			t = changesuffix(p, config.Objsuffix)
-			o = std.pathcat(b.objdir, t)
+			o = std.pathcat(opt_objdir, t)
 			std.slfree(t)
 
 			t = changesuffix(p, ".use")
-			u = std.pathcat(b.objdir, t)
+			u = std.pathcat(opt_objdir, t)
 			std.slfree(t)
 
 			depends(g, go, o)
@@ -149,7 +149,7 @@
 			std.slfree(deps)
 		elif std.hassuffix(f, ".s")
 			t = changesuffix(p, config.Objsuffix)
-			o = std.pathcat(b.objdir, t)
+			o = std.pathcat(opt_objdir, t)
 			std.slfree(t)
 
 			depends(g, go, o)
@@ -159,7 +159,7 @@
 			ascmd(b, n, mt, o, p)
 		elif std.hassuffix(f, ".glue.c")
 			t = changesuffix(p, config.Objsuffix)
-			o = std.pathcat(b.objdir, t)
+			o = std.pathcat(opt_objdir, t)
 			std.slfree(t)
 
 			(cflags, ll) = scrapecflags(b, mt, p)
@@ -292,11 +292,11 @@
 	leaf(g, sp)
 
 	t = changesuffix(f, "")
-	tp = std.pathjoin([mt.dir, "test", t][:])
+	tp = std.pathjoin([opt_objdir, mt.dir, "test", t][:])
 	std.slfree(t)
 
 	o = changesuffix(f, config.Objsuffix)
-	op = std.pathjoin([mt.dir, "test", o][:])
+	op = std.pathjoin([opt_objdir, mt.dir, "test", o][:])
 	std.slfree(o)
 
 	n = node(g, sp)
@@ -325,8 +325,8 @@
 
 	n = node(g, tp)
 	depends(g, n, tp)
-	n.wdir = std.sldup(std.dirname(std.dirname(tp)))
-	std.slpush(&n.cmd, std.fmt("./test/{}", std.basename(tp)))
+	n.wdir = std.sldup(std.dirname(std.dirname(sp)))
+	std.slpush(&n.cmd, std.pathjoin([b.basedir, opt_objdir, mt.dir, "test", std.basename(tp)][:]))
 
 	addnode(g, "test", n)
 }
@@ -439,21 +439,21 @@
 }
 
 const myrcmd = {b, n, mt, src, istest
-	std.slpush(&n.cmd, opt_mc)
-	if b.objdir.len > 0
-		pushopt(&n.cmd, "-O", b.objdir)
+	std.slpush(&n.cmd, std.sldup(opt_mc))
+	if opt_objdir.len > 0
+		pushopt(&n.cmd, "-O", std.sldup(opt_objdir))
 	;;
 	for inc : mt.incpath[:mt.incpath.len - 1]
-		pushopt(&n.cmd, "-I", inc)
+		pushopt(&n.cmd, "-I", std.pathcat(opt_objdir, inc))
 	;;
 	if istest
 		for (dir, _, _) : mt.tstdeps
-			pushopt(&n.cmd, "-I", dir)
+			pushopt(&n.cmd, "-I", std.pathcat(opt_objdir, dir))
 		;;
-		pushopt(&n.cmd, "-I", mt.dir)
+		pushopt(&n.cmd, "-I", std.pathcat(opt_objdir, mt.dir))
 	;;
 	for (dir, _, _) : mt.libdeps
-		pushopt(&n.cmd, "-I", dir)
+		pushopt(&n.cmd, "-I", std.pathcat(opt_objdir, dir))
 	;;
 	if opt_genasm
 		std.slpush(&n.cmd, "-S")
@@ -500,7 +500,7 @@
 				std.slpush(&l, `Xdep p)
 			else
 				/* internal library */
-				p = std.pathjoin([b.objdir, mt.dir, uses[3]][:])
+				p = std.pathjoin([opt_objdir, mt.dir, uses[3]][:])
 				std.sljoin(&p, ".use")
 				std.slpush(&l, `Ldep p)
 			;;
--- a/mbld/libs.myr
+++ b/mbld/libs.myr
@@ -28,11 +28,11 @@
 	u = std.fmt("lib{}.use", mt.name)
 	ldep = std.mk([
 		.name=mt.name,
-		.dir=std.pathcat(b.objdir, mt.dir),
+		.dir=std.pathcat(opt_objdir, mt.dir),
 		.dep=dep,
 		.dyndep=dyndep,
-		.genuse=std.pathjoin([b.objdir, mt.dir, u][:]),
-		.genar=std.pathjoin([b.objdir, mt.dir, l][:]),
+		.genuse=std.pathjoin([opt_objdir, mt.dir, u][:]),
+		.genar=std.pathjoin([opt_objdir, mt.dir, l][:]),
 	])
 	std.slfree(l)
 	std.slfree(u)
--- a/mbld/main.myr
+++ b/mbld/main.myr
@@ -37,6 +37,7 @@
 			[.opt='b', .arg="bin", .desc="compile binary named 'bin' from inputs"],
 			[.opt='l', .arg="lib", .desc="compile lib named 'lib' from inputs"],
 			[.opt='r', .arg="rt", .desc="link against runtime 'rt' instead of default"],
+			[.opt='o', .arg="dir", .desc="output directory"],
 		][:]
 	])
 
@@ -53,6 +54,7 @@
 		| ('B', arg):	bld.opt_instbase = arg
 		| ('t', tag):	std.slpush(&tags, tag)
 		| ('R', arg):	runsrc = arg
+		| ('o', arg):	bld.opt_objdir = arg
 		| ('b', arg):
 			targname = arg
 			bintarg = true
@@ -83,7 +85,7 @@
 
 	b = mkbuild(tags)
 	if targname.len != 0
-		buildimm(b, targname, cmd.args)
+		ok = buildimm(b, targname, cmd.args)
 	elif runsrc.len != 0
 		bld.opt_silent = true
 		tmp = std.mktemppath("runmyr")
@@ -152,7 +154,6 @@
 	var b
 
 	b = std.zalloc()
-	b.objdir = "obj"
 	b.libs = std.mkht(std.strhash, std.streq)
 	b.proc = std.mkht(std.inthash, std.inteq)
 	b.targs = std.mkht(std.strhash, std.streq)
--- a/mbld/opts.myr
+++ b/mbld/opts.myr
@@ -12,7 +12,7 @@
 	var opt_incpaths	: byte[:][:]
 	var opt_instbase	: byte[:]
 	var opt_destdir	: byte[:]
-	var opt_outdir	: byte[:]
+	var opt_objdir	: byte[:]
 	var opt_maxproc : std.size
 	var opt_debug	: bool
 	var opt_silent	: bool
@@ -44,6 +44,7 @@
 var opt_muse	= "muse"
 var opt_ld	= "ld"
 var opt_ar	= "ar"
+var opt_objdir	= "obj"
 var opt_genasm  = false
 var opt_silent	= false
 var opt_maxproc = 1
--- a/mbld/test.myr
+++ b/mbld/test.myr
@@ -57,7 +57,7 @@
 	var sub
 
 	dir = std.pathcat(b.basedir, n.wdir)
-	mbldput("run {}:\t", n.lbl)
+	mbldput("run {} in {}:\t", n.lbl, dir)
 	std.chdir(dir)
 	match std.spork(n.cmd)
 	| `std.Err m:
@@ -84,10 +84,10 @@
 			;;
 		;;
 		if !res
-			std.slpush(failed, n.lbl)
+			std.slpush(failed, std.fmt("{j= } || {}", n.cmd, dir))
 		;;
 	;;
-	std.slfree(dir)
+	//std.slfree(dir)
 	-> res
 }
 
--- a/mbld/types.myr
+++ b/mbld/types.myr
@@ -4,7 +4,6 @@
 	type build = struct
 		/* build state */
 		basedir	: byte[:]
-		objdir	: byte[:]
 		tags	: std.htab(byte[:], (int, int, int))#
 		libs	: std.htab(byte[:], libdep#)#
 		deps	: depgraph#
--- a/test/runtest.rc
+++ b/test/runtest.rc
@@ -5,7 +5,7 @@
 MYR_MUSE=../muse/6.out
 fn build {
 	rm -f $1 $1^.6 $1^.use
-	../mbld/mbld -b $1 -I../lib/std -I../lib/sys -r../rt/_myrrt.6 $1^.myr
+	../obj/mbld/mbld -o '' -b $1 -I../lib/std -I../lib/sys -r../rt/_myrrt.6 $1^.myr
 }
 
 fn pass {
--- a/test/runtest.sh
+++ b/test/runtest.sh
@@ -11,8 +11,8 @@
 
 build() {
 	rm -f $1 $1.o $1.s $1.use
-	echo mbld -b $1 -I../lib/std -I../lib/sys -r../rt/_myrrt.o $1.myr
-	../mbld/mbld -b $1 -I../lib/std -I../lib/sys -r../rt/_myrrt.o $1.myr
+	echo ../obj/mbld/mbld -o '' -b $1 -I../lib/std -I../lib/sys -r../rt/_myrrt.o $1.myr
+	../obj/mbld/mbld -o '' -b $1 -I../lib/std -I../lib/sys -r../rt/_myrrt.o $1.myr
 }
 
 pass() {