add echo to _.cmd _.cmdrst _.sh _.moonc when verbose

main v2.7.0
codinget 3 years ago
parent 37ab4f2299
commit de7ab2ddbf
  1. 15
      moonbuild/_cmd.moon
  2. 5
      moonbuild/_cmd/common.moon
  3. 6
      moonbuild/_cmd/lua.moon
  4. 1
      moonbuild/_cmd/posix.moon
  5. 12
      moonbuild/_common.moon
  6. 2
      moonbuild/_util.moon
  7. 15
      moonbuild/init.moon
  8. 122
      out/moonbuild.lua

@ -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 ok, cmd, backend = false, nil, nil
unless ok unless ok
@ -17,6 +18,18 @@ cmd.backend = backend
cmd.parseargs = parseargs cmd.parseargs = parseargs
cmd.escape = escape cmd.escape = escape
-- make verbose verisons of _.cmd, _.cmdrst and _.sh
for f in *({'cmd', 'cmdrst'})
orig = cmd[f]
cmd[f] = (...) ->
cli = cmdline ...
verbose -> print "[#{f}] #{cli}"
orig ...
_sh = cmd.sh
cmd.sh = (cli) ->
verbose -> print "[sh] #{cli}"
_sh cli
-- derived cmd functions -- derived cmd functions
_cmd = cmd.cmd _cmd = cmd.cmd
_cmdrst = cmd.cmdrst _cmdrst = cmd.cmdrst

@ -1,5 +1,6 @@
import gsub, sub, match from string import gsub, sub, match from string
import concat from table import concat from table
import flatten from require 'moonbuild._common'
specialchars = specialchars =
'\"': '\\\"' '\"': '\\\"'
@ -115,7 +116,11 @@ parseargs = (argstr) ->
args args
cmdline = (...) ->
concat [escape arg for arg in *flatten ...], ' '
{ {
:escape :escape
:parseargs :parseargs
:cmdline
} }

@ -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 flatten from require 'moonbuild._common'
import execute from require 'moonbuild.compat.execute' import execute from require 'moonbuild.compat.execute'
import popen from io import popen from io
import concat from table import concat from table
cmdline = (...) ->
concat [escape arg for arg in *flatten ...], ' '
cmd = (...) -> cmd = (...) ->
ok, ret, code = execute cmdline ... ok, ret, code = execute cmdline ...
error "command #{first ...} exited with #{code} (#{ret})" unless ok error "command #{first ...} exited with #{code} (#{ret})" unless ok
@ -19,6 +16,7 @@ cmdrst = (...) ->
data data
sh = (cli) -> sh = (cli) ->
verbose -> print '[sh] ' .. cli
ok, ret, code = execute cli ok, ret, code = execute cli
error "command '#{cli}' exited with #{code} (#{ret})" unless ok error "command '#{cli}' exited with #{code} (#{ret})" unless ok

