-
-
Notifications
You must be signed in to change notification settings - Fork 618
/
Copy pathworkspace.lua
202 lines (163 loc) · 4.24 KB
/
workspace.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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
---
-- workspace.lua
-- Work with the list of workspaces loaded from the script.
-- Copyright (c) 2002-2015 Jess Perkins and the Premake project
---
local p = premake
p.workspace = p.api.container("workspace", p.global)
local workspace = p.workspace
---
-- Switch this container's name from "solution" to "workspace"
--
-- We changed these names on 30 Jul 2015. While it might be nice to leave
-- `solution()` around for Visual Studio folks and everyone still used to the
-- old system, it would be good to eventually deprecate and remove all of
-- the other, more internal uses of "solution" and "sln". Probably including
-- all uses of container class aliases, since we probably aren't going to
-- need those again (right?).
---
p.solution = workspace
workspace.alias = "solution"
p.alias(_G, "workspace", "solution")
p.alias(_G, "externalworkspace", "externalsolution")
---
-- Create a new workspace container instance.
---
function workspace.new(name)
local wks = p.container.new(workspace, name)
return wks
end
--
-- Iterate over the configurations of a workspace.
--
-- @return
-- A configuration iteration function.
--
function workspace.eachconfig(self)
self = p.oven.bakeWorkspace(self)
local i = 0
return function()
i = i + 1
if i > #self.configs then
return nil
else
return self.configs[i]
end
end
end
--
-- Iterate over the projects of a workspace.
--
-- @return
-- An iterator function, returning project configurations.
--
function workspace.eachproject(self)
local i = 0
return function ()
i = i + 1
if i <= #self.projects then
return p.workspace.getproject(self, i)
end
end
end
--
-- Locate a project by name, case insensitive.
--
-- @param name
-- The name of the project to find.
-- @return
-- The project object, or nil if a matching project could not be found.
--
function workspace.findproject(self, name)
name = name:lower()
for _, prj in ipairs(self.projects) do
if name == prj.name:lower() then
return prj
end
end
return nil
end
--
-- Retrieve the tree of project groups.
--
-- @return
-- The tree of project groups defined for the workspace.
--
function workspace.grouptree(self)
-- check for a previously cached tree
if self.grouptree then
return self.grouptree
end
-- build the tree of groups
local tr = p.tree.new()
for prj in workspace.eachproject(self) do
local prjpath = path.join(prj.group, prj.name)
local node = p.tree.add(tr, prjpath)
node.project = prj
end
-- assign UUIDs to each node in the tree
p.tree.traverse(tr, {
onbranch = function(node)
node.uuid = os.uuid("group:" .. node.path)
end
})
-- sort by uuid for determinism.
p.tree.sort(tr, function(a,b)
return a.name < b.name
end)
self.grouptree = tr
return tr
end
--
-- Retrieve the project configuration at a particular index.
--
-- @param idx
-- An index into the array of projects.
-- @return
-- The project configuration at the given index.
--
function workspace.getproject(self, idx)
self = p.oven.bakeWorkspace(self)
return self.projects[idx]
end
---
-- Determines if the workspace contains a project that meets certain criteria.
--
-- @param func
-- A test function. Receives a project as its only argument and returns a
-- boolean indicating whether it meets to matching criteria.
-- @return
-- True if the test function returned true.
---
function workspace.hasProject(self, func)
return p.container.hasChild(self, p.project, func)
end
--
-- Return the relative path from the solution to the specified file.
--
-- @param self
-- The workspace object to query.
-- @param filename
-- The file path, or an array of file paths, to convert.
-- @return
-- The relative path, or array of paths, from the workspace to the file.
--
function workspace.getrelative(self, filename)
if type(filename) == "table" then
local result = {}
for i, name in ipairs(filename) do
if name and #name > 0 then
table.insert(result, workspace.getrelative(self, name))
end
end
return result
else
if filename then
local result = filename
if path.hasdeferredjoin(result) then
result = path.resolvedeferredjoin(result)
end
return path.getrelative(self.location, result)
end
end
end