improved verbose

main
codinget 3 years ago
parent 9450ec9c9d
commit 775d689e0a
  1. 18
      bin/moonbuild.moon
  2. 5
      moonbuild/_cmd.moon
  3. 4
      moonbuild/_common.moon
  4. 2
      moonbuild/_util.moon
  5. 12
      moonbuild/init.moon
  6. 31
      out/moonbuild
  7. 40
      out/moonbuild.lua

@ -1,8 +1,9 @@
-- load everything we need -- load everything we need
import loadfile from require 'moonscript.base' import loadfile from require 'moonscript.base'
import Context, DepGraph, Executor from require 'moonbuild' import Context, DepGraph, Executor from require 'moonbuild'
Variable = (require 'moonbuild')['core.Variable'] Variable = require 'moonbuild.core.Variable'
import parseargs from (require 'moonbuild')['_cmd.common'] import verbose from require 'moonbuild._common'
import parseargs from require 'moonbuild._cmd.common'
argparse = require 'argparse' argparse = require 'argparse'
import sort, concat from table import sort, concat from table
import exit from os 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}") 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) 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 -- load the buildfile
ctx = Context! ctx = Context!
ctx\load (loadfile args.buildfile), overrides ctx\load (loadfile args.buildfile), overrides
print "Loaded buildfile" if args.verbose verbose "Loaded buildfile"
-- handle -l and -V -- handle -l and -V
if args.list if args.list
@ -65,16 +67,16 @@ if args.list_variables
-- initialize the buildfile further -- initialize the buildfile further
ctx\init! ctx\init!
print "Initialized buildfile" if args.verbose verbose "Initialized buildfile"
-- create the DAG -- create the DAG
targets = #args.targets==0 and ctx.defaulttargets or args.targets targets = #args.targets==0 and ctx.defaulttargets or args.targets
dag = DepGraph ctx, targets dag = DepGraph ctx, targets
print "Created dependancy graph" if args.verbose verbose print "Created dependancy graph"
-- execute the build -- execute the build
nparallel = args.parallel == 'y' and Executor\getmaxparallel! or args.parallel 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 = Executor dag, nparallel
executor\execute args executor\execute args
print "Finished" if args.verbose verbose "Finished"

@ -22,12 +22,11 @@ cmd.escape = escape
for f in *({'cmd', 'cmdrst'}) for f in *({'cmd', 'cmdrst'})
orig = cmd[f] orig = cmd[f]
cmd[f] = (...) -> cmd[f] = (...) ->
cli = cmdline ... verbose "[#{f}] #{cmdline ...}"
verbose -> print "[#{f}] #{cli}"
orig ... orig ...
_sh = cmd.sh _sh = cmd.sh
cmd.sh = (cli) -> cmd.sh = (cli) ->
verbose -> print "[sh] #{cli}" verbose "[sh] #{cli}"
_sh cli _sh cli
-- derived cmd functions -- derived cmd functions

@ -155,8 +155,10 @@ verbose = (arg) ->
arg! if _verbose arg! if _verbose
elseif (type arg) == 'boolean' elseif (type arg) == 'boolean'
_verbose = arg _verbose = arg
elseif (type arg) == 'string'
print arg if _verbose
else else
error "_.verbose takes either no argument, a boolean or a function" error "_.verbose takes either no argument, a boolean, a function or a string"
common.flatten = flatten common.flatten = flatten
common.first = first common.first = first

@ -35,7 +35,7 @@ writefile = (filename, data) ->
nil nil
moonc = (infile, outfile) -> moonc = (infile, outfile) ->
verbose -> print "[moonc] #{infile} #{outfile}" verbose "[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

