Skip to content

Commit

Permalink
Fixes for optional stage handling, add rudimentary support for packag…
Browse files Browse the repository at this point in the history
…e mixins
  • Loading branch information
bazurbat committed Dec 22, 2021
1 parent a4ce016 commit fcda1ae
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 21 deletions.
47 changes: 30 additions & 17 deletions lib/rules.lua
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,24 @@ template {
}
}

template {
match = {
name = value,
build = some
},
apply = {
build = {
work_dir = path { from('jagen', 'build_dir'), value }
}
}
}

-- stage: clean

template {
match = {
source = some
match = anyof {
{ source = some },
{ build = some }
},
apply = {
stage = { clean = {} }
Expand All @@ -200,12 +213,14 @@ template {
-- update

template {
match = { source = { scm = true } },
match = {
source = { scm = true }
},
apply = {
stage = {
update = {
inputs = { stage 'clean' },
work_dir = from('jagen', 'build_dir')
work_dir = from('jagen', 'src_dir')
}
}
}
Expand All @@ -230,19 +245,17 @@ template {
template {
match = {
patches = some,
source = { dir = value 'source.dir' },
},
apply = {
stage = {
patch = {
inputs = {
from('<self>', anyof {
from(self, anyof {
stage 'update',
stage 'unpack',
stage 'clean'
})
},
work_dir = value 'source.dir'
}
}
}
}
Expand Down Expand Up @@ -297,22 +310,22 @@ template {
match = {
build = {
type = some,
dir = some
dir = value 'build.dir'
}
},
apply = {
stage = {
configure = {
inputs = {
anyof {
stage 'patch',
stage 'update',
stage 'unpack',
stage 'clean'
}
from(self, anyof {
stage 'patch',
stage 'update',
stage 'unpack',
stage 'clean'
})
},
work_dir = expand '${build.dir}'
}
work_dir = value 'build.dir'
}
}
}
}
Expand Down
19 changes: 18 additions & 1 deletion src/Engine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,30 @@ function Engine:process_module(module, pkg)
self:process_use(spec, pkg)
end
end
for i = 1, #env.packages do
local pkg = env.packages[i]
for ref in each(pkg.extends) do
local parent = self.packages[ref]
if parent then
local this = copy(parent)
this.abstract = nil
this.config = nil
this:merge(pkg, { env = pkg })
env.packages[i] = this
env.packages[this.ref] = this
else
error(format('package %s extends %s which is not defined',
pkg.ref, ref))
end
end
end
self:apply_templates(env)
end

function Engine:process_package(rule, env)
local pkg = self.packages[rule.ref]
if pkg then
Log.debug1('process package %s: merge with existing instance', rule.ref)
Log.debug1('process package %s: merge with an existing instance', rule.ref)
pkg:merge(rule, { env = pkg })
else
Log.debug1('process package %s: add new instance', rule.ref)
Expand Down
6 changes: 5 additions & 1 deletion src/Module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ function Module.env.from(expr, key)
ref = ref(state)
end
local pkg
if ref == '<self>' then
if ref == nil then
pkg = state.self
else
pkg = state.packages[ref]
Expand All @@ -423,6 +423,10 @@ function Module.env.from(expr, key)
elseif keytype == 'nil' then
return pkg
end
else
if debug then
Log.debug1('from %s: not found', ref)
end
end
end
end
Expand Down
13 changes: 11 additions & 2 deletions src/Package.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,20 @@ function Package:parse(rule)
rule.name = rule[1]
table.remove(rule, 1)
end
if type(rule[2]) == 'string' then
rule.config = rule[1]
table.remove(rule, 1)
end

if rule.name and rule.config then
rule.ref = string.format('%s:%s', rule.name, rule.config)
else
rule.ref = rule.name or rule.config
end

rule.ref = rule.name
rule.source = Source:parse(rule.source)

for key in each { 'class', 'uses' } do
for key in each { 'class', 'uses', 'extends' } do
local value = rule[key]
if type(value) == 'string' then
rule[key] = { value }
Expand Down

0 comments on commit fcda1ae

Please sign in to comment.