From 9df78d333d4fcc74754e16ddf06c2fba58c9858a Mon Sep 17 00:00:00 2001 From: Ori Bernstein Date: Thu, 16 Apr 2015 14:13:47 -0700 Subject: 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. --- bld.proj | 2 +- mbld/build.myr | 8 ++++++-- mbld/clean.myr | 3 ++- mbld/install.myr | 3 ++- mbld/main.myr | 3 ++- mbld/test.myr | 3 ++- mbld/types.myr | 1 + mbld/util.myr | 15 +++++++++++++-- 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) -- cgit v1.1