@ -39,21 +39,19 @@ moonbuild = (...) ->
-- create context and DAG -- create context and DAG
ctx = Context! ctx = Context!
ctx\load (loadfile buildfile), opts ctx\load (loadfile buildfile), opts
_.verbose -> print "Loaded buildfile" _.verbose "Loaded buildfile"
ctx\init! ctx\init!
_.verbose -> print "Initialized buildfile" _.verbose "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
_.verbose -> print "Created dependancy graph" _.verbose "Created dependancy graph"
-- and build -- and build
nparallel = parallel == true and Executor\getmaxparallel! or parallel nparallel = parallel == true and Executor\getmaxparallel! or parallel
_.verbose -> print "Building with #{nparallel} max parallel process#{nparallel>1 and "es" or ""}" _.verbose "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
_.verbose -> print "Finished" _.verbose "Finished"
print _.verbose!
table = { table = {
:moonbuild, :_ :moonbuild, :_

31
out/moonbuild generated

@ -6,9 +6,11 @@ do
local _obj_0 = require('moonbuild') local _obj_0 = require('moonbuild')
Context, DepGraph, Executor = _obj_0.Context, _obj_0.DepGraph, _obj_0.Executor Context, DepGraph, Executor = _obj_0.Context, _obj_0.DepGraph, _obj_0.Executor
end end
local Variable = (require('moonbuild'))['core.Variable'] local Variable = require('moonbuild.core.Variable')
local verbose
verbose = require('moonbuild._common').verbose
local parseargs local parseargs
parseargs = (require('moonbuild'))['_cmd.common'].parseargs parseargs = require('moonbuild._cmd.common').parseargs
local argparse = require('argparse') local argparse = require('argparse')
local sort, concat local sort, concat
do 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 if args.parallel ~= 'y' and (args.parallel < 1 or args.parallel % 1 ~= 0) then
error("Invalid argument for -j: " .. tostring(args.parallel)) error("Invalid argument for -j: " .. tostring(args.parallel))
end end
if args.verbose then verbose(args.verbose or false)
print("Parsed CLI args") verbose("Parsed CLI args")
end
local ctx = Context() local ctx = Context()
ctx:load((loadfile(args.buildfile)), overrides) ctx:load((loadfile(args.buildfile)), overrides)
if args.verbose then verbose("Loaded buildfile")
print("Loaded buildfile")
end
if args.list then if args.list then
print("Public targets") print("Public targets")
local targets, n = { }, 1 local targets, n = { }, 1
@ -94,20 +93,12 @@ if args.list_variables then
exit(0) exit(0)
end end
ctx:init() ctx:init()
if args.verbose then verbose("Initialized buildfile")
print("Initialized buildfile")
end
local targets = #args.targets == 0 and ctx.defaulttargets or args.targets local targets = #args.targets == 0 and ctx.defaulttargets or args.targets
local dag = DepGraph(ctx, targets) local dag = DepGraph(ctx, targets)
if args.verbose then verbose(print("Created dependancy graph"))
print("Created dependancy graph")
end
local nparallel = args.parallel == 'y' and Executor:getmaxparallel() or args.parallel local nparallel = args.parallel == 'y' and Executor:getmaxparallel() or args.parallel
if args.verbose then verbose("Building with " .. tostring(nparallel) .. " max parallel process" .. tostring(nparallel > 1 and "es" or ""))
print("Building with " .. tostring(nparallel) .. " max parallel process" .. tostring(nparallel > 1 and "es" or ""))
end
local executor = Executor(dag, nparallel) local executor = Executor(dag, nparallel)
executor:execute(args) executor:execute(args)
if args.verbose then return verbose("Finished")
return print("Finished")
end

40
out/moonbuild.lua generated

@ -77,18 +77,13 @@ for _index_0 = 1, #_list_0 do
local f = _list_0[_index_0] local f = _list_0[_index_0]
local orig = cmd[f] local orig = cmd[f]
cmd[f] = function(...) cmd[f] = function(...)
local cli = cmdline(...) verbose("[" .. tostring(f) .. "] " .. tostring(cmdline(...)))
verbose(function()
return print("[" .. tostring(f) .. "] " .. tostring(cli))
end)
return orig(...) return orig(...)
end end
end end
local _sh = cmd.sh local _sh = cmd.sh
cmd.sh = function(cli) cmd.sh = function(cli)
verbose(function() verbose("[sh] " .. tostring(cli))
return print("[sh] " .. tostring(cli))
end)
return _sh(cli) return _sh(cli)
end end
local _cmd = cmd.cmd local _cmd = cmd.cmd
@ -679,8 +674,12 @@ verbose = function(arg)
end end
elseif (type(arg)) == 'boolean' then elseif (type(arg)) == 'boolean' then
_verbose = arg _verbose = arg
elseif (type(arg)) == 'string' then
if _verbose then
return print(arg)
end
else else
return error("_.verbose takes either no argument, a boolean or a function") return error("_.verbose takes either no argument, a boolean, a function or a string")
end end
end end
common.flatten = flatten common.flatten = flatten
@ -1382,9 +1381,7 @@ writefile = function(filename, data)
end end
local moonc local moonc
moonc = function(infile, outfile) moonc = function(infile, outfile)
verbose(function() verbose("[moonc] " .. tostring(infile) .. " " .. tostring(outfile))
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))
@ -2887,28 +2884,17 @@ moonbuild = function(...)
_.verbose(verbose) _.verbose(verbose)
local ctx = Context() local ctx = Context()
ctx:load((loadfile(buildfile)), opts) ctx:load((loadfile(buildfile)), opts)
_.verbose(function() _.verbose("Loaded buildfile")
return print("Loaded buildfile")
end)
ctx:init() ctx:init()
_.verbose(function() _.verbose("Initialized buildfile")
return print("Initialized buildfile")
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)
_.verbose(function() _.verbose("Created dependancy graph")
return print("Created dependancy graph")
end)
local nparallel = parallel == true and Executor:getmaxparallel() or parallel local nparallel = parallel == true and Executor:getmaxparallel() or parallel
_.verbose(function() _.verbose("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)
local executor = Executor(dag, nparallel) local executor = Executor(dag, nparallel)
executor:execute(opts) executor:execute(opts)
_.verbose(function() return _.verbose("Finished")
return print("Finished")
end)
return print(_.verbose())
end end
local table = { local table = {
moonbuild = moonbuild, moonbuild = moonbuild,

Loading…
Cancel
Save