-
Notifications
You must be signed in to change notification settings - Fork 2
/
variant.lua
142 lines (119 loc) · 3.52 KB
/
variant.lua
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
---
-- Package management module
-- Variant matching/creation code.
-- Copyright (c) 2017 Blizzard Entertainment
---
local p = premake
local m = p.modules.packagemanager
local __members = {
filter = "table",
includes = "table",
links = "table",
libdirs = "table",
defines = "table",
dependson = "table",
bindirs = "table",
includedependencies = "table",
linkdependencies = "table",
location = "string",
server = "string",
script = "string",
testscript = "string",
initializer = "function",
loaded = "boolean",
package = "table",
options = "table",
}
local api = {}
function m.validateFilter(f)
local _validKeys = {
["system"] = "string",
["host"] = "string",
["architecture"] = "string",
["toolset"] = "string",
["action"] = "string",
["configurations"] = "string",
["tags"] = "table",
}
for key, _ in pairs(f) do
if not _validKeys[key] then
p.error("Invalid entry in filter: '%s'.", key)
end
m.checkType(key, f[key], _validKeys[key]);
end
return f
end
function api:matches(filter)
if self.filter == nil then
return true
end
if not self.__compiled_filter then
local f = m.validateFilter(self.filter)
local function add(tbl, name, value)
if value ~= nil then
table.insert(tbl, name .. value)
end
end
local tbl = {}
add(tbl, "system:" , f.system)
add(tbl, "host:" , f.host)
add(tbl, "architecture:", f.architecture)
add(tbl, "toolset:", f.toolset)
add(tbl, "action:", f.action)
add(tbl, "configurations:", f.configurations)
if f.tags then
for _, tag in ipairs(f.tags) do
table.insert(tbl, "tags:" .. tag)
end
end
-- avoid the metatable check.
rawset(self, "__compiled_filter", criteria.new(tbl))
end
return criteria.matches(self.__compiled_filter, filter)
end
function api:generateManifest(tbl, wks)
if not self.loaded then
return
end
tbl[self.name] = {
location = p.workspace.getrelative(wks, self.location),
system = self.filter.system,
host = self.filter.host,
architecture = self.filter.architecture,
toolset = self.filter.toolset,
action = self.filter.action,
configurations = self.filter.configurations,
tags = self.filter.tags,
includedirs = iif(type(self.includes) == 'function', '<function>', self.includes),
defines = iif(type(self.defines) == 'function', '<function>', self.defines),
dependson = iif(type(self.dependson) == 'function', '<function>', self.dependson),
links = iif(type(self.links) == 'function', '<function>', self.links),
libdirs = iif(type(self.libdirs) == 'function', '<function>', self.libdirs),
bindirs = iif(type(self.bindirs) == 'function', '<function>', self.bindirs),
}
end
function m.createVariant(name)
local variant = {
name = name
}
-- return locked down variant.
return setmetatable(variant, {
__metatable = false,
__index = api,
__newindex = function(tbl, key, value)
local t = __members[key]
if t ~= nil then
if value == nil or type(value) == t then
rawset(tbl, key, value)
else
p.error("'%s' expected a '%s', got: '%s'.", key, t, type(value))
end
else
p.error("Attempt to write to unknown member '%s' (%s).", key, type(value))
end
end,
__tostring = function()
return "Variant"
end,
})
end