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

8 Commits

Author SHA1 Message Date
Nathan DECHER 0779ea3ad4 Producing rockspec 1.1.3-1 2020-09-15 11:37:21 +02:00
Nathan DECHER e3e185110a Merge branch 'master' of github.com:natnat-mc/moonbuild 2020-09-15 11:37:04 +02:00
Nathan DECHER 7b4973f0b4 fixed wildcard and normalizepath 2020-09-15 11:36:44 +02:00
Nathan DECHER c96b2ece70 fixed wildcard and normalizepath 2020-09-15 11:36:17 +02:00
Nathan DECHER 0e23ccecfb Producing rockspec 1.1.2-1 2020-09-14 11:28:51 +02:00
Nathan DECHER ccce358155 min and max were broken, fixed them 2020-09-14 11:28:35 +02:00
Nathan DECHER a125eab22f Producing rockspec 1.1.1-1 2020-09-14 11:08:19 +02:00
Nathan DECHER 0c43e3a5b1 fixed broken cache 2020-09-14 11:08:04 +02:00
8 changed files with 173 additions and 60 deletions
+16 -9
View File
@@ -127,12 +127,11 @@ class BuildObject
for i=1, #@outs for i=1, #@outs
return true if not otimes[i] return true if not otimes[i]
(max itimes)>=(min otimes) (max itimes)>(min otimes)
error "Need Lua >=5.2" if setfenv error "Need Lua >=5.2" if setfenv
targets = {} local targets, defaulttarget
defaulttarget = 'all'
buildscope = buildscope =
default: (target) -> default: (target) ->
@@ -158,14 +157,25 @@ setmetatable buildscope,
return global if global return global if global
(...) -> Command k, ... (...) -> Command k, ...
loadtargets = ->
targets = {}
defaulttarget = 'all'
file = first {'Build.moon', 'Buildfile.moon', 'Build', 'Buildfile'}, exists file = first {'Build.moon', 'Buildfile.moon', 'Build', 'Buildfile'}, exists
error "No Build.moon or Buildfile found" unless file error "No Build.moon or Buildfile found" unless file
buildfn = loadwithscope file, buildscope buildfn = loadwithscope file, buildscope
error "Failed to load build function" unless buildfn error "Failed to load build function" unless buildfn
ok, err = pcall buildfn buildfn!
buildtargets = ->
if #args.targets==0
BuildObject\build defaulttarget
for target in *args.targets
BuildObject\build target
ok, err = pcall loadtargets
unless ok unless ok
if err if err
io.stderr\write err, '\n' io.stderr\write "Error while loading build file: ", err, '\n'
else else
io.stderr\write "Unknown error\n" io.stderr\write "Unknown error\n"
os.exit 1 os.exit 1
@@ -197,7 +207,4 @@ if args.deps
io.write "\n" io.write "\n"
os.exit 0 os.exit 0
if #args.targets==0 buildtargets!
BuildObject\build defaulttarget
for target in *args.targets
BuildObject\build target
+54 -23
View File
@@ -22,8 +22,8 @@ makecached = function(fn)
freeze = function(val) freeze = function(val)
cache[val] = FROZEN cache[val] = FROZEN
end end
local reset local clear
reset = function() clear = function()
cache = { } cache = { }
end end
local get local get
@@ -44,7 +44,7 @@ makecached = function(fn)
get = get, get = get,
invalidate = invalidate, invalidate = invalidate,
freeze = freeze, freeze = freeze,
reset = reset clear = clear
}, { }, {
__call = function(self, val) __call = function(self, val)
return get(val) return get(val)
@@ -53,7 +53,15 @@ makecached = function(fn)
end end
return { return {
attributes = makecached(attributes), attributes = makecached(attributes),
dir = makecached(dir) dir = makecached(function(file)
local _accum_0 = { }
local _len_0 = 1
for k in dir(file) do
_accum_0[_len_0] = k
_len_0 = _len_0 + 1
end
return _accum_0
end)
} }
end end
@@ -112,13 +120,19 @@ normalizepath = function(file)
break break
end end
end end
if #parts == 0 then
return '.'
else
return (absolute and '/' or '') .. concat(parts, '/') return (absolute and '/' or '') .. concat(parts, '/')
end end
end
local ls local ls
ls = function(d) ls = function(d)
local _accum_0 = { } local _accum_0 = { }
local _len_0 = 1 local _len_0 = 1
for f in dir(normalizepath(d)) do local _list_0 = dir(normalizepath(d))
for _index_0 = 1, #_list_0 do
local f = _list_0[_index_0]
if f ~= '.' and f ~= '..' then if f ~= '.' and f ~= '..' then
_accum_0[_len_0] = f _accum_0[_len_0] = f
_len_0 = _len_0 + 1 _len_0 = _len_0 + 1
@@ -133,7 +147,9 @@ lswithpath = function(d)
end end
local _accum_0 = { } local _accum_0 = { }
local _len_0 = 1 local _len_0 = 1
for f in dir(normalizepath(d)) do local _list_0 = dir(normalizepath(d))
for _index_0 = 1, #_list_0 do
local f = _list_0[_index_0]
if f ~= '.' and f ~= '..' then if f ~= '.' and f ~= '..' then
_accum_0[_len_0] = d .. '/' .. f _accum_0[_len_0] = d .. '/' .. f
_len_0 = _len_0 + 1 _len_0 = _len_0 + 1
@@ -189,7 +205,7 @@ wildcard = function(glob)
local absolute = (sub(glob, 1, 1)) == '/' local absolute = (sub(glob, 1, 1)) == '/'
for i, part in ipairs(parts) do for i, part in ipairs(parts) do
local prevpath = (absolute and '/' or '') .. concat(parts, '/', 1, i - 1) local prevpath = (absolute and '/' or '') .. concat(parts, '/', 1, i - 1)
local currpath = prevpath .. '/' .. part local currpath = (i == 1 and '' or (prevpath .. '/')) .. part
if match(part, '%*%*.*%*%*') then if match(part, '%*%*.*%*%*') then
error("Two '**' in the same path component in a wildcard") error("Two '**' in the same path component in a wildcard")
end end
@@ -264,6 +280,11 @@ invalidatecache = function(file)
dir.invalidate(parentdir(file)) dir.invalidate(parentdir(file))
return attributes.invalidate(file) return attributes.invalidate(file)
end end
local clearcache
clearcache = function()
dir.clear()
return attributes.clear()
end
return { return {
wildcard = wildcard, wildcard = wildcard,
exists = exists, exists = exists,
@@ -272,7 +293,8 @@ return {
normalizepath = normalizepath, normalizepath = normalizepath,
parentdir = parentdir, parentdir = parentdir,
freezecache = freezecache, freezecache = freezecache,
invalidatecache = invalidatecache invalidatecache = invalidatecache,
clearcache = clearcache
} }
end end
@@ -376,7 +398,7 @@ min = function(table, cmp)
local val = table[1] local val = table[1]
for i = 2, #table do for i = 2, #table do
local elem = table[i] local elem = table[i]
if cmp(val, elem) then if cmp(elem, val) then
val = elem val = elem
end end
end end
@@ -392,7 +414,7 @@ max = function(table, cmp)
local val = table[1] local val = table[1]
for i = 2, #table do for i = 2, #table do
local elem = table[i] local elem = table[i]
if not cmp(val, elem) then if not cmp(elem, val) then
val = elem val = elem
end end
end end
@@ -941,7 +963,7 @@ do
return true return true
end end
end end
return (max(itimes)) >= (min(otimes)) return (max(itimes)) > (min(otimes))
end end
} }
_base_0.__index = _base_0 _base_0.__index = _base_0
@@ -1016,8 +1038,7 @@ end
if setfenv then if setfenv then
error("Need Lua >=5.2") error("Need Lua >=5.2")
end end
local targets = { } local targets, defaulttarget
local defaulttarget = 'all'
local buildscope = { local buildscope = {
default = function(target) default = function(target)
defaulttarget = target.name defaulttarget = target.name
@@ -1055,6 +1076,10 @@ setmetatable(buildscope, {
end end
end end
}) })
local loadtargets
loadtargets = function()
targets = { }
defaulttarget = 'all'
local file = first({ local file = first({
'Build.moon', 'Build.moon',
'Buildfile.moon', 'Buildfile.moon',
@@ -1068,10 +1093,23 @@ local buildfn = loadwithscope(file, buildscope)
if not (buildfn) then if not (buildfn) then
error("Failed to load build function") error("Failed to load build function")
end end
local ok, err = pcall(buildfn) return buildfn()
end
local buildtargets
buildtargets = function()
if #args.targets == 0 then
BuildObject:build(defaulttarget)
end
local _list_0 = args.targets
for _index_0 = 1, #_list_0 do
local target = _list_0[_index_0]
BuildObject:build(target)
end
end
local ok, err = pcall(loadtargets)
if not (ok) then if not (ok) then
if err then if err then
io.stderr:write(err, '\n') io.stderr:write("Error while loading build file: ", err, '\n')
else else
io.stderr:write("Unknown error\n") io.stderr:write("Unknown error\n")
end end
@@ -1112,11 +1150,4 @@ if args.deps then
end end
os.exit(0) os.exit(0)
end end
if #args.targets == 0 then return buildtargets()
BuildObject:build(defaulttarget)
end
local _list_0 = args.targets
for _index_0 = 1, #_list_0 do
local target = _list_0[_index_0]
BuildObject:build(target)
end
+3 -3
View File
@@ -12,7 +12,7 @@ makecached = (fn) ->
freeze = (val) -> freeze = (val) ->
cache[val] = FROZEN cache[val] = FROZEN
reset = -> clear = ->
cache = {} cache = {}
get = (val) -> get = (val) ->
@@ -24,10 +24,10 @@ makecached = (fn) ->
cache[val] = ret cache[val] = ret
unpack ret unpack ret
setmetatable { :get, :invalidate, :freeze, :reset }, setmetatable { :get, :invalidate, :freeze, :clear },
__call: (val) => get val __call: (val) => get val
{ {
attributes: makecached attributes attributes: makecached attributes
dir: makecached dir dir: makecached (file) -> [k for k in dir file]
} }
+12 -6
View File
@@ -16,15 +16,17 @@ normalizepath = (file) ->
remove parts, i-1 remove parts, i-1
i -= 2 i -= 2
continue continue
if #parts==0
'.'
else
(absolute and '/' or '') .. concat parts, '/' (absolute and '/' or '') .. concat parts, '/'
ls = (d) -> ls = (d) ->
[f for f in dir normalizepath d when f!='.' and f!='..'] [f for f in *dir normalizepath d when f!='.' and f!='..']
lswithpath = (d) -> lswithpath = (d) ->
if d=='' return ls '.' if d==''
return ls '.' [d..'/'..f for f in *dir normalizepath d when f!='.' and f!='..']
[d..'/'..f for f in dir normalizepath d when f!='.' and f!='..']
exists = (f) -> exists = (f) ->
(attributes normalizepath f) != nil (attributes normalizepath f) != nil
@@ -55,7 +57,7 @@ wildcard = (glob) ->
for i, part in ipairs parts for i, part in ipairs parts
prevpath = (absolute and '/' or '') .. concat parts, '/', 1, i-1 prevpath = (absolute and '/' or '') .. concat parts, '/', 1, i-1
currpath = prevpath .. '/' .. part currpath = (i==1 and '' or (prevpath .. '/')) .. part
if match part, '%*%*.*%*%*' if match part, '%*%*.*%*%*'
error "Two '**' in the same path component in a wildcard" error "Two '**' in the same path component in a wildcard"
@@ -109,10 +111,14 @@ invalidatecache = (file) ->
dir.invalidate parentdir file dir.invalidate parentdir file
attributes.invalidate file attributes.invalidate file
clearcache = ->
dir.clear!
attributes.clear!
{ {
:wildcard :wildcard
:exists, :isdir :exists, :isdir
:mtime :mtime
:normalizepath, :parentdir :normalizepath, :parentdir
:freezecache, :invalidatecache :freezecache, :invalidatecache, :clearcache
} }
+2 -2
View File
@@ -12,7 +12,7 @@ min = (table, cmp=(a, b) -> a<b) ->
val = table[1] val = table[1]
for i=2, #table for i=2, #table
elem = table[i] elem = table[i]
if cmp val, elem if cmp elem, val
val = elem val = elem
val val
@@ -20,7 +20,7 @@ max = (table, cmp=(a, b) -> a<b) ->
val = table[1] val = table[1]
for i=2, #table for i=2, #table
elem = table[i] elem = table[i]
if not cmp val, elem if not cmp elem, val
val = elem val = elem
val val
+23
View File
@@ -0,0 +1,23 @@
build = {
install = {
bin = {
moonbuild = "moonbuild.lua"
}
},
type = "builtin"
}
dependencies = {
"lua >= 5.3",
"luafilesystem >= 1.7.0"
}
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)\n",
summary = "Small build system in between make and a build.sh"
}
package = "moonbuild"
rockspec_format = "3.0"
source = {
tag = "v1.1.1",
url = "git://github.com/natnat-mc/moonbuild"
}
version = "1.1.1-1"
+23
View File
@@ -0,0 +1,23 @@
build = {
install = {
bin = {
moonbuild = "moonbuild.lua"
}
},
type = "builtin"
}
dependencies = {
"lua >= 5.3",
"luafilesystem >= 1.7.0"
}
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)\n",
summary = "Small build system in between make and a build.sh"
}
package = "moonbuild"
rockspec_format = "3.0"
source = {
tag = "v1.1.2",
url = "git://github.com/natnat-mc/moonbuild"
}
version = "1.1.2-1"
+23
View File
@@ -0,0 +1,23 @@
build = {
install = {
bin = {
moonbuild = "moonbuild.lua"
}
},
type = "builtin"
}
dependencies = {
"lua >= 5.3",
"luafilesystem >= 1.7.0"
}
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)\n",
summary = "Small build system in between make and a build.sh"
}
package = "moonbuild"
rockspec_format = "3.0"
source = {
tag = "v1.1.3",
url = "git://github.com/natnat-mc/moonbuild"
}
version = "1.1.3-1"