summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-04-16 14:13:47 -0700
committerOri Bernstein <ori@eigenstate.org>2015-04-16 14:13:47 -0700
commit9df78d333d4fcc74754e16ddf06c2fba58c9858a (patch)
tree03f1f12dcd4cb74f0e6cc4fd63b95f9234b4ec5a
parentb7747c5a3d36f99514b1945efb05b9f04f7dc74a (diff)
downloadmc-9df78d333d4fcc74754e16ddf06c2fba58c9858a.tar.gz
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.
-rw-r--r--bld.proj2
-rw-r--r--mbld/build.myr8
-rw-r--r--mbld/clean.myr3
-rw-r--r--mbld/install.myr3
-rw-r--r--mbld/main.myr3
-rw-r--r--mbld/test.myr3
-rw-r--r--mbld/types.myr1
-rw-r--r--mbld/util.myr15
8 files changed, 29 insertions, 9 deletions
diff --git a/bld.proj b/bld.proj
index bc3b1c8..1f23b30 100644
--- a/bld.proj
+++ b/bld.proj
@@ -1,7 +1,7 @@
sub =
+ mbld
libstd
libbio
libregex
- mbld
;;
diff --git a/mbld/build.myr b/mbld/build.myr
index 19baa73..39caa9d 100644
--- a/mbld/build.myr
+++ b/mbld/build.myr
@@ -57,7 +57,7 @@ const buildbin = {b, targ, addsrc
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 @@ const buildbin = {b, targ, addsrc
std.slfree(src)
;;
targ.built = true
+ popdir(b)
}
const buildlib = {b, targ
@@ -84,7 +85,7 @@ const buildlib = {b, targ
if targ.built
->
;;
- setdir(b, targ.dir)
+ pushdir(b, targ.dir)
addincludes(b, targ)
buildlibdeps(b, targ)
lib = targ.name
@@ -106,15 +107,18 @@ const buildlib = {b, targ
;;
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)
break
;;
;;
+ popdir(b)
}
const addincludes = {b, targ
diff --git a/mbld/clean.myr b/mbld/clean.myr
index 89e595b..5452ae5 100644
--- a/mbld/clean.myr
+++ b/mbld/clean.myr
@@ -70,7 +70,7 @@ const cleanup = {b, targ, leaves, islib
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 @@ const cleanup = {b, targ, leaves, islib
std.put("\tclean %s\n", k)
;;
;;
+ popdir(b)
}
diff --git a/mbld/install.myr b/mbld/install.myr
index 88c80bf..ca053db 100644
--- a/mbld/install.myr
+++ b/mbld/install.myr
@@ -52,7 +52,7 @@ const movetargs = {b, delete
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 @@ const movefile = {b, delete, dir, file, instdir, destdir, prefix, perm
;;
;;
std.slfree(path)
+ popdir(b)
}
const moveman = {b, delete, dir, man
diff --git a/mbld/main.myr b/mbld/main.myr
index 2cff45b..359da8c 100644
--- a/mbld/main.myr
+++ b/mbld/main.myr
@@ -10,6 +10,7 @@ use "opts.use"
use "parse.use"
use "test.use"
use "types.use"
+use "util.use"
const main = {args : byte[:][:]
var b : bld.build#
@@ -107,7 +108,7 @@ const mkbuild = {bldfile
if !findbase(b, bldfile) || !std.chdir(b.basedir)
std.fatal(1, "could not find %s\n", bldfile)
;;
- b.curdir = ""
+ bld.pushdir(b, "")
-> b
}
diff --git a/mbld/test.myr b/mbld/test.myr
index 77c6c25..df45bbb 100644
--- a/mbld/test.myr
+++ b/mbld/test.myr
@@ -66,7 +66,7 @@ const dotest = {b, targ, ok
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 @@ const dotest = {b, targ, ok
std.slfree(t)
;;
std.slfree(tests)
+ popdir(b)
-> ok
}
diff --git a/mbld/types.myr b/mbld/types.myr
index c819ad0..a1e0f81 100644
--- a/mbld/types.myr
+++ b/mbld/types.myr
@@ -6,6 +6,7 @@ pkg bld =
/* build state */
basedir : byte[:]
bldfile : byte[:]
+ dirstk : byte[:][:]
curdir : byte[:]
/* build params */
all : byte[:][:]
diff --git a/mbld/util.myr b/mbld/util.myr
index 3268f4e..383cdbd 100644
--- a/mbld/util.myr
+++ b/mbld/util.myr
@@ -11,7 +11,8 @@ pkg bld =
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,13 +104,23 @@ const gettarg = {tab, n
;;
}
+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
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)