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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
--
-- action.lua
-- Work with the list of registered actions.
-- Copyright (c) 2002-2009 Jason Perkins and the Premake project
--
premake.action = { }
--
-- The list of registered actions.
--
premake.action.list = { }
--
-- Register a new action.
--
-- @param a
-- The new action object.
--
function premake.action.add(a)
-- validate the action object, at least a little bit
local missing
for _, field in ipairs({"description", "trigger"}) do
if (not a[field]) then
missing = field
end
end
if (missing) then
error("action needs a " .. missing, 3)
end
-- add it to the master list
premake.action.list[a.trigger] = a
end
--
-- Trigger an action.
--
-- @param name
-- The name of the action to be triggered.
-- @returns
-- None.
--
function premake.action.call(name)
local a = premake.action.list[name]
for sln in premake.solution.each() do
if a.onsolution then
a.onsolution(sln)
end
if sln.postsolutioncallbacks then
for _,cb in ipairs(sln.postsolutioncallbacks) do
cb(sln)
end
end
for prj in premake.solution.eachproject(sln) do
if a.onproject then
a.onproject(prj)
end
if prj.postprojectcallbacks then
for _,cb in ipairs(prj.postprojectcallbacks) do
cb(prj)
end
end
end
end
if a.execute then
a.execute()
end
end
--
-- Retrieve the current action, as determined by _ACTION.
--
-- @return
-- The current action, or nil if _ACTION is nil or does not match any action.
--
function premake.action.current()
return premake.action.get(_ACTION)
end
--
-- Retrieve an action by name.
--
-- @param name
-- The name of the action to retrieve.
-- @returns
-- The requested action, or nil if the action does not exist.
--
function premake.action.get(name)
return premake.action.list[name]
end
--
-- Iterator for the list of actions.
--
function premake.action.each()
-- sort the list by trigger
local keys = { }
for _, action in pairs(premake.action.list) do
table.insert(keys, action.trigger)
end
table.sort(keys)
local i = 0
return function()
i = i + 1
return premake.action.list[keys[i]]
end
end
--
-- Activates a particular action.
--
-- @param name
-- The name of the action to activate.
--
function premake.action.set(name)
_ACTION = name
-- Some actions imply a particular operating system
local action = premake.action.get(name)
if action then
_OS = action.os or _OS
end
end
--
-- Determines if an action supports a particular language or target type.
--
-- @param action
-- The action to test.
-- @param feature
-- The feature to check, either a programming language or a target type.
-- @returns
-- True if the feature is supported, false otherwise.
--
function premake.action.supports(action, feature)
if not action then
return false
end
if action.valid_languages then
if table.contains(action.valid_languages, feature) then
return true
end
end
if action.valid_kinds then
if table.contains(action.valid_kinds, feature) then
return true
end
end
return false
end
|