-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathvsandroid_packaging.lua
More file actions
322 lines (247 loc) · 8.27 KB
/
Copy pathvsandroid_packaging.lua
File metadata and controls
322 lines (247 loc) · 8.27 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
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
---
-- VSAndroid/vsandroid_packaging.lua
-- VS Android projects generator.
-- Copyright (c) 2015 Dmytro "StiX" Vovk and the Premake project
---
premake.modules.vsandroid_packaging = {}
local p = premake
local pack = p.modules.vsandroid_packaging
local vc2010 = p.vstudio.vc2010
local project = p.project
local vstudio = p.vstudio
local solution = p.solution
local tree = premake.tree
---
-- Override vs action's methods
---
premake.override(vstudio, "tool", function(oldfn, prj)
if prj.kind == "Packaging" then
return "39E2626F-3545-4960-A6E8-258AD8476CE5"
end
return oldfn(prj)
end)
function pack.configurationPlatforms(sln) -- TODO: refactor original premake to fix this
local descriptors = {}
local sorted = {}
for cfg in solution.eachconfig(sln) do
-- Create a Visual Studio solution descriptor (i.e. Debug|Win32) for
-- this solution configuration. I need to use it in a few different places
-- below so it makes sense to precompute it up front.
local platform = vstudio.solutionPlatform(cfg)
descriptors[cfg] = string.format("%s|%s", cfg.buildcfg, platform)
-- Also add the configuration to an indexed table which I can sort below
table.insert(sorted, cfg)
end
-- Sort the solution configurations to match Visual Studio's preferred
-- order, which appears to be a simple alpha sort on the descriptors.
table.sort(sorted, function(cfg0, cfg1)
return descriptors[cfg0]:lower() < descriptors[cfg1]:lower()
end)
-- Now I can output the sorted list of solution configuration descriptors
-- Visual Studio assumes the first configurations as the defaults.
if sln.defaultplatform then
_p(1,'GlobalSection(SolutionConfigurationPlatforms) = preSolution')
table.foreachi(sorted, function (cfg)
if cfg.platform == sln.defaultplatform then
_p(2,'%s = %s', descriptors[cfg], descriptors[cfg])
end
end)
_p(1,"EndGlobalSection")
end
_p(1,'GlobalSection(SolutionConfigurationPlatforms) = preSolution')
table.foreachi(sorted, function (cfg)
if not sln.defaultplatform or cfg.platform ~= sln.defaultplatform then
_p(2,'%s = %s', descriptors[cfg], descriptors[cfg])
end
end)
_p(1,"EndGlobalSection")
-- For each project in the solution...
_p(1,"GlobalSection(ProjectConfigurationPlatforms) = postSolution")
local tr = solution.grouptree(sln)
tree.traverse(tr, {
onleaf = function(n)
local prj = n.project
-- For each (sorted) configuration in the solution...
table.foreachi(sorted, function (cfg)
local platform, architecture
-- Look up the matching project configuration. If none exist, this
-- configuration has been excluded from the project, and should map
-- to closest available project configuration instead.
local prjCfg = project.getconfig(prj, cfg.buildcfg, cfg.platform)
local excluded = (prjCfg == nil or prjCfg.flags.ExcludeFromBuild)
if prjCfg == nil then
prjCfg = project.findClosestMatch(prj, cfg.buildcfg, cfg.platform)
end
local descriptor = descriptors[cfg]
local platform = vstudio.projectPlatform(prjCfg)
local architecture = vstudio.archFromConfig(prjCfg, true)
_p(2,'{%s}.%s.ActiveCfg = %s|%s', prj.uuid, descriptor, platform, architecture)
-- Only output Build.0 entries for buildable configurations
if not excluded and prjCfg.kind ~= premake.NONE then
_p(2,'{%s}.%s.Build.0 = %s|%s', prj.uuid, descriptor, platform, architecture)
if prjCfg.kind == "Packaging" then
_p(2,'{%s}.%s.Deploy.0 = %s|%s', prj.uuid, descriptor, platform, architecture)
end
end
end)
end
})
_p(1,"EndGlobalSection")
end
premake.override(vstudio.sln2005.elements, "sections", function(oldfn, prj)
local elements = oldfn(cfg)
if _ACTION == "android" then
table.replace(elements, vstudio.sln2005.configurationPlatforms, pack.configurationPlatforms)
end
return elements
end)
pack.elements = {}
pack.elements.project = function(prj)
return {
vc2010.xmlDeclaration,
pack.project,
vc2010.projectConfigurations,
pack.globals,
pack.importDefaultProps,
pack.configurationPropertiesGroup,
pack.importExtensionSettings,
vc2010.userMacros,
pack.itemDefinitionGroups,
pack.files,
vc2010.projectReferences,
pack.importExtensionTargets,
}
end
function pack.generatePackaging(prj)
p.utf8()
p.callArray(pack.elements.project, prj)
p.out('</Project>')
end
pack.elements.globals = function(prj)
return {
pack.keyword,
vc2010.projectGuid,
vc2010.ignoreWarnDuplicateFilename,
}
end
function pack.globals(prj)
vc2010.propertyGroup(nil, "Globals")
p.callArray(pack.elements.globals, prj)
p.pop('</PropertyGroup>')
end
function pack.keyword(prj)
vc2010.element("RootNamespace", nil, "%s", prj.name)
vc2010.element("MinimumVisualStudioVersion", nil, "14.0")
vc2010.element("ProjectVersion", nil, "1.0")
end
function pack.importDefaultProps(prj)
p.w('<Import Project="$(AndroidTargetsPath)\\Android.Default.props" />')
end
function pack.configurationPropertiesGroup(prj)
for cfg in project.eachconfig(prj) do
pack.configurationProperties(cfg)
end
end
function pack.useDebugLibraries(cfg)
local runtime = vstudio.projectPlatform(cfg)
vc2010.element("UseDebugLibraries", nil, tostring(runtime:endswith("Debug")))
end
function pack.configurationProperties(cfg)
vc2010.propertyGroup(cfg, "Configuration")
pack.useDebugLibraries(cfg)
p.pop('</PropertyGroup>')
end
function pack.importExtensionSettings(prj)
p.w('<Import Project="$(AndroidTargetsPath)\\Android.props" />')
p.w('<ImportGroup Label="ExtensionSettings" />')
p.w('<ImportGroup Label="Shared" />')
end
--
-- Write a configuration's item definition group, which contains all
-- of the per-configuration compile and link settings.
--
pack.elements.antPackage = function(cfg)
return {
pack.androidAppLibName,
pack.applicationName,
pack.workingDirectory,
pack.antTarget,
pack.additionalOptions,
}
end
function pack.antPackage(cfg)
p.push('<AntPackage>')
p.callArray(pack.elements.antPackage, cfg)
p.pop('</AntPackage>')
end
function pack.itemDefinitionGroup(cfg)
p.push('<ItemDefinitionGroup %s>', vc2010.condition(cfg))
pack.antPackage(cfg)
p.pop('</ItemDefinitionGroup>')
end
function pack.itemDefinitionGroups(prj)
for cfg in project.eachconfig(prj) do
pack.itemDefinitionGroup(cfg)
end
end
function pack.androidAppLibName(cfg)
vc2010.element("AndroidAppLibName", nil, cfg.applibname or "$(RootNamespace)")
end
function pack.applicationName(cfg)
if cfg.targetname ~= nil then
vc2010.element("ApplicationName", nil, cfg.targetname)
end
end
function pack.workingDirectory(cfg)
if cfg.targetdir ~= nil then
vc2010.element("WorkingDirectory", nil, cfg.targetdir)
end
end
function pack.antTarget(cfg)
-- TODO: should I expose this, should I fall to default options or should I stick to Debug\Release configs?!
end
function pack.additionalOptions(cfg)
if #cfg.deploymentoptions > 0 then
local opts = table.concat(cfg.deploymentoptions, " ")
vc2010.element("AdditionalOptions", nil, opts)
end
end
function pack.importExtensionTargets(prj)
p.w('<Import Project="$(AndroidTargetsPath)\\Android.targets" />')
p.w('<ImportGroup Label="ExtensionTargets" />')
end
vc2010.elements.ContentFile = function(cfg, file)
return {}
end
vc2010.elements.ContentFileCfg = function(fcfg, condition)
return {}
end
function pack.antBuild(prj)
if prj.antbuild ~= nil then
p.x('<AntBuildXml Include="%s" />', prj.antbuild)
end
end
function pack.antProperties(prj)
if prj.antproperties ~= nil then
p.x('<AntProjectPropertiesFile Include="%s" />', prj.antproperties)
end
end
function pack.manifest(prj)
if prj.androidmanifest ~= nil then
p.x('<AndroidManifest Include="%s" />', prj.androidmanifest)
end
end
function pack.files(prj)
local groups = vc2010.categorizeSources(prj)
for _, group in ipairs(groups) do
vc2010.emitFiles(prj, group, "Content")
end
p.push('<ItemGroup>')
pack.antBuild(prj)
pack.manifest(prj)
pack.antProperties(prj)
p.pop('</ItemGroup>')
end
function pack.project(prj)
p.push('<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">')
end