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

main v2.7.0
codinget 2 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
unless ok
@ -17,6 +18,18 @@ 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] = (...) ->
cli = cmdline ...
verbose -> print "[#{f}] #{cli}"
orig ...
_sh = cmd.sh
cmd.sh = (cli) ->
verbose -> print "[sh] #{cli}"
_sh cli
-- derived cmd functions
_cmd = cmd.cmd
_cmdrst = cmd.cmdrst

@ -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
}

@ -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

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

@ -147,6 +147,17 @@ 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
else
error "_.verbose takes either no argument, a boolean or a function"
common.flatten = flatten
common.first = first
common.foreach = foreach
@ -159,5 +170,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]

@ -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 -> print "[moonc] #{infile} #{outfile}"
code, err = to_lua readfile infile
error "Failed to compile #{@infile}: #{err}" unless code
writefile outfile, code

@ -33,22 +33,27 @@ 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 -> print "Loaded buildfile"
ctx\init!
print "Initialized buildfile" if verbose
_.verbose -> print "Initialized buildfile"
targets = #opts==0 and ctx.defaulttargets or opts
dag = DepGraph ctx, targets
print "Created dependancy graph" if verbose
_.verbose -> print "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 -> print "Building with #{nparallel} max parallel process#{nparallel>1 and "es" or ""}"
executor = Executor dag, nparallel
executor\execute opts
print "Finished" if verbose
_.verbose -> print "Finished"
print _.verbose!
table = {
:moonbuild, :_

122
out/moonbuild.lua generated

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

Loading…
Cancel
Save