1
0
mirror of https://github.com/natnat-mc/moonbuild synced 2026-05-28 04:59:41 +02:00

17 Commits

Author SHA1 Message Date
codinget f20dd6a777 Producing rockspec 2.7.1-1 2022-05-20 16:48:04 +02:00
codinget 775d689e0a improved verbose 2022-05-20 16:47:47 +02:00
codinget 9450ec9c9d Producing rockspec 2.7.0-1 2022-05-20 16:32:09 +02:00
codinget de7ab2ddbf add echo to _.cmd _.cmdrst _.sh _.moonc when verbose 2022-05-20 16:31:47 +02:00
codinget 37ab4f2299 Producing rockspec 2.6.0-1 2022-05-20 15:48:07 +02:00
codinget 4cd18877a9 moved to git+http protocol due to github killing the base git proto 2022-05-20 15:47:35 +02:00
codinget 67eb978e43 add resolve tree in failed resolution errors, closes #24 2022-05-20 15:25:46 +02:00
Codinget f51be8631b added .gitattributes 2021-06-04 23:17:42 +02:00
Codinget 715aa2ebb7 Producing rockspec 2.5.1-1 2021-01-10 23:24:31 +01:00
Codinget bed119a40c added watcher to Alfons.moon 2021-01-10 22:43:18 +01:00
Codinget 57126a7973 fixed mkdirs sometimes failing due to race condition when multiprocess builds are running 2021-01-10 22:19:10 +01:00
Codinget cd9b0ab159 Producing rockspec 2.5.0-1 2020-12-02 02:49:11 +01:00
Codinget 678313d09f added pipelines, closes #18 2020-12-02 02:48:36 +01:00
Codinget ebd380fb0f Producing rockspec 2.4.0-1 2020-12-01 22:06:32 +01:00
Codinget 803d1093bb added table syntax for var, closes #19 2020-12-01 22:05:04 +01:00
Codinget ec5fc1cf7d added @in (but not working due to moonscript bug) and @out 2020-12-01 21:43:04 +01:00
Codinget 17578bb721 Producing rockspec 2.3.0-2 2020-12-01 21:35:49 +01:00
26 changed files with 700 additions and 157 deletions
+3
View File
@@ -0,0 +1,3 @@
*.lua linguist-generated
out/* linguist-generated
Makefile -linguist-detectable
+1
View File
@@ -7,6 +7,7 @@ tasks:
tasks.build!
sh "rockbuild -m -t #{@v} upload"
watch: => watch {'.'}, {'.git'}, 'live', (glob '*.moon'), pcall -> moonbuild j: true
build: => moonbuild j: true
install: => moonbuild 'install', j: true
clean: => moonbuild 'clean'
+31 -36
View File
@@ -1,17 +1,16 @@
public var 'MOONC', 'moonc'
public var 'AMALG', 'amalg.lua'
public var 'RM', 'rm', '-f', '--'
public var 'LUA', 'lua5.3'
public var AMALG: 'amalg.lua'
public var RM: 'rm', '-f', '--'
public var LUA: 'lua5.3'
var 'LIB_SRC', _.wildcard 'moonbuild/**.moon'
var 'BIN_SRC', _.wildcard 'bin/*.moon'
var LIB_SRC: _.wildcard 'moonbuild/**.moon'
var BIN_SRC: _.wildcard 'bin/*.moon'
var 'LIB_LUA', _.patsubst LIB_SRC, '%.moon', '%.lua'
var 'BIN_LUA', _.patsubst BIN_SRC, '%.moon', '%.lua'
var 'BIN', _.patsubst BIN_LUA, 'bin/%.lua', 'out/%'
var 'LIB', 'out/moonbuild.lua'
var LIB_LUA: _.patsubst LIB_SRC, '%.moon', '%.lua'
var BIN_LUA: _.patsubst BIN_SRC, '%.moon', '%.lua'
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'
\after 'bin'
@@ -24,13 +23,13 @@ with public target 'install'
with public target 'install-bin'
\depends BIN
\produces _.patsubst BIN, 'out/%', '/usr/local/bin/%'
\fn => _.cmd 'sudo', 'cp', @infile, @outfile
\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, @outfile
\fn => _.cmd 'sudo', 'cp', @infile, @out
\sync!
with public target 'clean'
@@ -41,27 +40,23 @@ with public target 'mrproper'
\after 'clean'
\fn => _.cmd RM, BIN, LIB
with public target 'bin'
\depends BIN
with pipeline! -- lib
\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'
\depends LIB_LUA, LIB
with target BIN, pattern: 'out/%'
\depends 'bin/%.lua'
\produces 'out/%'
\mkdirs!
\fn =>
_.writefile @outfile, "#!/usr/bin/env #{LUA}\n#{_.readfile @infile}"
_.cmd 'chmod', '+x', @outfile
with target LIB
\depends 'moonbuild/init.lua'
\depends LIB_LUA
\produces '%'
\fn => _.cmd AMALG, '-o', @outfile, '-s', @infile, _.exclude MODULES, 'moonbuild.init'
with target {LIB_LUA, BIN_LUA}, pattern: '%.lua'
\depends '%.moon'
\produces '%.lua'
\fn => _.moonc @infile, @outfile
with pipeline! -- bin
\sources BIN_SRC
\step 'compile-bin'
pattern: {'%.moon', '%.lua'}
fn: => _.moonc @infile, @out
\step 'bin'
pattern: {'bin/%.lua', 'out/%'}
mkdirs: true
fn: =>
_.writefile @out, "#!/usr/bin/env #{LUA}\n#{_.readfile @infile}"
_.cmd 'chmod', '+x', @out
+10 -8
View File
@@ -1,8 +1,9 @@
-- load everything we need
import loadfile from require 'moonscript.base'
import Context, DepGraph, Executor from require 'moonbuild'
Variable = (require 'moonbuild')['core.Variable']
import parseargs from (require 'moonbuild')['_cmd.common']
Variable = require 'moonbuild.core.Variable'
import verbose from require 'moonbuild._common'
import parseargs from require 'moonbuild._cmd.common'
argparse = require 'argparse'
import sort, concat from table
import exit from os
@@ -34,12 +35,13 @@ for set in *args.set_list
args.parallel = args.parallel == 'y' and 'y' or ((tonumber args.parallel) or error "Invalid argument for -j: #{args.parallel}")
error "Invalid argument for -j: #{args.parallel}" if args.parallel != 'y' and (args.parallel<1 or args.parallel%1 != 0)
print "Parsed CLI args" if args.verbose
verbose args.verbose or false
verbose "Parsed CLI args"
-- load the buildfile
ctx = Context!
ctx\load (loadfile args.buildfile), overrides
print "Loaded buildfile" if args.verbose
verbose "Loaded buildfile"
-- handle -l and -V
if args.list
@@ -65,16 +67,16 @@ if args.list_variables
-- initialize the buildfile further
ctx\init!
print "Initialized buildfile" if args.verbose
verbose "Initialized buildfile"
-- create the DAG
targets = #args.targets==0 and ctx.defaulttargets or args.targets
dag = DepGraph ctx, targets
print "Created dependancy graph" if args.verbose
verbose print "Created dependancy graph"
-- execute the build
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
verbose "Building with #{nparallel} max parallel process#{nparallel>1 and "es" or ""}"
executor = Executor dag, nparallel
executor\execute args
print "Finished" if args.verbose
verbose "Finished"
+13 -1
View File
@@ -1,4 +1,5 @@
import parseargs, escape from require 'moonbuild._cmd.common'
import parseargs, escape, cmdline from require 'moonbuild._cmd.common'
import verbose from require 'moonbuild._common'
ok, cmd, backend = false, nil, nil
unless ok
@@ -17,6 +18,17 @@ cmd.backend = backend
cmd.parseargs = parseargs
cmd.escape = escape
-- make verbose verisons of _.cmd, _.cmdrst and _.sh
for f in *({'cmd', 'cmdrst'})
orig = cmd[f]
cmd[f] = (...) ->
verbose "[#{f}] #{cmdline ...}"
orig ...
_sh = cmd.sh
cmd.sh = (cli) ->
verbose "[sh] #{cli}"
_sh cli
-- derived cmd functions
_cmd = cmd.cmd
_cmdrst = cmd.cmdrst
+5
View File
@@ -1,5 +1,6 @@
import gsub, sub, match from string
import concat from table
import flatten from require 'moonbuild._common'
specialchars =
'\"': '\\\"'
@@ -115,7 +116,11 @@ parseargs = (argstr) ->
args
cmdline = (...) ->
concat [escape arg for arg in *flatten ...], ' '
{
:escape
:parseargs
:cmdline
}
+2 -4
View File
@@ -1,12 +1,9 @@
import escape from require 'moonbuild._cmd.common'
import cmdline from require 'moonbuild._cmd.common'
import flatten from require 'moonbuild._common'
import execute from require 'moonbuild.compat.execute'
import popen from io
import concat from table
cmdline = (...) ->
concat [escape arg for arg in *flatten ...], ' '
cmd = (...) ->
ok, ret, code = execute cmdline ...
error "command #{first ...} exited with #{code} (#{ret})" unless ok
@@ -19,6 +16,7 @@ cmdrst = (...) ->
data
sh = (cli) ->
verbose -> print '[sh] ' .. cli
ok, ret, code = execute cli
error "command '#{cli}' exited with #{code} (#{ret})" unless ok
+1
View File
@@ -37,6 +37,7 @@ cmdrst = (...) ->
data
sh = (cli) ->
verbose -> print '[sh] ' .. cli
cmd 'sh', '-c', cli
{
+14
View File
@@ -147,6 +147,19 @@ minmax = (list) ->
M = e if e>M
m, M
_verbose = false
verbose = (arg) ->
if arg == nil
_verbose
elseif (type arg) == 'function'
arg! if _verbose
elseif (type arg) == 'boolean'
_verbose = arg
elseif (type arg) == 'string'
print arg if _verbose
else
error "_.verbose takes either no argument, a boolean, a function or a string"
common.flatten = flatten
common.first = first
common.foreach = foreach
@@ -159,5 +172,6 @@ common.exclude = exclude
common.min = min
common.max = max
common.minmax = minmax
common.verbose = verbose
setmetatable common, __call: => [k for k in pairs common]
+9 -3
View File
@@ -166,10 +166,16 @@ mkdir = (dir) ->
clearentry parent dir
mkdirs = (dir) ->
return if isdir dir
error "Can't mkdirs #{dir}: file exists" if exists dir
if attr = attributes normalizepath dir
return if attr.mode == 'directory'
error "Can't mkdirs #{dir}: file exists"
mkdirs parent dir
mkdir dir
unless pcall -> actualmkdir dir
clearentry parent dir
clearentry dir
error "Failed to mkdirs #{dir}: last mkdir failed" unless isdir dir
clearentry parent dir
clearentry dir
-- from the backend
fs = {k, withcache fn for k, fn in pairs fs}
+2
View File
@@ -1,5 +1,6 @@
import to_lua from require 'moonscript.base'
import parseargs, cmdrst from require 'moonbuild._cmd'
import verbose from require 'moonbuild._common'
import gmatch, match, gsub from string
import open from io
@@ -34,6 +35,7 @@ writefile = (filename, data) ->
nil
moonc = (infile, outfile) ->
verbose "[moonc] #{infile} #{outfile}"
code, err = to_lua readfile infile
error "Failed to compile #{@infile}: #{err}" unless code
writefile outfile, code
+34 -12
View File
@@ -56,22 +56,44 @@ class DepGraph
addnode: (name) =>
return if @nodes[name]
elected = @resolvedeps name
elected = @topresolvedeps name
@nodes[name] = elected
for dep in *(transclosure elected, 'deps')
@nodes[dep.name] = dep
dep.deps = nil
elected.deps = nil
resolvedeps: (name) =>
topresolvedeps: (name) =>
errors = {}
ok, rst = pcall -> @resolvedeps name, nil, errors
if ok
rst
else
msg = {"Failed to resolve target \'#{name}\'\n"}
for e in *errors
if e.err\match '^moonbuild'
e.err = e.err\match ': (.+)$'
for i=#errors, 1, -1
e = errors[i]
insert msg, "#{string.rep '| ', e.level - 1}+-[#{e.name}] level #{e.level}: #{e.err}"
insert msg, ''
error table.concat msg, '\n'
resolvedeps: (name, level=1, errors={}) =>
do
node = @nodes[name]
return node, {} if node
if node
print "deps(#{name}) = #{node.name or '[noname]'}"
return node, {}
candidates = filter {@ctx.targets, FileTarget!}, (target) -> target\matches name
nodes = foreach candidates, (candidate) -> a: {pcall -> DepNode @, candidate, name}
nodes = foreach candidates, (candidate) -> a: {pcall -> DepNode @, candidate, name, level, errors}
resolved = foreach (filter nodes, (node) -> node.a[1]), (node) -> node.a[2]
sort resolved, nodepriority
resolved[1] or error "Cannot resolve target #{name}: #{#candidates} candidates, #{#resolved} resolved"
unless resolved[1]
err = "Cannot resolve target #{name}: #{#candidates} candidates, #{#resolved} resolved"
table.insert errors, {:name, :level, :err}
error err
resolved[1]
buildablenodes: =>
[v for k, v in pairs @nodes when v\canbuild! and not v.built]
@@ -91,7 +113,7 @@ class DepGraph
insert stack, n for n in *(node\children!)
class DepNode
new: (@dag, target, @name) =>
new: (@dag, target, @name, @level, errors) =>
@priority = target.priority
@buildfunctions = target.buildfunctions
@mkdirs = target._mkdirs
@@ -101,19 +123,19 @@ class DepNode
@type = 'virtual' if #@outs == 0
@built = false
resolve = (name) -> @dag\resolvedeps patsubst @name, target.pattern, name
resolve = (name) -> @dag\resolvedeps (patsubst @name, target.pattern, name), level + 1, errors
after = flatten foreach target.needtargets, resolve
deps = flatten foreach target.infiles, resolve
if #target.depfunctions!=0
ctx = setmetatable {},
__index: (_, k) ->
switch k
when 'infile'
when 'infile', 'in'
f = first deps
f and f.name
when 'infiles'
foreach deps, => @name
when 'outfile'
when 'outfile', 'out'
f = first @outs
f and f.name
when 'outfiles'
@@ -149,7 +171,7 @@ class DepNode
return false if @built or #@buildfunctions == 0
return false unless force or @shouldbuild!
print "#{@type == 'virtual' and "Running" or "Building"} #{@name}" unless quiet
print "#{@type == 'virtual' and "Running" or "Building"} #{@name} [level #{@level}]" unless quiet
@actuallybuild!
true
@@ -182,9 +204,9 @@ class DepNode
ctx = setmetatable {},
__index: (_, k) ->
switch k
when 'infile' then @ins[1]
when 'infile', 'in' then @ins[1]
when 'infiles' then @ins
when 'outfile' then @outs[1]
when 'outfile', 'out' then @outs[1]
when 'outfiles' then @outs
when 'name' then @name
else error "No such field in TargetContext: #{k}"
+56
View File
@@ -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
+11 -1
View File
@@ -4,7 +4,17 @@ class Variable
new: (@name, ...) =>
@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 ...
else
@value = ...
+7 -3
View File
@@ -1,5 +1,6 @@
Target = require 'moonbuild.core.Target'
Variable = require 'moonbuild.core.Variable'
Pipeline = require 'moonbuild.core.Pipeline'
_ = require 'moonbuild._'
import flatten from _
@@ -18,10 +19,10 @@ import flatten from _
rawset env, '_G', env
rawset env, '_ENV', env
rawset env, 'var', (name, ...) ->
var = Variable name, ...
rawset env, 'var', (...) ->
var = Variable ...
ctx\addvar var
rawset varlayer, name, var.value
rawset varlayer, var.name, var.value
var
rawset env, 'target', (name, opts) ->
@@ -29,4 +30,7 @@ import flatten from _
ctx\addtarget target
target
rawset env, 'pipeline', ->
Pipeline ctx
env, varlayer
+8 -5
View File
@@ -33,22 +33,25 @@ moonbuild = (...) ->
verbose = opts.verbose or opts.v or false
opts.verbose = verbose
-- set verbosity level
_.verbose verbose
-- create context and DAG
ctx = Context!
ctx\load (loadfile buildfile), opts
print "Loaded buildfile" if verbose
_.verbose "Loaded buildfile"
ctx\init!
print "Initialized buildfile" if verbose
_.verbose "Initialized buildfile"
targets = #opts==0 and ctx.defaulttargets or opts
dag = DepGraph ctx, targets
print "Created dependancy graph" if verbose
_.verbose "Created dependancy graph"
-- and build
nparallel = parallel == true and Executor\getmaxparallel! or parallel
print "Building with #{nparallel} max parallel process#{nparallel>1 and "es" or ""}" if verbose
_.verbose "Building with #{nparallel} max parallel process#{nparallel>1 and "es" or ""}"
executor = Executor dag, nparallel
executor\execute opts
print "Finished" if verbose
_.verbose "Finished"
table = {
:moonbuild, :_
Generated
+11 -20
View File
@@ -6,9 +6,11 @@ do
local _obj_0 = require('moonbuild')
Context, DepGraph, Executor = _obj_0.Context, _obj_0.DepGraph, _obj_0.Executor
end
local Variable = (require('moonbuild'))['core.Variable']
local Variable = require('moonbuild.core.Variable')
local verbose
verbose = require('moonbuild._common').verbose
local parseargs
parseargs = (require('moonbuild'))['_cmd.common'].parseargs
parseargs = require('moonbuild._cmd.common').parseargs
local argparse = require('argparse')
local sort, concat
do
@@ -55,14 +57,11 @@ args.parallel = args.parallel == 'y' and 'y' or ((tonumber(args.parallel)) or er
if args.parallel ~= 'y' and (args.parallel < 1 or args.parallel % 1 ~= 0) then
error("Invalid argument for -j: " .. tostring(args.parallel))
end
if args.verbose then
print("Parsed CLI args")
end
verbose(args.verbose or false)
verbose("Parsed CLI args")
local ctx = Context()
ctx:load((loadfile(args.buildfile)), overrides)
if args.verbose then
print("Loaded buildfile")
end
verbose("Loaded buildfile")
if args.list then
print("Public targets")
local targets, n = { }, 1
@@ -94,20 +93,12 @@ if args.list_variables then
exit(0)
end
ctx:init()
if args.verbose then
print("Initialized buildfile")
end
verbose("Initialized buildfile")
local targets = #args.targets == 0 and ctx.defaulttargets or args.targets
local dag = DepGraph(ctx, targets)
if args.verbose then
print("Created dependancy graph")
end
verbose(print("Created dependancy graph"))
local nparallel = args.parallel == 'y' and Executor:getmaxparallel() or args.parallel
if args.verbose then
print("Building with " .. tostring(nparallel) .. " max parallel process" .. tostring(nparallel > 1 and "es" or ""))
end
verbose("Building with " .. tostring(nparallel) .. " max parallel process" .. tostring(nparallel > 1 and "es" or ""))
local executor = Executor(dag, nparallel)
executor:execute(args)
if args.verbose then
return print("Finished")
end
return verbose("Finished")
+292 -63
View File
@@ -1,5 +1,3 @@
do
do
local _ENV = _ENV
package.preload[ "moonbuild._" ] = function( ... ) local arg = _G.arg;
@@ -38,11 +36,13 @@ end
do
local _ENV = _ENV
package.preload[ "moonbuild._cmd" ] = function( ... ) local arg = _G.arg;
local parseargs, escape
local parseargs, escape, cmdline
do
local _obj_0 = require('moonbuild._cmd.common')
parseargs, escape = _obj_0.parseargs, _obj_0.escape
parseargs, escape, cmdline = _obj_0.parseargs, _obj_0.escape, _obj_0.cmdline
end
local verbose
verbose = require('moonbuild._common').verbose
local ok, cmd, backend = false, nil, nil
if not (ok) then
ok, cmd = pcall(function()
@@ -69,6 +69,23 @@ end
cmd.backend = backend
cmd.parseargs = parseargs
cmd.escape = escape
local _list_0 = ({
'cmd',
'cmdrst'
})
for _index_0 = 1, #_list_0 do
local f = _list_0[_index_0]
local orig = cmd[f]
cmd[f] = function(...)
verbose("[" .. tostring(f) .. "] " .. tostring(cmdline(...)))
return orig(...)
end
end
local _sh = cmd.sh
cmd.sh = function(cli)
verbose("[sh] " .. tostring(cli))
return _sh(cli)
end
local _cmd = cmd.cmd
local _cmdrst = cmd.cmdrst
cmd.cmdline = function(cmdline)
@@ -101,6 +118,8 @@ do
end
local concat
concat = table.concat
local flatten
flatten = require('moonbuild._common').flatten
local specialchars = {
['\"'] = '\\\"',
['\\'] = '\\\\',
@@ -232,26 +251,6 @@ parseargs = function(argstr)
end
return args
end
return {
escape = escape,
parseargs = parseargs
}
end
end
do
local _ENV = _ENV
package.preload[ "moonbuild._cmd.lua" ] = function( ... ) local arg = _G.arg;
local escape
escape = require('moonbuild._cmd.common').escape
local flatten
flatten = require('moonbuild._common').flatten
local execute
execute = require('moonbuild.compat.execute').execute
local popen
popen = io.popen
local concat
concat = table.concat
local cmdline
cmdline = function(...)
return concat((function(...)
@@ -266,6 +265,27 @@ cmdline = function(...)
return _accum_0
end)(...), ' ')
end
return {
escape = escape,
parseargs = parseargs,
cmdline = cmdline
}
end
end
do
local _ENV = _ENV
package.preload[ "moonbuild._cmd.lua" ] = function( ... ) local arg = _G.arg;
local cmdline
cmdline = require('moonbuild._cmd.common').cmdline
local flatten
flatten = require('moonbuild._common').flatten
local execute
execute = require('moonbuild.compat.execute').execute
local popen
popen = io.popen
local concat
concat = table.concat
local cmd
cmd = function(...)
local ok, ret, code = execute(cmdline(...))
@@ -285,6 +305,9 @@ cmdrst = function(...)
end
local sh
sh = function(cli)
verbose(function()
return print('[sh] ' .. cli)
end)
local ok, ret, code = execute(cli)
if not (ok) then
return error("command '" .. tostring(cli) .. "' exited with " .. tostring(code) .. " (" .. tostring(ret) .. ")")
@@ -356,6 +379,9 @@ cmdrst = function(...)
end
local sh
sh = function(cli)
verbose(function()
return print('[sh] ' .. cli)
end)
return cmd('sh', '-c', cli)
end
return {
@@ -637,6 +663,25 @@ minmax = function(list)
end
return m, M
end
local _verbose = false
local verbose
verbose = function(arg)
if arg == nil then
return _verbose
elseif (type(arg)) == 'function' then
if _verbose then
return arg()
end
elseif (type(arg)) == 'boolean' then
_verbose = arg
elseif (type(arg)) == 'string' then
if _verbose then
return print(arg)
end
else
return error("_.verbose takes either no argument, a boolean, a function or a string")
end
end
common.flatten = flatten
common.first = first
common.foreach = foreach
@@ -649,6 +694,7 @@ common.exclude = exclude
common.min = min
common.max = max
common.minmax = minmax
common.verbose = verbose
return setmetatable(common, {
__call = function(self)
local _accum_0 = { }
@@ -973,14 +1019,27 @@ mkdir = function(dir)
end
local mkdirs
mkdirs = function(dir)
if isdir(dir) then
return
end
if exists(dir) then
error("Can't mkdirs " .. tostring(dir) .. ": file exists")
do
local attr = attributes(normalizepath(dir))
if attr then
if attr.mode == 'directory' then
return
end
error("Can't mkdirs " .. tostring(dir) .. ": file exists")
end
end
mkdirs(parent(dir))
return mkdir(dir)
if not (pcall(function()
return actualmkdir(dir)
end)) then
clearentry(parent(dir))
clearentry(dir)
if not (isdir(dir)) then
error("Failed to mkdirs " .. tostring(dir) .. ": last mkdir failed")
end
end
clearentry(parent(dir))
return clearentry(dir)
end
do
local _tbl_0 = { }
@@ -1249,6 +1308,8 @@ do
local _obj_0 = require('moonbuild._cmd')
parseargs, cmdrst = _obj_0.parseargs, _obj_0.cmdrst
end
local verbose
verbose = require('moonbuild._common').verbose
local gmatch, match, gsub
do
local _obj_0 = string
@@ -1320,6 +1381,7 @@ writefile = function(filename, data)
end
local moonc
moonc = function(infile, outfile)
verbose("[moonc] " .. tostring(infile) .. " " .. tostring(outfile))
local code, err = to_lua(readfile(infile))
if not (code) then
error("Failed to compile " .. tostring(self.infile) .. ": " .. tostring(err))
@@ -1737,7 +1799,7 @@ do
if self.nodes[name] then
return
end
local elected = self:resolvedeps(name)
local elected = self:topresolvedeps(name)
self.nodes[name] = elected
local _list_0 = (transclosure(elected, 'deps'))
for _index_0 = 1, #_list_0 do
@@ -1747,10 +1809,42 @@ do
end
elected.deps = nil
end,
resolvedeps = function(self, name)
topresolvedeps = function(self, name)
local errors = { }
local ok, rst = pcall(function()
return self:resolvedeps(name, nil, errors)
end)
if ok then
return rst
else
local msg = {
"Failed to resolve target \'" .. tostring(name) .. "\'\n"
}
for _index_0 = 1, #errors do
local e = errors[_index_0]
if e.err:match('^moonbuild') then
e.err = e.err:match(': (.+)$')
end
end
for i = #errors, 1, -1 do
local e = errors[i]
insert(msg, tostring(string.rep('| ', e.level - 1)) .. "+-[" .. tostring(e.name) .. "] level " .. tostring(e.level) .. ": " .. tostring(e.err))
end
insert(msg, '')
return error(table.concat(msg, '\n'))
end
end,
resolvedeps = function(self, name, level, errors)
if level == nil then
level = 1
end
if errors == nil then
errors = { }
end
do
local node = self.nodes[name]
if node then
print("deps(" .. tostring(name) .. ") = " .. tostring(node.name or '[noname]'))
return node, { }
end
end
@@ -1764,7 +1858,7 @@ do
return {
a = {
pcall(function()
return DepNode(self, candidate, name)
return DepNode(self, candidate, name, level, errors)
end)
}
}
@@ -1775,7 +1869,16 @@ do
return node.a[2]
end)
sort(resolved, nodepriority)
return resolved[1] or error("Cannot resolve target " .. tostring(name) .. ": " .. tostring(#candidates) .. " candidates, " .. tostring(#resolved) .. " resolved")
if not (resolved[1]) then
local err = "Cannot resolve target " .. tostring(name) .. ": " .. tostring(#candidates) .. " candidates, " .. tostring(#resolved) .. " resolved"
table.insert(errors, {
name = name,
level = level,
err = err
})
error(err)
end
return resolved[1]
end,
buildablenodes = function(self)
local _accum_0 = { }
@@ -1904,7 +2007,7 @@ do
return false
end
if not (quiet) then
print(tostring(self.type == 'virtual' and "Running" or "Building") .. " " .. tostring(self.name))
print(tostring(self.type == 'virtual' and "Running" or "Building") .. " " .. tostring(self.name) .. " [level " .. tostring(self.level) .. "]")
end
self:actuallybuild()
return true
@@ -1952,11 +2055,11 @@ do
local ctx = setmetatable({ }, {
__index = function(_, k)
local _exp_0 = k
if 'infile' == _exp_0 then
if 'infile' == _exp_0 or 'in' == _exp_0 then
return self.ins[1]
elseif 'infiles' == _exp_0 then
return self.ins
elseif 'outfile' == _exp_0 then
elseif 'outfile' == _exp_0 or 'out' == _exp_0 then
return self.outs[1]
elseif 'outfiles' == _exp_0 then
return self.outs
@@ -1986,8 +2089,8 @@ do
}
_base_0.__index = _base_0
_class_0 = setmetatable({
__init = function(self, dag, target, name)
self.dag, self.name = dag, name
__init = function(self, dag, target, name, level, errors)
self.dag, self.name, self.level = dag, name, level
self.priority = target.priority
self.buildfunctions = target.buildfunctions
self.mkdirs = target._mkdirs
@@ -2002,7 +2105,7 @@ do
self.built = false
local resolve
resolve = function(name)
return self.dag:resolvedeps(patsubst(self.name, target.pattern, name))
return self.dag:resolvedeps((patsubst(self.name, target.pattern, name)), level + 1, errors)
end
local after = flatten(foreach(target.needtargets, resolve))
local deps = flatten(foreach(target.infiles, resolve))
@@ -2010,14 +2113,14 @@ do
local ctx = setmetatable({ }, {
__index = function(_, k)
local _exp_0 = k
if 'infile' == _exp_0 then
if 'infile' == _exp_0 or 'in' == _exp_0 then
local f = first(deps)
return f and f.name
elseif 'infiles' == _exp_0 then
return foreach(deps, function(self)
return self.name
end)
elseif 'outfile' == _exp_0 then
elseif 'outfile' == _exp_0 or 'out' == _exp_0 then
local f = first(self.outs)
return f and f.name
elseif 'outfiles' == _exp_0 then
@@ -2107,6 +2210,123 @@ return DepGraph
end
end
do
local _ENV = _ENV
package.preload[ "moonbuild.core.Pipeline" ] = function( ... ) local arg = _G.arg;
local Target = require('moonbuild.core.Target')
local _ = require('moonbuild._')
local flatten, patsubst
flatten, patsubst = _.flatten, _.patsubst
local Pipeline
do
local _class_0
local _base_0 = {
sources = function(self, ...)
self.lastsources = flatten(self.lastsources, ...)
end,
source = function(self, src)
self.lastsources = flatten(self.lastsources, src)
end,
step = function(self, name, params)
local public = true
if (type(name)) == 'table' then
public, params = false, name
end
local tgttype
if params.pattern then
if not ((type(params.pattern)) == 'table' and (type(params.pattern[1])) == 'string' and (type(params.pattern[2])) == 'string') then
error("pattern must be a table with the same format as patsubst")
end
tgttype = 'pattern'
elseif params.output or params.out then
if not ((type(params.output or params.out)) == 'string') then
error("output must be a string")
end
tgttype = 'single'
else
tgttype = error("invalid step type for pipeline: must be pattern or single (out/output)")
end
local tgtouts
local _exp_0 = tgttype
if 'pattern' == _exp_0 then
tgtouts = patsubst(self.lastsources, params.pattern[1], params.pattern[2])
elseif 'single' == _exp_0 then
tgtouts = params.output or params.out
end
local tgtpatt
local _exp_1 = tgttype
if 'pattern' == _exp_1 then
tgtpatt = params.pattern[2]
elseif 'single' == _exp_1 then
tgtpatt = nil
end
local tgtins
local _exp_2 = tgttype
if 'pattern' == _exp_2 then
tgtins = params.pattern[1]
elseif 'single' == _exp_2 then
tgtins = self.lastsources
end
local tgtprod
local _exp_3 = tgttype
if 'pattern' == _exp_3 then
tgtprod = params.pattern[2]
elseif 'single' == _exp_3 then
tgtprod = '%'
end
local tgt
do
local _with_0 = Target(self.ctx, tgtouts, {
pattern = tgtpatt
})
_with_0:depends(tgtins)
_with_0:produces(tgtprod)
_with_0:fn(params.fn or error("pipeline steps need a fn"))
tgt = _with_0
end
if params.mkdirs then
tgt:mkdirs()
end
if params.sync then
tgt:sync()
end
self.ctx:addtarget(tgt)
if public then
self.ctx:addtarget((function()
do
local _with_0 = Target(self.ctx, name)
_with_0:depends(tgtouts)
_with_0.public = true
return _with_0
end
end)())
end
self.lastsources = tgtouts
end
}
_base_0.__index = _base_0
_class_0 = setmetatable({
__init = function(self, ctx)
self.ctx = ctx
self.lastsources = { }
end,
__base = _base_0,
__name = "Pipeline"
}, {
__index = _base_0,
__call = function(cls, ...)
local _self_0 = setmetatable({}, _base_0)
cls.__init(_self_0, ...)
return _self_0
end
})
_base_0.__class = _class_0
Pipeline = _class_0
return _class_0
end
end
end
do
local _ENV = _ENV
package.preload[ "moonbuild.core.Target" ] = function( ... ) local arg = _G.arg;
@@ -2227,7 +2447,23 @@ do
__init = function(self, name, ...)
self.name = name
self.public = false
if (select('#', ...)) ~= 1 or (type(...)) == 'table' then
if (type(self.name)) == 'table' then
if not ((type(next(self.name))) == 'string') then
error("not a valid var table: " .. tostring(next(self.name)))
end
if next(self.name, (next(self.name))) then
error("more than one var at once: " .. tostring(next(self.name)) .. ", " .. tostring(next(self.name, (next(self.name)))))
end
name = next(self.name)
local param
self.name, param = name, self.name
local val = param[name]
if (select('#', ...)) ~= 0 or (type(val)) == 'table' then
self.value = flatten(val, ...)
else
self.value = val
end
elseif (select('#', ...)) ~= 1 or (type(...)) == 'table' then
self.value = flatten(...)
else
self.value = ...
@@ -2523,6 +2759,7 @@ local _ENV = _ENV
package.preload[ "moonbuild.env.init" ] = function( ... ) local arg = _G.arg;
local Target = require('moonbuild.core.Target')
local Variable = require('moonbuild.core.Variable')
local Pipeline = require('moonbuild.core.Pipeline')
local _ = require('moonbuild._')
local flatten
flatten = _.flatten
@@ -2542,10 +2779,10 @@ return function(ctx)
rawset(env, '_', _)
rawset(env, '_G', env)
rawset(env, '_ENV', env)
rawset(env, 'var', function(name, ...)
local var = Variable(name, ...)
rawset(env, 'var', function(...)
local var = Variable(...)
ctx:addvar(var)
rawset(varlayer, name, var.value)
rawset(varlayer, var.name, var.value)
return var
end)
rawset(env, 'target', function(name, opts)
@@ -2553,6 +2790,9 @@ return function(ctx)
ctx:addtarget(target)
return target
end)
rawset(env, 'pipeline', function()
return Pipeline(ctx)
end)
return env, varlayer
end
end
@@ -2600,8 +2840,6 @@ end
end
end
end
local loadfile
loadfile = require('moonscript.base').loadfile
local Context = require('moonbuild.context')
@@ -2643,29 +2881,20 @@ moonbuild = function(...)
opts.force = force
local verbose = opts.verbose or opts.v or false
opts.verbose = verbose
_.verbose(verbose)
local ctx = Context()
ctx:load((loadfile(buildfile)), opts)
if verbose then
print("Loaded buildfile")
end
_.verbose("Loaded buildfile")
ctx:init()
if verbose then
print("Initialized buildfile")
end
_.verbose("Initialized buildfile")
local targets = #opts == 0 and ctx.defaulttargets or opts
local dag = DepGraph(ctx, targets)
if verbose then
print("Created dependancy graph")
end
_.verbose("Created dependancy graph")
local nparallel = parallel == true and Executor:getmaxparallel() or parallel
if verbose then
print("Building with " .. tostring(nparallel) .. " max parallel process" .. tostring(nparallel > 1 and "es" or ""))
end
_.verbose("Building with " .. tostring(nparallel) .. " max parallel process" .. tostring(nparallel > 1 and "es" or ""))
local executor = Executor(dag, nparallel)
executor:execute(opts)
if verbose then
return print("Finished")
end
return _.verbose("Finished")
end
local table = {
moonbuild = moonbuild,
+1 -1
View File
@@ -1,6 +1,6 @@
package: moonbuild
source:
url: git://github.com/natnat-mc/moonbuild
url: git+http://github.com/natnat-mc/moonbuild
description:
summary: Small build system in between make and a build.sh
detailed: >
+27
View File
@@ -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"
+27
View File
@@ -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"
+27
View File
@@ -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.5.0",
url = "git://github.com/natnat-mc/moonbuild"
}
version = "2.5.0-1"
+27
View File
@@ -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.5.1",
url = "git://github.com/natnat-mc/moonbuild"
}
version = "2.5.1-1"
+27
View File
@@ -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.6.0",
url = "git+http://github.com/natnat-mc/moonbuild"
}
version = "2.6.0-1"
+27
View File
@@ -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.7.0",
url = "git+http://github.com/natnat-mc/moonbuild"
}
version = "2.7.0-1"
+27
View File
@@ -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.7.1",
url = "git+http://github.com/natnat-mc/moonbuild"
}
version = "2.7.1-1"