ref: dbb3de0c99202d9e0ed00d196f8863526cbce95f
parent: 3920112fb1060bed3ebecff443d9887330ef0348
author: Ori Bernstein <[email protected]>
date: Sat Jan 2 13:18:42 EST 2016
Add support for installing data blobs.
--- a/configure
+++ b/configure
@@ -54,6 +54,7 @@
echo "const Runtime = \"_myrrt.o\"" >> mbld/config.myr
# paths to install to
echo "const Manpath = \"share/man/man\"" >> mbld/config.myr
+echo "const Sharepath = \"share\"" >> mbld/config.myr
echo "const Binpath = \"bin\"" >> mbld/config.myr
echo "const Libpath = \"lib/myr\"" >> mbld/config.myr
case $OS in
--- a/mbld/build.myr
+++ b/mbld/build.myr
@@ -28,8 +28,9 @@
;;
| `Lib lt: buildlib(b, lt)
| `Gen gt: genfiles(b, gt)
- | `Man mt: /* nothing needed */
- | `Cmd ct: /* these are for manual commands or tests */
+ | `Data _: /* nothing needed */
+ | `Man _: /* nothing needed */
+ | `Cmd _: /* these are for manual commands or tests */
;;
;;
setdir(b, "")
@@ -56,8 +57,9 @@
;;
| `Lib lt: buildlib(b, lt)
| `Gen gt: genfiles(b, gt)
- | `Man mt: /* nothing needed */
- | `Cmd ct: /* these are for manual commands or tests */
+ | `Data _: /* nothing needed */
+ | `Man _: /* nothing needed */
+ | `Cmd _: /* these are for manual commands or tests */
;;
;;
build(b, targ)
@@ -101,7 +103,8 @@
| `std.Some (`Lib lt): buildlib(b, lt)
| `std.Some (`Gen gt): runin(b, gt.cmd, gt.dir)
| `std.Some (`Cmd ct): runin(b, ct.cmd, ct.dir)
- | `std.Some (`Man mt): /* nothing needed */
+ | `std.Some (`Data _): /* nothing needed */
+ | `std.Some (`Man _): /* nothing needed */
| `std.None: std.fatal("invalid target {}\n", targ)
;;
-> true
--- a/mbld/clean.myr
+++ b/mbld/clean.myr
@@ -26,8 +26,9 @@
std.put("\tclean {}\n", f)
;;
;;
- | `Cmd ct: /* nothing to do */
- | `Man mt: /* nothing to do */
+ | `Data _: /* nothing to do */
+ | `Cmd _: /* nothing to do */
+ | `Man _: /* nothing to do */
;;
;;
-> true
@@ -50,8 +51,9 @@
std.put("\tclean {}\n", f)
;;
;;
- | `Cmd ct:
- | `Man mt:
+ | `Data _: /* nothing to do */
+ | `Cmd _: /* nothing to do */
+ | `Man _: /* nothing to do */
;;
;;
-> true
--- a/mbld/config+plan9-x64.myr
+++ b/mbld/config+plan9-x64.myr
@@ -11,4 +11,5 @@
const Manpath = "sys/man/"
const Binpath = "amd64/bin"
const Libpath = "amd64/lib/myr"
+ const Sharepath = "lib"
;;
--- a/mbld/install.myr
+++ b/mbld/install.myr
@@ -24,6 +24,7 @@
const movetargs = {b, rm
var libarchive
+ var pfx
for tn in b.all
match gettarg(b.targs, tn)
@@ -37,6 +38,15 @@
libarchive = std.fmt("lib{}.a", lt.name)
movefile(b, rm, lt.dir, libarchive, config.Libpath, 0o644)
std.slfree(libarchive)
+ ;;
+ | `Data dt:
+ for blob in dt.blobs
+ if dt.base.len == 0
+ pfx = config.Sharepath
+ else
+ pfx = dt.base
+ ;;
+ movefile(b, rm, dt.dir, blob, pfx, 0o644)
;;
| `Gen gt:
/* nothing to do */
--- a/mbld/parse.myr
+++ b/mbld/parse.myr
@@ -201,6 +201,7 @@
| `std.Some "test": testtarget(b, p)
| `std.Some "gen": cmdtarget(b, p, "gen", false)
| `std.Some "cmd": cmdtarget(b, p, "cmd", true)
+ | `std.Some "data": datatarget(b, p, "data")
| `std.Some "man": mantarget(b, p)
| `std.Some "sub": subtarget(b, p)
/* global attributes */
@@ -242,7 +243,7 @@
const bintarget = {b, p
var t
t = myrtarget(b, p, "bin")
- addtarg(p, b, t.name, t.systags, `Bin t)
+ addtarg(p, b, t.name, t.tags, `Bin t)
}
/* libtarget: myrtarget */
@@ -250,7 +251,7 @@
var t
t = myrtarget(b, p, "lib")
t.islib = true
- addtarg(p, b, t.name, t.systags, `Lib t)
+ addtarg(p, b, t.name, t.tags, `Lib t)
}
/* testtarget: myrtarget */
@@ -259,7 +260,7 @@
t = myrtarget(b, p, "test")
t.istest = true
t.install = false
- addtarg(p, b, t.name, t.systags, `Bin t)
+ addtarg(p, b, t.name, t.tags, `Bin t)
}
/* mantarget: anontarget */
@@ -285,7 +286,7 @@
/* gentarget: wordlist {attrs} = wordlist ;; */
const cmdtarget = {b, p, cmd, iscmd
- var outlist, deplist, cmdlist, systags
+ var outlist, deplist, cmdlist, tags
var durable, istest
var attrs
var gt
@@ -327,7 +328,7 @@
durable = false
istest = false
deplist = [][:]
- systags = [][:]
+ tags = [][:]
for elt in attrs
match elt
| ("durable", ""): durable = true
@@ -334,7 +335,7 @@
| ("test", ""): istest = true
| ("notest", ""): istest = false
| ("dep", depname): deplist = std.slpush(deplist, depname)
- | ("tag", tag): systags = std.slpush(systags, tag)
+ | ("tag", tag): tags = std.slpush(tags, tag)
| (attr, ""):
failparse(p, "attribute {} not valid on {} targets\n", attr, cmd)
| (attr, val):
@@ -349,14 +350,14 @@
.istest=istest,
.deps=deplist,
.cmd=cmdlist,
- .systags=systags,
+ .tags=tags,
])
for o in outlist
if iscmd
- addtarg(p, b, o, gt.systags, `Cmd gt)
+ addtarg(p, b, o, gt.tags, `Cmd gt)
else
std.htput(b.gensrc, o, gt)
- addtarg(p, b, o, gt.systags, `Gen gt)
+ addtarg(p, b, o, gt.tags, `Gen gt)
;;
;;
}
@@ -366,7 +367,7 @@
| name attrlist = inputlist ';;'
*/
const myrtarget = {b, p, targ
- var ldscript, runtime, install, incpath, systags
+ var ldscript, runtime, install, incpath, tags
var name, inputs, libdeps, attrs
var istest
var fsel
@@ -416,13 +417,13 @@
for path in p.incpath
incpath = std.slpush(incpath, path)
;;
- systags = [][:]
+ tags = [][:]
for elt in attrs
match elt
| ("ldscript", lds): ldscript = std.sldup(lds)
| ("runtime", rt): runtime = std.sldup(rt)
| ("inc", path): incpath = std.slpush(incpath, std.sldup(path))
- | ("tag", tag): systags = std.slpush(systags, tag)
+ | ("tag", tag): tags = std.slpush(tags, tag)
| ("inst", ""): install = true
| ("noinst", ""): install = false
| ("test", ""): istest = true
@@ -445,7 +446,7 @@
.islib=false,
.istest=istest,
/* attrs */
- .systags=systags,
+ .tags=tags,
.install=install,
.ldscript=ldscript,
.runtime=runtime,
@@ -453,6 +454,62 @@
])
}
+const datatarget = {b, p, targ
+ var name, attrs, blobs
+ var tags, base
+
+ match word(p)
+ | `std.Some n: name = n
+ | `std.None: failparse(p, "expected target name after '{}'\n", targ)
+ ;;
+
+ skipspace(p)
+ if matchc(p, '{')
+ match attrlist(p)
+ | `std.Some al: attrs = al
+ | `std.None: failparse(p, "invalid attr list for {} {}\n", targ, name)
+ ;;
+ else
+ attrs = [][:]
+ ;;
+
+ skipspace(p)
+ if !matchc(p, '=')
+ failparse(p, "expected '=' after '{} {}'\n", targ, name)
+ ;;
+
+ match wordlist(p)
+ | `std.Some wl:
+ blobs = wl
+ | `std.None: failparse(p, "expected list of file names after '{} {}'\n", targ, name)
+ ;;
+
+ skipspace(p)
+ if !matchc(p, ';') || !matchc(p, ';')
+ failparse(p, "expected ';;' terminating input list, got {}\n", peekc(p))
+ ;;
+
+ tags = [][:]
+ for elt in attrs
+ match elt
+ | ("tag", tag): tags = std.slpush(tags, tag)
+ | ("base", basedir): base = basedir
+ | (invalid, ""):
+ std.fatal("{}: got invalid attr '{}'\n", targ, invalid)
+ | (invalid, attr):
+ std.fatal("{}: got invalid attr '{} = {}'\n", targ, invalid, attr)
+ ;;
+ ;;
+
+ addtarg(p, b, name, tags, `Data std.mk([
+ .dir=std.sldup(p.fdir),
+ .name=name,
+ .tags=tags,
+ .base=base,
+ .blobs=blobs,
+ ]))
+}
+
/* anontarget: '=' wordlist ';;' */
const anontarget = {p, targ
var inputs
@@ -671,11 +728,11 @@
-> c
}
-const addtarg = {p, b, name, systags, targ
+const addtarg = {p, b, name, tags, targ
var tn
tn = std.fmt("{}:{}", p.fdir, name)
- sysseladdlist(p.targsel, tn, systags, (tn, targ))
+ sysseladdlist(p.targsel, tn, tags, (tn, targ))
}
const libpath = {p, libpath
--- a/mbld/types.myr
+++ b/mbld/types.myr
@@ -25,6 +25,7 @@
`Gen cmdtarg#
`Cmd cmdtarg#
`Man mantarg#
+ `Data datatarg#
;;
type myrtarg = struct
@@ -40,7 +41,7 @@
install : bool
runtime : byte[:]
incpath : byte[:][:]
- systags : byte[:][:]
+ tags : byte[:][:]
ldscript : byte[:]
;;
@@ -49,7 +50,7 @@
out : byte[:][:]
cmd : byte[:][:]
deps : byte[:][:]
- systags : byte[:][:]
+ tags : byte[:][:]
durable : bool
/* we can have multiple outputs, but we only want to run once for each */
done : bool
@@ -58,7 +59,16 @@
type mantarg = struct
dir : byte[:]
+ tags : byte[:][:]
pages : byte[:][:]
+ ;;
+
+ type datatarg = struct
+ dir : byte[:]
+ name : byte[:]
+ tags : byte[:][:]
+ base : byte[:]
+ blobs : byte[:][:]
;;
type depgraph = struct