ref: fc4ed1323d5011c0907599e918077163f3405ea1
parent: 9c424350ad0084f4c11bea8752edc306c9e88e84
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Jan 2 15:44:35 EST 2015
Fix support for generating files. This needs to happen when we do the dependency scraping, before the build happens. Otherwise, we can't scrape generated source for dependencies..
--- a/build.myr
+++ b/build.myr
@@ -99,7 +99,7 @@
;;
;;
std.put("%s...\n", targ.name)
- if !myrdeps(&dg, targ.name, targ.inputs, false)
+ if !myrdeps(p, &dg, targ.name, targ.inputs, false)
std.fatal(1, "Could not load dependencies for %s\n", targ.name)
;;
if !std.hthas(dg.deps, targ.name)
@@ -123,7 +123,7 @@
lib = targ.name
std.put("lib%s.a...\n", lib)
archive = std.fmt("lib%s.a", lib)
- if !myrdeps(&dg, lib, targ.inputs, true)
+ if !myrdeps(p, &dg, lib, targ.inputs, true)
std.fatal(1, "Could not load dependencies for %s\n", lib)
;;
if !std.hthas(dg.deps, lib)
--- a/clean.myr
+++ b/clean.myr
@@ -58,7 +58,7 @@
var keys
var dg
- if !myrdeps(&dg, out, leaves, islib)
+ if !myrdeps(p, &dg, out, leaves, islib)
std.fatal(1, "Could not load dependencies for %s\n", out)
;;
mchammer_files = std.mkht(std.strhash, std.streq)
--- a/deps.myr
+++ b/deps.myr
@@ -8,7 +8,7 @@
use "util.use"
pkg bld =
- const myrdeps : (dg : depgraph#, targ : byte[:], srcs : byte[:][:], islib : bool -> bool)
+ const myrdeps : (p : parser#, dg : depgraph#, targ : byte[:], srcs : byte[:][:], islib : bool -> bool)
/* a bit ugly: initialized from main() */
@@ -22,7 +22,7 @@
`Lib byte[:]
;;
-const myrdeps = {dg, targ, srcs, islib
+const myrdeps = {p, dg, targ, srcs, islib
var seentab, donetab
var out, useout
var objs, uses
@@ -59,7 +59,7 @@
;;
;;
for i = 0; i < srcs.len; i++
- srcdeps(dg, seentab, donetab, srcs[i], objs[i], uses[i])
+ srcdeps(p, dg, seentab, donetab, srcs[i], objs[i], uses[i])
;;
dumpgraph(dg)
std.htfree(seentab)
@@ -93,7 +93,7 @@
std.put("}\n")
}
-const srcdeps = {g, seen, done, path, obj, usefile
+const srcdeps = {p, g, seen, done, path, obj, usefile
var deps
if std.hthas(done, path)
@@ -102,7 +102,7 @@
std.fput(1, "dependency loop involving %s\n", path)
std.exit(1)
;;
- deps = getdeps(path)
+ deps = getdeps(p, path)
std.htput(seen, path, true)
for d in deps
match d
@@ -118,7 +118,7 @@
if usefile.len != 0
pushdep(g, l, usefile)
;;
- addusedep(g, seen, done, l)
+ addusedep(p, g, seen, done, l)
;;
;;
std.htput(seen, path, false)
@@ -125,7 +125,7 @@
std.htput(done, path, true)
}
-const addusedep = {g, seen, done, usefile
+const addusedep = {p, g, seen, done, usefile
var src
if std.hthas(done, usefile)
@@ -142,15 +142,21 @@
;;
pushdep(g, src, usefile)
std.htput(g.sources, usefile, src)
- srcdeps(g, seen, done, src, "", usefile)
+ srcdeps(p, g, seen, done, src, "", usefile)
std.htput(done, usefile, true)
}
-const getdeps = {path
+const getdeps = {p, path
var f
var deps : dep[:]
deps = [][:]
+ if !std.fexists(path)
+ match std.htget(p.gensrc, path)
+ | `std.Some gt: run(gt.cmd, "")
+ | `std.None: std.fatal(1, "no input file %s\n", path)
+ ;;
+ ;;
match bio.open(path, bio.Rd)
| `std.Some fd: f = fd
| `std.None: std.fatal(1, "could not open %s\n", path)