summaryrefslogtreecommitdiff
path: root/mbld/clean.myr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-04-13 01:25:54 -0700
committerOri Bernstein <ori@eigenstate.org>2015-04-13 01:29:42 -0700
commit52585564bf5a46db0ae6c9fe4e20307e014de848 (patch)
treea0cbd5529dcb351d1c1c059d44379e8e5b85b1f8 /mbld/clean.myr
parent2f5a88d9b79271f78ec71cf7f796ca5fb74de89e (diff)
downloadmc-52585564bf5a46db0ae6c9fe4e20307e014de848.tar.gz
Move mbld to subdirectory of itself for merging.
Diffstat (limited to 'mbld/clean.myr')
-rw-r--r--mbld/clean.myr89
1 files changed, 89 insertions, 0 deletions
diff --git a/mbld/clean.myr b/mbld/clean.myr
new file mode 100644
index 0000000..89e595b
--- /dev/null
+++ b/mbld/clean.myr
@@ -0,0 +1,89 @@
+use std
+
+use "config.use"
+use "deps.use"
+use "opts.use"
+use "parse.use"
+use "subdir.use"
+use "types.use"
+use "util.use"
+
+pkg bld =
+ const cleanall : (b : build# -> bool)
+ const clean : (b : build#, targ : byte[:] -> bool)
+;;
+
+const cleanall = {b
+ for tn in b.all
+ match gettarg(b.targs, tn)
+ | `Bin bt:
+ cleanup(b, bt, bt.inputs, true)
+ | `Lib lt:
+ cleanup(b, lt, lt.inputs, true)
+ | `Test tt:
+ cleanup(b, tt, tt.inputs, true)
+ | `Gen gt:
+ for f in gt.out
+ if !gt.durable && std.remove(f)
+ std.put("\tclean %s\n", f)
+ ;;
+ ;;
+ | `Man m:
+ ;;
+ ;;
+ -> true
+}
+
+const clean = {b, targ
+ for tn in b.all
+ match gettarg(b.targs, tn)
+ | `Bin bt:
+ if std.sleq(bt.name, targ)
+ cleanup(b, bt, bt.inputs, true)
+ ;;
+ | `Lib lt:
+ if std.sleq(lt.name, targ)
+ cleanup(b, lt, lt.inputs, true)
+ ;;
+ | `Test tt:
+ if std.sleq(tt.name, targ)
+ cleanup(b, tt, tt.inputs, true)
+ ;;
+ | `Gen gt:
+ for f in gt.out
+ if !gt.durable && std.remove(f)
+ std.put("\tclean %s\n", f)
+ ;;
+ ;;
+ | `Man m:
+ ;;
+ ;;
+ -> true
+}
+
+const cleanup = {b, targ, leaves, islib
+ var mchammer_files /* cant touch this */
+ var keys
+ var dg
+
+ /*
+ 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)
+ if !myrdeps(b, targ, islib, true, true, &dg)
+ std.fatal(1, "Could not load dependencies for %s\n", targ.name)
+ ;;
+ mchammer_files = std.mkht(std.strhash, std.streq)
+ for l in leaves
+ std.htput(mchammer_files, l, true)
+ ;;
+
+ keys = std.htkeys(dg.deps)
+ for k in keys
+ if !std.htgetv(mchammer_files, k, false) && std.remove(k)
+ std.put("\tclean %s\n", k)
+ ;;
+ ;;
+}
+