@ -37,6 +37,7 @@ cmdrst = (...) ->
data data
sh = (cli) -> sh = (cli) ->
verbose -> print '[sh] ' .. cli
cmd 'sh', '-c', cli cmd 'sh', '-c', cli
{ {

@ -147,6 +147,17 @@ minmax = (list) ->
M = e if e>M M = e if e>M
m, M m, M
_verbose = false
verbose = (arg) ->
if arg == nil
_verbose
elseif (type arg) == 'function'
arg! if _verbose
elseif (type arg) == 'boolean'
_verbose = arg
else
error "_.verbose takes either no argument, a boolean or a function"
common.flatten = flatten common.flatten = flatten
common.first = first common.first = first
common.foreach = foreach common.foreach = foreach
@ -159,5 +170,6 @@ common.exclude = exclude
common.min = min common.min = min
common.max = max common.max = max
common.minmax = minmax common.minmax = minmax
common.verbose = verbose
setmetatable common, __call: => [k for k in pairs common] setmetatable common, __call: => [k for k in pairs common]

@ -1,5 +1,6 @@
import to_lua from require 'moonscript.base' import to_lua from require 'moonscript.base'
import parseargs, cmdrst from require 'moonbuild._cmd' import parseargs, cmdrst from require 'moonbuild._cmd'
import verbose from require 'moonbuild._common'
import gmatch, match, gsub from string import gmatch, match, gsub from string
import open from io import open from io
@ -34,6 +35,7 @@ writefile = (filename, data) ->
nil nil
moonc = (infile, outfile) -> moonc = (infile, outfile) ->
verbose -> print "[moonc] #{infile} #{outfile}"
code, err = to_lua readfile infile code, err = to_lua readfile infile
error "Failed to compile #{@infile}: #{err}" unless code error "Failed to compile #{@infile}: #{err}" unless code
writefile outfile, code writefile outfile, code

@ -33,22 +33,27 @@ moonbuild = (...) ->
verbose = opts.verbose or opts.v or false verbose = opts.verbose or opts.v or false
opts.verbose = verbose opts.verbose = verbose
-- set verbosity level
_.verbose verbose
-- create context and DAG -- create context and DAG
ctx = Context! ctx = Context!
ctx\load (loadfile buildfile), opts ctx\load (loadfile buildfile), opts
print "Loaded buildfile" if verbose _.verbose -> print "Loaded buildfile"
ctx\init! ctx\init!
print "Initialized buildfile" if verbose _.verbose -> print "Initialized buildfile"
targets = #opts==0 and ctx.defaulttargets or opts targets = #opts==0 and ctx.defaulttargets or opts
dag = DepGraph ctx, targets dag = DepGraph ctx, targets
print "Created dependancy graph" if verbose _.verbose -> print "Created dependancy graph"
-- and build -- and build
nparallel = parallel == true and Executor\getmaxparallel! or parallel nparallel = parallel == true and Executor\getmaxparallel! or parallel
print "Building with #{nparallel} max parallel process#{nparallel>1 and "es" or ""}" if verbose _.verbose -> print "Building with #{nparallel} max parallel process#{nparallel>1 and "es" or ""}"
executor = Executor dag, nparallel executor = Executor dag, nparallel
executor\execute opts executor\execute opts
print "Finished" if verbose _.verbose -> print "Finished"
print _.verbose!
table = { table = {
:moonbuild, :_ :moonbuild, :_

122
out/moonbuild.lua generated

@ -36,11 +36,13 @@ end
do do
local _ENV = _ENV local _ENV = _ENV
package.preload[ "moonbuild._cmd" ] = function( ... ) local arg = _G.arg; package.preload[ "moonbuild._cmd" ] = function( ... ) local arg = _G.arg;
local parseargs, escape local parseargs, escape, cmdline
do do
local _obj_0 = require('moonbuild._cmd.common') 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 end
local verbose
verbose = require('moonbuild._common').verbose
local ok, cmd, backend = false, nil, nil local ok, cmd, backend = false, nil, nil
if not (ok) then if not (ok) then
ok, cmd = pcall(function() ok, cmd = pcall(function()
@ -67,6 +69,28 @@ end
cmd.backend = backend cmd.backend = backend
cmd.parseargs = parseargs cmd.parseargs = parseargs
cmd.escape = escape 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(...)
local cli = cmdline(...)
verbose(function()
return print("[" .. tostring(f) .. "] " .. tostring(cli))
end)
return orig(...)
end
end
local _sh = cmd.sh
cmd.sh = function(cli)
verbose(function()
return print("[sh] " .. tostring(cli))
end)
return _sh(cli)
end
local _cmd = cmd.cmd local _cmd = cmd.cmd
local _cmdrst = cmd.cmdrst local _cmdrst = cmd.cmdrst
cmd.cmdline = function(cmdline) cmd.cmdline = function(cmdline)
@ -99,6 +123,8 @@ do
end end
local concat local concat
concat = table.concat concat = table.concat
local flatten
flatten = require('moonbuild._common').flatten
local specialchars = { local specialchars = {
['\"'] = '\\\"', ['\"'] = '\\\"',
['\\'] = '\\\\', ['\\'] = '\\\\',
@ -230,9 +256,24 @@ parseargs = function(argstr)
end end
return args return args
end end
local cmdline
cmdline = function(...)
return concat((function(...)
local _accum_0 = { }
local _len_0 = 1
local _list_0 = flatten(...)
for _index_0 = 1, #_list_0 do
local arg = _list_0[_index_0]
_accum_0[_len_0] = escape(arg)
_len_0 = _len_0 + 1
end
return _accum_0
end)(...), ' ')
end
return { return {
escape = escape, escape = escape,
parseargs = parseargs parseargs = parseargs,
cmdline = cmdline
} }
end end
end end
@ -240,8 +281,8 @@ end
do do
local _ENV = _ENV local _ENV = _ENV
package.preload[ "moonbuild._cmd.lua" ] = function( ... ) local arg = _G.arg; package.preload[ "moonbuild._cmd.lua" ] = function( ... ) local arg = _G.arg;
local escape local cmdline
escape = require('moonbuild._cmd.common').escape cmdline = require('moonbuild._cmd.common').cmdline
local flatten local flatten
flatten = require('moonbuild._common').flatten flatten = require('moonbuild._common').flatten
local execute local execute
@ -250,20 +291,6 @@ local popen
popen = io.popen popen = io.popen
local concat local concat
concat = table.concat concat = table.concat
local cmdline
cmdline = function(...)
return concat((function(...)
local _accum_0 = { }
local _len_0 = 1
local _list_0 = flatten(...)
for _index_0 = 1, #_list_0 do
local arg = _list_0[_index_0]
_accum_0[_len_0] = escape(arg)
_len_0 = _len_0 + 1
end
return _accum_0
end)(...), ' ')
end
local cmd local cmd
cmd = function(...) cmd = function(...)
local ok, ret, code = execute(cmdline(...)) local ok, ret, code = execute(cmdline(...))
@ -283,6 +310,9 @@ cmdrst = function(...)
end end
local sh local sh
sh = function(cli) sh = function(cli)
verbose(function()
return print('[sh] ' .. cli)
end)
local ok, ret, code = execute(cli) local ok, ret, code = execute(cli)
if not (ok) then if not (ok) then
return error("command '" .. tostring(cli) .. "' exited with " .. tostring(code) .. " (" .. tostring(ret) .. ")") return error("command '" .. tostring(cli) .. "' exited with " .. tostring(code) .. " (" .. tostring(ret) .. ")")
@ -354,6 +384,9 @@ cmdrst = function(...)
end end
local sh local sh
sh = function(cli) sh = function(cli)
verbose(function()
return print('[sh] ' .. cli)
end)
return cmd('sh', '-c', cli) return cmd('sh', '-c', cli)
end end
return { return {
@ -635,6 +668,21 @@ minmax = function(list)
end end
return m, M return m, M
end 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
else
return error("_.verbose takes either no argument, a boolean or a function")
end
end
common.flatten = flatten common.flatten = flatten
common.first = first common.first = first
common.foreach = foreach common.foreach = foreach
@ -647,6 +695,7 @@ common.exclude = exclude
common.min = min common.min = min
common.max = max common.max = max
common.minmax = minmax common.minmax = minmax
common.verbose = verbose
return setmetatable(common, { return setmetatable(common, {
__call = function(self) __call = function(self)
local _accum_0 = { } local _accum_0 = { }
@ -1260,6 +1309,8 @@ do
local _obj_0 = require('moonbuild._cmd') local _obj_0 = require('moonbuild._cmd')
parseargs, cmdrst = _obj_0.parseargs, _obj_0.cmdrst parseargs, cmdrst = _obj_0.parseargs, _obj_0.cmdrst
end end
local verbose
verbose = require('moonbuild._common').verbose
local gmatch, match, gsub local gmatch, match, gsub
do do
local _obj_0 = string local _obj_0 = string
@ -1331,6 +1382,9 @@ writefile = function(filename, data)
end end
local moonc local moonc
moonc = function(infile, outfile) moonc = function(infile, outfile)
verbose(function()
return print("[moonc] " .. tostring(infile) .. " " .. tostring(outfile))
end)
local code, err = to_lua(readfile(infile)) local code, err = to_lua(readfile(infile))
if not (code) then if not (code) then
error("Failed to compile " .. tostring(self.infile) .. ": " .. tostring(err)) error("Failed to compile " .. tostring(self.infile) .. ": " .. tostring(err))
@ -2830,29 +2884,31 @@ moonbuild = function(...)
opts.force = force opts.force = force
local verbose = opts.verbose or opts.v or false local verbose = opts.verbose or opts.v or false
opts.verbose = verbose opts.verbose = verbose
_.verbose(verbose)
local ctx = Context() local ctx = Context()
ctx:load((loadfile(buildfile)), opts) ctx:load((loadfile(buildfile)), opts)
if verbose then _.verbose(function()
print("Loaded buildfile") return print("Loaded buildfile")
end end)
ctx:init() ctx:init()
if verbose then _.verbose(function()
print("Initialized buildfile") return print("Initialized buildfile")
end end)
local targets = #opts == 0 and ctx.defaulttargets or opts local targets = #opts == 0 and ctx.defaulttargets or opts
local dag = DepGraph(ctx, targets) local dag = DepGraph(ctx, targets)
if verbose then _.verbose(function()
print("Created dependancy graph") return print("Created dependancy graph")
end end)
local nparallel = parallel == true and Executor:getmaxparallel() or parallel local nparallel = parallel == true and Executor:getmaxparallel() or parallel
if verbose then _.verbose(function()
print("Building with " .. tostring(nparallel) .. " max parallel process" .. tostring(nparallel > 1 and "es" or "")) return print("Building with " .. tostring(nparallel) .. " max parallel process" .. tostring(nparallel > 1 and "es" or ""))
end end)
local executor = Executor(dag, nparallel) local executor = Executor(dag, nparallel)
executor:execute(opts) executor:execute(opts)
if verbose then _.verbose(function()
return print("Finished") return print("Finished")
end end)
return print(_.verbose())
end end
local table = { local table = {
moonbuild = moonbuild, moonbuild = moonbuild,

Loading…
Cancel
Save