mirror of
https://github.com/natnat-mc/moonbuild
synced 2026-05-28 11:59:41 +02:00
Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 678313d09f | |||
| ebd380fb0f | |||
| 803d1093bb | |||
| ec5fc1cf7d | |||
| 17578bb721 | |||
| d3c8414086 | |||
| d43e9350d3 | |||
| 0f3506c7b7 | |||
| eb28c9c8bb | |||
| e0afeaaf07 | |||
| e13705f232 | |||
| c6004f1582 | |||
| ce942f9da8 | |||
| cc776ef24e | |||
| 603d09fc84 | |||
| 2b3337fc69 | |||
| 5518c61fc1 | |||
| 81baa03624 | |||
| 77f73f3a21 | |||
| 31fcc58ccd | |||
| fcf7c3fa07 |
+3
-1
@@ -1 +1,3 @@
|
|||||||
*.lua
|
bin/*.lua
|
||||||
|
moonbuild/*.lua
|
||||||
|
moonbuild/*/*.lua
|
||||||
|
|||||||
+8
-2
@@ -1,7 +1,13 @@
|
|||||||
|
require 'moonscript'
|
||||||
|
moonbuild = require 'moonbuild'
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
build: =>
|
|
||||||
sh "moon bin/moonbuild.moon -jy"
|
|
||||||
release: =>
|
release: =>
|
||||||
error "no version provided" unless @v
|
error "no version provided" unless @v
|
||||||
tasks.build!
|
tasks.build!
|
||||||
sh "rockbuild -m -t #{@v} upload"
|
sh "rockbuild -m -t #{@v} upload"
|
||||||
|
|
||||||
|
build: => moonbuild j: true
|
||||||
|
install: => moonbuild 'install', j: true
|
||||||
|
clean: => moonbuild 'clean'
|
||||||
|
mrproper: => moonbuild 'mrproper'
|
||||||
|
|||||||
+44
-33
@@ -1,25 +1,36 @@
|
|||||||
public var 'MOONC', 'moonc'
|
public var AMALG: 'amalg.lua'
|
||||||
public var 'AMALG', 'amalg.lua'
|
public var RM: 'rm', '-f', '--'
|
||||||
public var 'RM', 'rm', '-f', '--'
|
public var LUA: 'lua5.3'
|
||||||
public var 'LUA', 'lua5.3'
|
|
||||||
|
|
||||||
var 'LIB_SRC', _.wildcard 'moonbuild/**.moon'
|
var LIB_SRC: _.wildcard 'moonbuild/**.moon'
|
||||||
var 'BIN_SRC', _.wildcard 'bin/*.moon'
|
var BIN_SRC: _.wildcard 'bin/*.moon'
|
||||||
|
|
||||||
var 'LIB_LUA', _.patsubst LIB_SRC, '%.moon', '%.lua'
|
var LIB_LUA: _.patsubst LIB_SRC, '%.moon', '%.lua'
|
||||||
var 'BIN_LUA', _.patsubst BIN_SRC, '%.moon', '%.lua'
|
var BIN_LUA: _.patsubst BIN_SRC, '%.moon', '%.lua'
|
||||||
var 'BIN', _.patsubst BIN_LUA, 'bin/%.lua', 'out/%'
|
var BIN: _.patsubst BIN_LUA, 'bin/%.lua', 'out/%'
|
||||||
|
var LIB: 'out/moonbuild.lua'
|
||||||
|
|
||||||
var 'MODULES', _.foreach (_.patsubst LIB_LUA, '%.lua', '%'), => @gsub '/', '.'
|
var MODULES: _.foreach (_.patsubst LIB_LUA, '%.lua', '%'), => @gsub '/', '.'
|
||||||
|
|
||||||
with public default target 'all'
|
with public default target 'all'
|
||||||
\after 'bin'
|
\after 'bin'
|
||||||
\after 'lib'
|
\after 'lib'
|
||||||
|
|
||||||
with public target 'install'
|
with public target 'install'
|
||||||
\depends 'out/moonbuild'
|
\after 'install-bin'
|
||||||
\produces '/usr/local/bin/moonbuild'
|
\after 'install-lib'
|
||||||
\fn => _.cmd 'sudo', 'cp', @infile, @outfile
|
|
||||||
|
with public target 'install-bin'
|
||||||
|
\depends BIN
|
||||||
|
\produces _.patsubst BIN, 'out/%', '/usr/local/bin/%'
|
||||||
|
\fn => _.cmd 'sudo', 'cp', @infile, @out
|
||||||
|
\sync!
|
||||||
|
|
||||||
|
with public target 'install-lib'
|
||||||
|
\depends LIB
|
||||||
|
\produces "/usr/local/share/lua/#{LUA\gsub 'lua', ''}/moonbuild.lua"
|
||||||
|
\fn => _.cmd 'sudo', 'cp', @infile, @out
|
||||||
|
\sync!
|
||||||
|
|
||||||
with public target 'clean'
|
with public target 'clean'
|
||||||
\fn => _.cmd RM, LIB_LUA
|
\fn => _.cmd RM, LIB_LUA
|
||||||
@@ -27,25 +38,25 @@ with public target 'clean'
|
|||||||
|
|
||||||
with public target 'mrproper'
|
with public target 'mrproper'
|
||||||
\after 'clean'
|
\after 'clean'
|
||||||
\fn => _.cmd RM, BIN
|
\fn => _.cmd RM, BIN, LIB
|
||||||
|
|
||||||
with public target 'bin'
|
with pipeline! -- lib
|
||||||
\depends BIN
|
\sources LIB_SRC
|
||||||
|
\step 'compile-lib'
|
||||||
|
pattern: {'%.moon', '%.lua'}
|
||||||
|
fn: => _.moonc @infile, @out
|
||||||
|
\step 'lib'
|
||||||
|
output: LIB
|
||||||
|
fn: => _.cmd AMALG, '-o', @out, '-s', 'moonbuild/init.lua', _.exclude MODULES, 'moonbuild.init'
|
||||||
|
|
||||||
with public target 'lib'
|
with pipeline! -- bin
|
||||||
\depends LIB_LUA
|
\sources BIN_SRC
|
||||||
|
\step 'compile-bin'
|
||||||
with target BIN, pattern: 'out/%'
|
pattern: {'%.moon', '%.lua'}
|
||||||
\depends 'bin/%.lua'
|
fn: => _.moonc @infile, @out
|
||||||
\depends LIB_LUA
|
\step 'bin'
|
||||||
\produces 'out/%'
|
pattern: {'bin/%.lua', 'out/%'}
|
||||||
\mkdirs!
|
mkdirs: true
|
||||||
\fn =>
|
fn: =>
|
||||||
_.cmd AMALG, '-o', @outfile, '-s', @infile, MODULES
|
_.writefile @out, "#!/usr/bin/env #{LUA}\n#{_.readfile @infile}"
|
||||||
_.writefile @outfile, "#!/usr/bin/env #{LUA}\n#{_.readfile @outfile}"
|
_.cmd 'chmod', '+x', @out
|
||||||
_.cmd 'chmod', '+x', @outfile
|
|
||||||
|
|
||||||
with target {LIB_LUA, BIN_LUA}, pattern: '%.lua'
|
|
||||||
\depends '%.moon'
|
|
||||||
\produces '%.lua'
|
|
||||||
\fn => _.moonc @infile, @outfile
|
|
||||||
|
|||||||
@@ -16,27 +16,27 @@ MODULES = $(shell echo $(foreach lib, $(LIB_LUA), $(patsubst %.lua, %, $(lib)))
|
|||||||
|
|
||||||
all: bin lib
|
all: bin lib
|
||||||
|
|
||||||
install: all
|
|
||||||
sudo cp out/moonbuild /usr/local/bin/moonbuild
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) $(LIB_LUA)
|
$(RM) $(LIB_LUA)
|
||||||
$(RM) $(BIN_LUA)
|
$(RM) $(BIN_LUA)
|
||||||
|
|
||||||
mrproper: clean
|
mrproper: clean
|
||||||
$(RM) $(BIN)
|
$(RM) $(BIN) out/moonbuild.lua
|
||||||
|
|
||||||
bin: $(BIN)
|
bin: $(BIN)
|
||||||
|
|
||||||
lib: $(LIB_LUA)
|
lib: $(LIB_LUA) out/moonbuild.lua
|
||||||
|
|
||||||
out/%: bin/%.lua $(LIB_LUA)
|
out/%: bin/%.lua $(LIB_LUA)
|
||||||
@mkdir -p `dirname $@`
|
@mkdir -p `dirname $@`
|
||||||
$(AMALG) -o $@.body -s $< $(MODULES)
|
|
||||||
@printf '#!/usr/bin/env %s\n' $(LUA) > $@.headline
|
@printf '#!/usr/bin/env %s\n' $(LUA) > $@.headline
|
||||||
@cat $@.headline $@.body > $@
|
@cat $@.headline $< > $@
|
||||||
@rm $@.headline $@.body
|
@rm $@.headline
|
||||||
chmod +x $@
|
chmod +x $@
|
||||||
|
|
||||||
|
out/moonbuild.lua: moonbuild/init.lua $(LIB_LUA)
|
||||||
|
@mkdir -p `dirname $@`
|
||||||
|
$(AMALG) -o $@ -s $< $(MODULES)
|
||||||
|
|
||||||
%.lua: %.moon
|
%.lua: %.moon
|
||||||
moonc $^
|
moonc $^
|
||||||
|
|||||||
@@ -24,11 +24,13 @@ You will need `argparse` and `moonscript` installed from luarocks, and `luaposix
|
|||||||
|
|
||||||
### Bootstrapping
|
### Bootstrapping
|
||||||
You can build moonbuild with itself: `moon bin/moonbuild.moon -qjy`.
|
You can build moonbuild with itself: `moon bin/moonbuild.moon -qjy`.
|
||||||
This will leave the binary ready to be used as `out/moonbuild`.
|
This will leave the binary ready to be used as `out/moonbuild` (it will still depend on the library to be used).
|
||||||
|
The binary and library can then be installed with `bin/moonbuild install`.
|
||||||
|
|
||||||
### Using make
|
You can combine these steps with `moon bin/moonbuild.moon -qjy install` which will build and install moonbuild.
|
||||||
You can also build moonbuild with make: `make`.
|
|
||||||
This will leave the binary ready to be used as `out/moonbuild`.
|
### With `Alfons`
|
||||||
|
Alfons can use the devel version of moonbuild directly from its sources, so `alfons build` and `alfons install` will work directly.
|
||||||
|
|
||||||
## Docs
|
## Docs
|
||||||
TODO
|
TODO
|
||||||
|
|||||||
+8
-16
@@ -1,14 +1,13 @@
|
|||||||
-- load everything we need
|
-- load everything we need
|
||||||
import loadfile from require 'moonscript.base'
|
import loadfile from require 'moonscript.base'
|
||||||
Context = require 'moonbuild.context'
|
import Context, DepGraph, Executor from require 'moonbuild'
|
||||||
Variable = require 'moonbuild.core.Variable'
|
Variable = (require 'moonbuild')['core.Variable']
|
||||||
DepGraph = require 'moonbuild.core.DAG'
|
import parseargs from (require 'moonbuild')['_cmd.common']
|
||||||
import parseargs from require 'moonbuild._cmd.common'
|
argparse = require 'argparse'
|
||||||
import sort, concat from table
|
import sort, concat from table
|
||||||
import exit from os
|
import exit from os
|
||||||
|
|
||||||
-- parse the arguments
|
-- parse the arguments
|
||||||
argparse = require 'argparse'
|
|
||||||
parser = with argparse "moonbuild", "A build system in moonscript"
|
parser = with argparse "moonbuild", "A build system in moonscript"
|
||||||
\option '-b --buildfile', "Build file to use", 'Build.moon'
|
\option '-b --buildfile', "Build file to use", 'Build.moon'
|
||||||
\option '-j --parallel', "Sets the number of parallel tasks, 'y' to run as many as we have cores", '1'
|
\option '-j --parallel', "Sets the number of parallel tasks, 'y' to run as many as we have cores", '1'
|
||||||
@@ -74,15 +73,8 @@ dag = DepGraph ctx, targets
|
|||||||
print "Created dependancy graph" if args.verbose
|
print "Created dependancy graph" if args.verbose
|
||||||
|
|
||||||
-- execute the build
|
-- execute the build
|
||||||
if args.parallel==1
|
nparallel = args.parallel == 'y' and Executor\getmaxparallel! or args.parallel
|
||||||
Executor = require 'moonbuild.core.singleprocessexecutor'
|
print "Building with #{nparallel} max parallel process#{nparallel>1 and "es" or ""}" if args.verbose
|
||||||
executor = Executor dag, args.parallel
|
executor = Executor dag, nparallel
|
||||||
executor\execute args
|
executor\execute args
|
||||||
else
|
|
||||||
ok, Executor = pcall -> require 'moonbuild.core.multiprocessexecutor'
|
|
||||||
Executor = require 'moonbuild.core.singleprocessexecutor' unless ok
|
|
||||||
nparallel = args.parallel == 'y' and Executor\getmaxparallel! or args.parallel
|
|
||||||
print "Building with #{nparallel} max parallel process#{nparallel>1 and "es" or ""}" if args.verbose
|
|
||||||
executor = Executor dag, nparallel
|
|
||||||
executor\execute args
|
|
||||||
print "Finished" if args.verbose
|
print "Finished" if args.verbose
|
||||||
|
|||||||
+7
-1
@@ -17,5 +17,11 @@ cmd.backend = backend
|
|||||||
cmd.parseargs = parseargs
|
cmd.parseargs = parseargs
|
||||||
cmd.escape = escape
|
cmd.escape = escape
|
||||||
|
|
||||||
|
-- derived cmd functions
|
||||||
|
_cmd = cmd.cmd
|
||||||
|
_cmdrst = cmd.cmdrst
|
||||||
|
cmd.cmdline = (cmdline) -> _cmd parseargs cmdline
|
||||||
|
cmd.cmdlinerst = (cmdline) -> _cmdrst parseargs cmdline
|
||||||
|
|
||||||
-- the library itself
|
-- the library itself
|
||||||
setmetatable cmd, __call: => {'cmd', 'cmdrst', 'sh'}
|
setmetatable cmd, __call: => {'cmd', 'cmdrst', 'cmdline', 'cmdlinerst', 'sh'}
|
||||||
|
|||||||
@@ -155,6 +155,7 @@ common.includes = includes
|
|||||||
common.patget = patget
|
common.patget = patget
|
||||||
common.patset = patset
|
common.patset = patset
|
||||||
common.patsubst = patsubst
|
common.patsubst = patsubst
|
||||||
|
common.exclude = exclude
|
||||||
common.min = min
|
common.min = min
|
||||||
common.max = max
|
common.max = max
|
||||||
common.minmax = minmax
|
common.minmax = minmax
|
||||||
|
|||||||
+28
-10
@@ -1,8 +1,8 @@
|
|||||||
import first, filter, foreach, flatten, patsubst from require 'moonbuild._common'
|
import first, filter, foreach, flatten, patsubst, includes from require 'moonbuild._common'
|
||||||
import runwithcontext from require 'moonbuild.compat.ctx'
|
import runwithcontext from require 'moonbuild.compat.ctx'
|
||||||
globalenv = require 'moonbuild.env.global'
|
globalenv = require 'moonbuild.env.global'
|
||||||
import exists, parent, mkdirs, clearentry, disableentry, attributes from require 'moonbuild._fs'
|
import exists, parent, mkdirs, clearentry, disableentry, attributes from require 'moonbuild._fs'
|
||||||
import sort from table
|
import sort, insert, remove from table
|
||||||
import huge from math
|
import huge from math
|
||||||
|
|
||||||
local DepNode, FileTarget
|
local DepNode, FileTarget
|
||||||
@@ -76,6 +76,20 @@ class DepGraph
|
|||||||
buildablenodes: =>
|
buildablenodes: =>
|
||||||
[v for k, v in pairs @nodes when v\canbuild! and not v.built]
|
[v for k, v in pairs @nodes when v\canbuild! and not v.built]
|
||||||
|
|
||||||
|
reset: =>
|
||||||
|
n.built = false for k, n in pairs @nodes
|
||||||
|
|
||||||
|
resetchildren: (names) =>
|
||||||
|
done = {}
|
||||||
|
stack = [v for v in *names]
|
||||||
|
while #stack != 0
|
||||||
|
name = remove stack
|
||||||
|
continue if done[name]
|
||||||
|
done[name] = true
|
||||||
|
node = @nodes[name]
|
||||||
|
node.built = false
|
||||||
|
insert stack, n for n in *(node\children!)
|
||||||
|
|
||||||
class DepNode
|
class DepNode
|
||||||
new: (@dag, target, @name) =>
|
new: (@dag, target, @name) =>
|
||||||
@priority = target.priority
|
@priority = target.priority
|
||||||
@@ -94,12 +108,12 @@ class DepNode
|
|||||||
ctx = setmetatable {},
|
ctx = setmetatable {},
|
||||||
__index: (_, k) ->
|
__index: (_, k) ->
|
||||||
switch k
|
switch k
|
||||||
when 'infile'
|
when 'infile', 'in'
|
||||||
f = first deps
|
f = first deps
|
||||||
f and f.name
|
f and f.name
|
||||||
when 'infiles'
|
when 'infiles'
|
||||||
foreach deps, => @name
|
foreach deps, => @name
|
||||||
when 'outfile'
|
when 'outfile', 'out'
|
||||||
f = first @outs
|
f = first @outs
|
||||||
f and f.name
|
f and f.name
|
||||||
when 'outfiles'
|
when 'outfiles'
|
||||||
@@ -117,23 +131,27 @@ class DepNode
|
|||||||
@deps = flatten { deps, after }
|
@deps = flatten { deps, after }
|
||||||
@built = true if #@deps == 0 and #@buildfunctions == 0
|
@built = true if #@deps == 0 and #@buildfunctions == 0
|
||||||
|
|
||||||
|
children: =>
|
||||||
|
[k for k, n in pairs @dag.nodes when (includes n.ins, @name) or (includes n.after, @name)]
|
||||||
|
|
||||||
canbuild: =>
|
canbuild: =>
|
||||||
for node in *flatten { @ins, @after }
|
for node in *flatten { @ins, @after }
|
||||||
if not @dag.nodes[node].built
|
if not @dag.nodes[node].built
|
||||||
return false
|
return false
|
||||||
for file in *@ins
|
for file in *@ins
|
||||||
if not exists file
|
if not exists file
|
||||||
error "Node #{name} has ran all of its parents, but can't run since #{file} doesn't exist"
|
error "Node #{@name} has ran all of its parents, but can't run since #{file} doesn't exist. Did you mean to use after instead of depends?"
|
||||||
return true
|
return true
|
||||||
|
|
||||||
build: (opts={}) =>
|
build: (opts={}) =>
|
||||||
force = opts.force or false
|
force = opts.force or false
|
||||||
quiet = opts.quiet or false
|
quiet = opts.quiet or false
|
||||||
|
|
||||||
return if @built
|
return false if @built or #@buildfunctions == 0
|
||||||
return unless force or @shouldbuild!
|
return false unless force or @shouldbuild!
|
||||||
print "#{@type == 'virtual' and "Running" or "Building"} #{@name}" unless quiet or #@buildfunctions == 0
|
print "#{@type == 'virtual' and "Running" or "Building"} #{@name}" unless quiet
|
||||||
@actuallybuild!
|
@actuallybuild!
|
||||||
|
true
|
||||||
|
|
||||||
|
|
||||||
shouldbuild: =>
|
shouldbuild: =>
|
||||||
@@ -164,9 +182,9 @@ class DepNode
|
|||||||
ctx = setmetatable {},
|
ctx = setmetatable {},
|
||||||
__index: (_, k) ->
|
__index: (_, k) ->
|
||||||
switch k
|
switch k
|
||||||
when 'infile' then @ins[1]
|
when 'infile', 'in' then @ins[1]
|
||||||
when 'infiles' then @ins
|
when 'infiles' then @ins
|
||||||
when 'outfile' then @outs[1]
|
when 'outfile', 'out' then @outs[1]
|
||||||
when 'outfiles' then @outs
|
when 'outfiles' then @outs
|
||||||
when 'name' then @name
|
when 'name' then @name
|
||||||
else error "No such field in TargetContext: #{k}"
|
else error "No such field in TargetContext: #{k}"
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
Target = require 'moonbuild.core.Target'
|
||||||
|
_ = require 'moonbuild._'
|
||||||
|
import flatten, patsubst from _
|
||||||
|
|
||||||
|
class Pipeline
|
||||||
|
new: (@ctx) =>
|
||||||
|
@lastsources = {}
|
||||||
|
|
||||||
|
sources: (...) =>
|
||||||
|
@lastsources = flatten @lastsources, ...
|
||||||
|
source: (src) =>
|
||||||
|
@lastsources = flatten @lastsources, src
|
||||||
|
|
||||||
|
step: (name, params) =>
|
||||||
|
public = true
|
||||||
|
public, params = false, name if (type name) == 'table'
|
||||||
|
|
||||||
|
tgttype = if params.pattern
|
||||||
|
error "pattern must be a table with the same format as patsubst" unless (type params.pattern) == 'table' and (type params.pattern[1]) == 'string' and (type params.pattern[2]) == 'string'
|
||||||
|
'pattern'
|
||||||
|
elseif params.output or params.out
|
||||||
|
error "output must be a string" unless (type params.output or params.out) == 'string'
|
||||||
|
'single'
|
||||||
|
else
|
||||||
|
error "invalid step type for pipeline: must be pattern or single (out/output)"
|
||||||
|
|
||||||
|
tgtouts = switch tgttype
|
||||||
|
when 'pattern' then patsubst @lastsources, params.pattern[1], params.pattern[2]
|
||||||
|
when 'single' then params.output or params.out
|
||||||
|
|
||||||
|
tgtpatt = switch tgttype
|
||||||
|
when 'pattern' then params.pattern[2]
|
||||||
|
when 'single' then nil
|
||||||
|
|
||||||
|
tgtins = switch tgttype
|
||||||
|
when 'pattern' then params.pattern[1]
|
||||||
|
when 'single' then @lastsources
|
||||||
|
|
||||||
|
tgtprod = switch tgttype
|
||||||
|
when 'pattern' then params.pattern[2]
|
||||||
|
when 'single' then '%'
|
||||||
|
|
||||||
|
tgt = with Target @ctx, tgtouts, pattern: tgtpatt
|
||||||
|
\depends tgtins
|
||||||
|
\produces tgtprod
|
||||||
|
\fn params.fn or error "pipeline steps need a fn"
|
||||||
|
tgt\mkdirs! if params.mkdirs
|
||||||
|
tgt\sync! if params.sync
|
||||||
|
@ctx\addtarget tgt
|
||||||
|
|
||||||
|
if public
|
||||||
|
@ctx\addtarget with Target @ctx, name
|
||||||
|
\depends tgtouts
|
||||||
|
.public = true
|
||||||
|
|
||||||
|
@lastsources = tgtouts
|
||||||
@@ -4,7 +4,17 @@ class Variable
|
|||||||
|
|
||||||
new: (@name, ...) =>
|
new: (@name, ...) =>
|
||||||
@public = false
|
@public = false
|
||||||
if (select '#', ...) !=1 or (type ...) == 'table'
|
if (type @name) == 'table'
|
||||||
|
error "not a valid var table: #{next @name}" unless (type next @name) == 'string'
|
||||||
|
error "more than one var at once: #{next @name}, #{next @name, (next @name)}" if next @name, (next @name)
|
||||||
|
name = next @name
|
||||||
|
@name, param = name, @name
|
||||||
|
val = param[name]
|
||||||
|
if (select '#', ...) !=0 or (type val) == 'table'
|
||||||
|
@value = flatten val, ...
|
||||||
|
else
|
||||||
|
@value = val
|
||||||
|
elseif (select '#', ...) !=1 or (type ...) == 'table'
|
||||||
@value = flatten ...
|
@value = flatten ...
|
||||||
else
|
else
|
||||||
@value = ...
|
@value = ...
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
ok, MultiProcessExecutor = pcall -> require 'moonbuild.core.multiprocessexecutor'
|
||||||
|
ok and MultiProcessExecutor or require 'moonbuild.core.singleprocessexecutor'
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
SingleProcessExecutor = require 'moonbuild.core.singleprocessexecutor'
|
||||||
import fork, _exit from require 'posix.unistd'
|
import fork, _exit from require 'posix.unistd'
|
||||||
import wait from require 'posix.sys.wait'
|
import wait from require 'posix.sys.wait'
|
||||||
import open, stderr from io
|
import open, stderr from io
|
||||||
@@ -17,8 +18,12 @@ class Executor
|
|||||||
@processes = {}
|
@processes = {}
|
||||||
@nprocesses = 0
|
@nprocesses = 0
|
||||||
@building = {}
|
@building = {}
|
||||||
|
@nbuilt = 0
|
||||||
|
|
||||||
execute: (opts) =>
|
execute: (opts) =>
|
||||||
|
if @nparallel == 1
|
||||||
|
return (SingleProcessExecutor @dag, 1)\execute opts
|
||||||
|
|
||||||
block = @dag\buildablenodes!
|
block = @dag\buildablenodes!
|
||||||
while #block != 0
|
while #block != 0
|
||||||
for node in *block
|
for node in *block
|
||||||
@@ -36,10 +41,16 @@ class Executor
|
|||||||
for name, node in pairs @dag.nodes
|
for name, node in pairs @dag.nodes
|
||||||
error "Node #{name} wasn't built" unless node.built
|
error "Node #{name} wasn't built" unless node.built
|
||||||
|
|
||||||
|
unless opts.quiet
|
||||||
|
if @nbuilt == 0
|
||||||
|
print "Nothing to be done"
|
||||||
|
else
|
||||||
|
print "Built #{@nbuilt} targets"
|
||||||
|
|
||||||
addprocess: (node, opts) =>
|
addprocess: (node, opts) =>
|
||||||
if node.sync
|
if node.sync
|
||||||
while @nprocesses != 0
|
while @nprocesses != 0
|
||||||
@waitprocess
|
@waitprocess!
|
||||||
node\build opts
|
node\build opts
|
||||||
node.built = true
|
node.built = true
|
||||||
node\updatecache!
|
node\updatecache!
|
||||||
@@ -52,18 +63,20 @@ class Executor
|
|||||||
@nprocesses += 1
|
@nprocesses += 1
|
||||||
@building[node] = true
|
@building[node] = true
|
||||||
else
|
else
|
||||||
ok, err = pcall -> node\build opts
|
ok, status = pcall -> node\build opts
|
||||||
if ok
|
if ok
|
||||||
|
_exit status and 0 or 2
|
||||||
_exit 0
|
_exit 0
|
||||||
else
|
else
|
||||||
stderr\write err
|
stderr\write status
|
||||||
_exit 1
|
_exit 1
|
||||||
|
|
||||||
waitprocess: =>
|
waitprocess: =>
|
||||||
pid, ty, status = wait!
|
pid, ty, status = wait!
|
||||||
error "Failed to wait" unless pid
|
error "Failed to wait" unless pid
|
||||||
error "Failed to build #{@processes[pid].name}" if ty != 'exited' or status != 0
|
error "Failed to build #{@processes[pid].name}" if ty != 'exited' or status != 0 and status != 2
|
||||||
@processes[pid].built = true
|
@processes[pid].built = true
|
||||||
@processes[pid]\updatecache!
|
@processes[pid]\updatecache!
|
||||||
@processes[pid] = nil
|
@processes[pid] = nil
|
||||||
@nprocesses -= 1
|
@nprocesses -= 1
|
||||||
|
@nbuilt += 1 if status == 0
|
||||||
|
|||||||
@@ -4,13 +4,21 @@ class Executor
|
|||||||
new: (@dag, @nparallel) =>
|
new: (@dag, @nparallel) =>
|
||||||
|
|
||||||
execute: (opts) =>
|
execute: (opts) =>
|
||||||
|
nbuilt = 0
|
||||||
|
|
||||||
block = @dag\buildablenodes!
|
block = @dag\buildablenodes!
|
||||||
while #block != 0
|
while #block != 0
|
||||||
for node in *block
|
for node in *block
|
||||||
node\build opts
|
nbuilt +=1 if node\build opts
|
||||||
node\updatecache!
|
node\updatecache!
|
||||||
node.built = true
|
node.built = true
|
||||||
block = @dag\buildablenodes!
|
block = @dag\buildablenodes!
|
||||||
|
|
||||||
for name, node in pairs @dag.nodes
|
for name, node in pairs @dag.nodes
|
||||||
error "Node #{name} wasn't built" unless node.built
|
error "Node #{name} wasn't built" unless node.built
|
||||||
|
|
||||||
|
unless opts.quiet
|
||||||
|
if nbuilt == 0
|
||||||
|
print "Nothing to be done"
|
||||||
|
else
|
||||||
|
print "Built #{nbuilt} targets"
|
||||||
|
|||||||
Vendored
+7
-3
@@ -1,5 +1,6 @@
|
|||||||
Target = require 'moonbuild.core.Target'
|
Target = require 'moonbuild.core.Target'
|
||||||
Variable = require 'moonbuild.core.Variable'
|
Variable = require 'moonbuild.core.Variable'
|
||||||
|
Pipeline = require 'moonbuild.core.Pipeline'
|
||||||
_ = require 'moonbuild._'
|
_ = require 'moonbuild._'
|
||||||
import flatten from _
|
import flatten from _
|
||||||
|
|
||||||
@@ -18,10 +19,10 @@ import flatten from _
|
|||||||
rawset env, '_G', env
|
rawset env, '_G', env
|
||||||
rawset env, '_ENV', env
|
rawset env, '_ENV', env
|
||||||
|
|
||||||
rawset env, 'var', (name, ...) ->
|
rawset env, 'var', (...) ->
|
||||||
var = Variable name, ...
|
var = Variable ...
|
||||||
ctx\addvar var
|
ctx\addvar var
|
||||||
rawset varlayer, name, var.value
|
rawset varlayer, var.name, var.value
|
||||||
var
|
var
|
||||||
|
|
||||||
rawset env, 'target', (name, opts) ->
|
rawset env, 'target', (name, opts) ->
|
||||||
@@ -29,4 +30,7 @@ import flatten from _
|
|||||||
ctx\addtarget target
|
ctx\addtarget target
|
||||||
target
|
target
|
||||||
|
|
||||||
|
rawset env, 'pipeline', ->
|
||||||
|
Pipeline ctx
|
||||||
|
|
||||||
env, varlayer
|
env, varlayer
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
import loadfile from require 'moonscript.base'
|
||||||
|
Context = require 'moonbuild.context'
|
||||||
|
DepGraph = require 'moonbuild.core.DAG'
|
||||||
|
Executor = require 'moonbuild.core.executor'
|
||||||
|
_ = require 'moonbuild._'
|
||||||
|
import insert from table
|
||||||
|
|
||||||
|
moonbuild = (...) ->
|
||||||
|
-- build argument table
|
||||||
|
opts = {}
|
||||||
|
for i=1, select '#', ...
|
||||||
|
arg = select i, ...
|
||||||
|
if (type arg) == 'string'
|
||||||
|
insert opts, arg
|
||||||
|
elseif (type arg) == 'table'
|
||||||
|
for k, v in pairs arg
|
||||||
|
opts[k] = v if (type k) != 'number'
|
||||||
|
for i, v in ipairs arg
|
||||||
|
insert opts, v
|
||||||
|
else
|
||||||
|
error "Invalid argument type #{type arg} for moonbuild"
|
||||||
|
|
||||||
|
-- resolve arguments
|
||||||
|
buildfile = opts.buildfile or opts.b or 'Build.moon'
|
||||||
|
opts.buildfile = buildfile
|
||||||
|
parallel = opts.parallel or opts.j or 1
|
||||||
|
parallel = true if parallel == 'y'
|
||||||
|
opts.parallel = parallel
|
||||||
|
quiet = opts.quiet or opts.q or false
|
||||||
|
opts.quiet = quiet
|
||||||
|
force = opts.force or opts.f or false
|
||||||
|
opts.force = force
|
||||||
|
verbose = opts.verbose or opts.v or false
|
||||||
|
opts.verbose = verbose
|
||||||
|
|
||||||
|
-- create context and DAG
|
||||||
|
ctx = Context!
|
||||||
|
ctx\load (loadfile buildfile), opts
|
||||||
|
print "Loaded buildfile" if verbose
|
||||||
|
ctx\init!
|
||||||
|
print "Initialized buildfile" if verbose
|
||||||
|
targets = #opts==0 and ctx.defaulttargets or opts
|
||||||
|
dag = DepGraph ctx, targets
|
||||||
|
print "Created dependancy graph" if verbose
|
||||||
|
|
||||||
|
-- and build
|
||||||
|
nparallel = parallel == true and Executor\getmaxparallel! or parallel
|
||||||
|
print "Building with #{nparallel} max parallel process#{nparallel>1 and "es" or ""}" if verbose
|
||||||
|
executor = Executor dag, nparallel
|
||||||
|
executor\execute opts
|
||||||
|
print "Finished" if verbose
|
||||||
|
|
||||||
|
table = {
|
||||||
|
:moonbuild, :_
|
||||||
|
:Context, :DepGraph, :Executor
|
||||||
|
}
|
||||||
|
|
||||||
|
setmetatable table,
|
||||||
|
__call: (...) => moonbuild ...
|
||||||
|
__index: (name) => require "moonbuild.#{name}"
|
||||||
+12
-2522
File diff suppressed because it is too large
Load Diff
+2821
File diff suppressed because it is too large
Load Diff
@@ -22,3 +22,5 @@ build:
|
|||||||
install:
|
install:
|
||||||
bin:
|
bin:
|
||||||
moonbuild: out/moonbuild
|
moonbuild: out/moonbuild
|
||||||
|
modules:
|
||||||
|
moonbuild: out/moonbuild.lua
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
build = {
|
||||||
|
install = {
|
||||||
|
bin = {
|
||||||
|
moonbuild = "out/moonbuild"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
type = "builtin"
|
||||||
|
}
|
||||||
|
dependencies = {
|
||||||
|
"lua >= 5.1",
|
||||||
|
"argparse >= 0.7.1-1",
|
||||||
|
"moonscript >= 0.5.0-1"
|
||||||
|
}
|
||||||
|
description = {
|
||||||
|
detailed = "moonbuild is a small build system that simplifies your build definitions by allowing you to use declarative as well as imperative rules. It represents the build as a DAG with explicit ordering, and doesn't give you any default confusing rules (unlike make). If you can, installing luaposix and/or luafilesystem will speed up builds and increase stability.\n",
|
||||||
|
summary = "Small build system in between make and a build.sh"
|
||||||
|
}
|
||||||
|
package = "moonbuild"
|
||||||
|
rockspec_format = "3.0"
|
||||||
|
source = {
|
||||||
|
tag = "v2.1.2",
|
||||||
|
url = "git://github.com/natnat-mc/moonbuild"
|
||||||
|
}
|
||||||
|
version = "2.1.2-2"
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
build = {
|
||||||
|
install = {
|
||||||
|
bin = {
|
||||||
|
moonbuild = "out/moonbuild"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
type = "builtin"
|
||||||
|
}
|
||||||
|
dependencies = {
|
||||||
|
"lua >= 5.1",
|
||||||
|
"argparse >= 0.7.1-1",
|
||||||
|
"moonscript >= 0.5.0-1"
|
||||||
|
}
|
||||||
|
description = {
|
||||||
|
detailed = "moonbuild is a small build system that simplifies your build definitions by allowing you to use declarative as well as imperative rules. It represents the build as a DAG with explicit ordering, and doesn't give you any default confusing rules (unlike make). If you can, installing luaposix and/or luafilesystem will speed up builds and increase stability.\n",
|
||||||
|
summary = "Small build system in between make and a build.sh"
|
||||||
|
}
|
||||||
|
package = "moonbuild"
|
||||||
|
rockspec_format = "3.0"
|
||||||
|
source = {
|
||||||
|
tag = "v2.1.3",
|
||||||
|
url = "git://github.com/natnat-mc/moonbuild"
|
||||||
|
}
|
||||||
|
version = "2.1.3-1"
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
build = {
|
||||||
|
install = {
|
||||||
|
bin = {
|
||||||
|
moonbuild = "out/moonbuild"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
type = "builtin"
|
||||||
|
}
|
||||||
|
dependencies = {
|
||||||
|
"lua >= 5.1",
|
||||||
|
"argparse >= 0.7.1-1",
|
||||||
|
"moonscript >= 0.5.0-1"
|
||||||
|
}
|
||||||
|
description = {
|
||||||
|
detailed = "moonbuild is a small build system that simplifies your build definitions by allowing you to use declarative as well as imperative rules. It represents the build as a DAG with explicit ordering, and doesn't give you any default confusing rules (unlike make). If you can, installing luaposix and/or luafilesystem will speed up builds and increase stability.\n",
|
||||||
|
summary = "Small build system in between make and a build.sh"
|
||||||
|
}
|
||||||
|
package = "moonbuild"
|
||||||
|
rockspec_format = "3.0"
|
||||||
|
source = {
|
||||||
|
tag = "v2.1.3",
|
||||||
|
url = "git://github.com/natnat-mc/moonbuild"
|
||||||
|
}
|
||||||
|
version = "2.1.3-2"
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
build = {
|
||||||
|
install = {
|
||||||
|
bin = {
|
||||||
|
moonbuild = "out/moonbuild"
|
||||||
|
},
|
||||||
|
modules = {
|
||||||
|
moonbuild = "out/moonbuild.lua"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
type = "builtin"
|
||||||
|
}
|
||||||
|
dependencies = {
|
||||||
|
"lua >= 5.1",
|
||||||
|
"argparse >= 0.7.1-1",
|
||||||
|
"moonscript >= 0.5.0-1"
|
||||||
|
}
|
||||||
|
description = {
|
||||||
|
detailed = "moonbuild is a small build system that simplifies your build definitions by allowing you to use declarative as well as imperative rules. It represents the build as a DAG with explicit ordering, and doesn't give you any default confusing rules (unlike make). If you can, installing luaposix and/or luafilesystem will speed up builds and increase stability.\n",
|
||||||
|
summary = "Small build system in between make and a build.sh"
|
||||||
|
}
|
||||||
|
package = "moonbuild"
|
||||||
|
rockspec_format = "3.0"
|
||||||
|
source = {
|
||||||
|
tag = "v2.2.0",
|
||||||
|
url = "git://github.com/natnat-mc/moonbuild"
|
||||||
|
}
|
||||||
|
version = "2.2.0-1"
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
build = {
|
||||||
|
install = {
|
||||||
|
bin = {
|
||||||
|
moonbuild = "out/moonbuild"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
modules = {
|
||||||
|
moonbuild = "out/moonbuild.lua"
|
||||||
|
},
|
||||||
|
type = "builtin"
|
||||||
|
}
|
||||||
|
dependencies = {
|
||||||
|
"lua >= 5.1",
|
||||||
|
"argparse >= 0.7.1-1",
|
||||||
|
"moonscript >= 0.5.0-1"
|
||||||
|
}
|
||||||
|
description = {
|
||||||
|
detailed = "moonbuild is a small build system that simplifies your build definitions by allowing you to use declarative as well as imperative rules. It represents the build as a DAG with explicit ordering, and doesn't give you any default confusing rules (unlike make). If you can, installing luaposix and/or luafilesystem will speed up builds and increase stability.\n",
|
||||||
|
summary = "Small build system in between make and a build.sh"
|
||||||
|
}
|
||||||
|
package = "moonbuild"
|
||||||
|
rockspec_format = "3.0"
|
||||||
|
source = {
|
||||||
|
tag = "v2.2.0",
|
||||||
|
url = "git://github.com/natnat-mc/moonbuild"
|
||||||
|
}
|
||||||
|
version = "2.2.0-2"
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
build = {
|
||||||
|
install = {
|
||||||
|
bin = {
|
||||||
|
moonbuild = "out/moonbuild"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
modules = {
|
||||||
|
moonbuild = "out/moonbuild.lua"
|
||||||
|
},
|
||||||
|
type = "builtin"
|
||||||
|
}
|
||||||
|
dependencies = {
|
||||||
|
"lua >= 5.1",
|
||||||
|
"argparse >= 0.7.1-1",
|
||||||
|
"moonscript >= 0.5.0-1"
|
||||||
|
}
|
||||||
|
description = {
|
||||||
|
detailed = "moonbuild is a small build system that simplifies your build definitions by allowing you to use declarative as well as imperative rules. It represents the build as a DAG with explicit ordering, and doesn't give you any default confusing rules (unlike make). If you can, installing luaposix and/or luafilesystem will speed up builds and increase stability.\n",
|
||||||
|
summary = "Small build system in between make and a build.sh"
|
||||||
|
}
|
||||||
|
package = "moonbuild"
|
||||||
|
rockspec_format = "3.0"
|
||||||
|
source = {
|
||||||
|
tag = "v2.2.1",
|
||||||
|
url = "git://github.com/natnat-mc/moonbuild"
|
||||||
|
}
|
||||||
|
version = "2.2.1-1"
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
build = {
|
||||||
|
install = {
|
||||||
|
bin = {
|
||||||
|
moonbuild = "out/moonbuild"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
modules = {
|
||||||
|
moonbuild = "out/moonbuild.lua"
|
||||||
|
},
|
||||||
|
type = "builtin"
|
||||||
|
}
|
||||||
|
dependencies = {
|
||||||
|
"lua >= 5.1",
|
||||||
|
"argparse >= 0.7.1-1",
|
||||||
|
"moonscript >= 0.5.0-1"
|
||||||
|
}
|
||||||
|
description = {
|
||||||
|
detailed = "moonbuild is a small build system that simplifies your build definitions by allowing you to use declarative as well as imperative rules. It represents the build as a DAG with explicit ordering, and doesn't give you any default confusing rules (unlike make). If you can, installing luaposix and/or luafilesystem will speed up builds and increase stability.\n",
|
||||||
|
summary = "Small build system in between make and a build.sh"
|
||||||
|
}
|
||||||
|
package = "moonbuild"
|
||||||
|
rockspec_format = "3.0"
|
||||||
|
source = {
|
||||||
|
tag = "v2.2.2",
|
||||||
|
url = "git://github.com/natnat-mc/moonbuild"
|
||||||
|
}
|
||||||
|
version = "2.2.2-1"
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
build = {
|
||||||
|
install = {
|
||||||
|
bin = {
|
||||||
|
moonbuild = "out/moonbuild"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
modules = {
|
||||||
|
moonbuild = "out/moonbuild.lua"
|
||||||
|
},
|
||||||
|
type = "builtin"
|
||||||
|
}
|
||||||
|
dependencies = {
|
||||||
|
"lua >= 5.1",
|
||||||
|
"argparse >= 0.7.1-1",
|
||||||
|
"moonscript >= 0.5.0-1"
|
||||||
|
}
|
||||||
|
description = {
|
||||||
|
detailed = "moonbuild is a small build system that simplifies your build definitions by allowing you to use declarative as well as imperative rules. It represents the build as a DAG with explicit ordering, and doesn't give you any default confusing rules (unlike make). If you can, installing luaposix and/or luafilesystem will speed up builds and increase stability.\n",
|
||||||
|
summary = "Small build system in between make and a build.sh"
|
||||||
|
}
|
||||||
|
package = "moonbuild"
|
||||||
|
rockspec_format = "3.0"
|
||||||
|
source = {
|
||||||
|
tag = "v2.2.2",
|
||||||
|
url = "git://github.com/natnat-mc/moonbuild"
|
||||||
|
}
|
||||||
|
version = "2.2.2-2"
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
build = {
|
||||||
|
install = {
|
||||||
|
bin = {
|
||||||
|
moonbuild = "out/moonbuild"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
modules = {
|
||||||
|
moonbuild = "out/moonbuild.lua"
|
||||||
|
},
|
||||||
|
type = "builtin"
|
||||||
|
}
|
||||||
|
dependencies = {
|
||||||
|
"lua >= 5.1",
|
||||||
|
"argparse >= 0.7.1-1",
|
||||||
|
"moonscript >= 0.5.0-1"
|
||||||
|
}
|
||||||
|
description = {
|
||||||
|
detailed = "moonbuild is a small build system that simplifies your build definitions by allowing you to use declarative as well as imperative rules. It represents the build as a DAG with explicit ordering, and doesn't give you any default confusing rules (unlike make). If you can, installing luaposix and/or luafilesystem will speed up builds and increase stability.\n",
|
||||||
|
summary = "Small build system in between make and a build.sh"
|
||||||
|
}
|
||||||
|
package = "moonbuild"
|
||||||
|
rockspec_format = "3.0"
|
||||||
|
source = {
|
||||||
|
tag = "v2.3.0",
|
||||||
|
url = "git://github.com/natnat-mc/moonbuild"
|
||||||
|
}
|
||||||
|
version = "2.3.0-1"
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
build = {
|
||||||
|
install = {
|
||||||
|
bin = {
|
||||||
|
moonbuild = "out/moonbuild"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
modules = {
|
||||||
|
moonbuild = "out/moonbuild.lua"
|
||||||
|
},
|
||||||
|
type = "builtin"
|
||||||
|
}
|
||||||
|
dependencies = {
|
||||||
|
"lua >= 5.1",
|
||||||
|
"argparse >= 0.7.1-1",
|
||||||
|
"moonscript >= 0.5.0-1"
|
||||||
|
}
|
||||||
|
description = {
|
||||||
|
detailed = "moonbuild is a small build system that simplifies your build definitions by allowing you to use declarative as well as imperative rules. It represents the build as a DAG with explicit ordering, and doesn't give you any default confusing rules (unlike make). If you can, installing luaposix and/or luafilesystem will speed up builds and increase stability.\n",
|
||||||
|
summary = "Small build system in between make and a build.sh"
|
||||||
|
}
|
||||||
|
package = "moonbuild"
|
||||||
|
rockspec_format = "3.0"
|
||||||
|
source = {
|
||||||
|
tag = "v2.3.0",
|
||||||
|
url = "git://github.com/natnat-mc/moonbuild"
|
||||||
|
}
|
||||||
|
version = "2.3.0-2"
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
build = {
|
||||||
|
install = {
|
||||||
|
bin = {
|
||||||
|
moonbuild = "out/moonbuild"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
modules = {
|
||||||
|
moonbuild = "out/moonbuild.lua"
|
||||||
|
},
|
||||||
|
type = "builtin"
|
||||||
|
}
|
||||||
|
dependencies = {
|
||||||
|
"lua >= 5.1",
|
||||||
|
"argparse >= 0.7.1-1",
|
||||||
|
"moonscript >= 0.5.0-1"
|
||||||
|
}
|
||||||
|
description = {
|
||||||
|
detailed = "moonbuild is a small build system that simplifies your build definitions by allowing you to use declarative as well as imperative rules. It represents the build as a DAG with explicit ordering, and doesn't give you any default confusing rules (unlike make). If you can, installing luaposix and/or luafilesystem will speed up builds and increase stability.\n",
|
||||||
|
summary = "Small build system in between make and a build.sh"
|
||||||
|
}
|
||||||
|
package = "moonbuild"
|
||||||
|
rockspec_format = "3.0"
|
||||||
|
source = {
|
||||||
|
tag = "v2.4.0",
|
||||||
|
url = "git://github.com/natnat-mc/moonbuild"
|
||||||
|
}
|
||||||
|
version = "2.4.0-1"
|
||||||
Reference in New Issue
Block a user