-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_targets.lua
More file actions
93 lines (77 loc) · 2.69 KB
/
custom_targets.lua
File metadata and controls
93 lines (77 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
local custom_rules = { }
local custom_targets = { }
local protected_properties = {
rule = true,
command = true,
generator = true,
restat = true,
outputs = true,
implicit_outputs = true,
inputs = true,
implicit_inputs = true,
order_only_inputs = true,
vars = true
}
local function configure_custom_target (t, configured, search_paths)
t.outputs = expand_pathspec(t.outputs, search_paths, configured)
local found, not_found
for i = 1, #t.outputs do
local o = t.outputs[i]
if custom_targets[o] then found = true else not_found = true end
custom_targets[o] = true
end
if found and not_found then
warn('Some custom targets have already been defined!', configured, { t = be.util.sprint_r(t) })
end
if found then return end
if not custom_rules[t.rule] then
custom_rules[t.rule] = t.command
local extra = {
command = t.command,
description = t.rule .. ' $out'
}
if t.generator then
extra.generator = 'true'
end
if t.restat then
extra.restat = 'true'
end
make_rule(t.rule)(extra)
elseif custom_rules[t.rule] ~= t.command then
fatal('a custom build rule named ' .. t.rule .. 'already exists with a different definition!', configured, { t = be.util.sprint_r(t) })
end
t.implicit_outputs = t.implicit_outputs and expand_pathspec(t.implicit_outputs, search_paths, configured)
t.inputs = t.inputs and expand_pathspec(t.inputs, search_paths, configured)
t.implicit_inputs = t.implicit_inputs and expand_pathspec(t.implicit_inputs, search_paths, configured)
t.order_only_inputs = t.order_only_inputs and expand_pathspec(t.order_only_inputs, search_paths, configured)
t.vars = t.vars or { }
for k, v in pairs(t) do
if not protected_properties[k] then
t.vars[#t.vars+1] = { name = k, value = v }
end
end
if #t.vars == 0 then
t.vars = nil
end
table.sort(t.vars, function (a, b) return a.name < b.name end)
return t
end
function build_scripts.env.custom (t)
if type(t) ~= 'table' or not t.outputs or not t.rule or not t.command then
fatal('custom build step must specify at least one output, a rule name, and a command!', nil, { t = be.util.sprint_r(t) })
end
return function (configured)
configured.custom = append_sequence({ t }, configured.custom)
end
end
function make_custom_targets (configured)
if configured.custom then
for i = 1, #configured.custom do
local t = configure_custom_target(configured.custom[i], configured, { configured.path, root_dir })
if t then
t.rule = rule(t.rule)
make_target(t)
end
end
end
end