Skip to content

Instantly share code, notes, and snippets.

@washort
Created November 10, 2019 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save washort/1ba60801d9ecf4d918878c080751db53 to your computer and use it in GitHub Desktop.
Save washort/1ba60801d9ecf4d918878c080751db53 to your computer and use it in GitHub Desktop.
build system thoughts
import "lib/codec/utf8" =~ [=> UTF8]
import "lib/streams" =~ [=> Sink]
exports (main)
def partialFlow(source, sink) :Vow[Void] as DeepFrozen:
"Flow all packets from `source` to `sink`, like flow(), but don't tell the sink we're done."
if (Ref.isBroken(sink)):
return sink
if (Ref.isBroken(source)):
return source
def [p, r] := Ref.promise()
object flowSink as Sink:
to run(packet) :Vow[Void]:
return when (sink<-(packet)) ->
source<-(flowSink)
null
catch problem:
r.smash(problem)
sink.abort(problem)
Ref.broken(problem)
to complete() :Vow[Void]:
r.resolve(null)
to abort(problem) :Vow[Void]:
r.smash(problem)
return sink.abort(problem)
return when (source<-(flowSink)) ->
p
catch problem:
r.smash(problem)
null
def which(makeFileResource, pathString :Bytes, target :Bytes, ej) as DeepFrozen:
def paths := pathString.split(b`:`).reverse().diverge()
def check():
if (paths.size() == 0):
throw.eject(ej, `$target not found`)
var loc := paths.pop()
if (loc.slice(loc.size() - 1) != b`/`):
loc += b`/`
loc += target
def fp := makeFileResource(UTF8.decode(loc, null)).getContents()
return when (fp) ->
loc
catch _:
check()
return check()
def main(_argv, => makeProcess, => currentProcess, => makeFileResource, => stdio) as DeepFrozen:
def stdout := stdio.stdout()
def [
(b`MONTE`) => var MONTE := null,
(b`EMACS`) => var EMACS := null,
(b`PATH`) => PATH := b``
] | _ := currentProcess.getEnvironment()
if (MONTE == null):
MONTE := which(makeFileResource, PATH, b`monte`, throw)
if (EMACS == null):
EMACS := which(makeFileResource, PATH, b`emacs`, throw)
def do(path :Bytes, argv :List[Bytes]):
def proc := makeProcess(path, argv, [].asMap(), "stdout" => true,
"stderr" => true)
def exitInfo := proc.wait()
return when (exitInfo) ->
def code := exitInfo.exitStatus()
if (code != 0):
partialFlow(proc.stdout(), stdout)
partialFlow(proc.stderr(), stdout)
Ref.broken(`Failure running ``${" ".join([for via (UTF8.decode) s in (argv) s])}``:Error code ${code}`)
catch p:
traceln.exception(p)
p
def bake(sourcePath):
return do(MONTE, [b`monte`, b`bake`, sourcePath])
def orgExport(sourcePath, destPath):
return do(EMACS, [b`emacs`, sourcePath, b`-q`, b`--batch`, b`--eval`, b`(progn (require 'ob-tangle) (setq org-src-preserve-indentation t) (org-babel-goto-named-src-block "root") (org-babel-tangle '(4) "${destPath}"))`])
return when (MONTE, EMACS) ->
def p1 := when (orgExport(b`game.org`, b`game.mt`)) -> { bake(b`game.mt`) }
when (bake(b`mcurses.mt`), p1) ->
traceln(`Done.`)
0
catch p:
traceln.exception(p)
1
catch ee:
traceln.exception(ee)
1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment