-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathpremake5.lua
54 lines (37 loc) · 1.34 KB
/
premake5.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
newoption {
trigger = "protogen",
description = "Generate ProtoBuf serialization classes"
}
local protoGen = _OPTIONS["protogen"]
local function joinPath(...)
local args = arg or {...}
if #args == 0 then return nil end
if #args == 1 then return args[1] end
return path.join(args[1], joinPath(select(2, unpack(args))))
end
--
-- ProtoBuf generation
--
local function protoGen(projPath)
local exePath = path.translate(path.getabsolute(joinPath("Tools", "CodeGenerator.exe")))
local assPath = path.getabsolute(joinPath(projPath, "Assets"))
local outPath = joinPath("Scripts", "Generated", "ProtocolBuffers.cs")
local files = { joinPath(assPath, "ProtoBuf"), joinPath(assPath, "Scripts") }
for i, f in ipairs(files) do
files[i] = string.format('"%s"', f)
end
local mono = ""
if os.get() ~= "windows" then mono = "mono " end
local format = "cd \"%s\" && %s\"%s\" %s --output \"%s\" --preserve-names"
local call = string.format(format, assPath, mono, exePath, table.concat(files, " "), outPath)
print(call)
local pwd = _WORKING_DIR
local exitCode = os.execute(call)
os.execute(string.format("cd \"%s\"", pwd))
return exitCode == 0
end
if protoGen then
local protoGenSuccess = protoGen(".")
if protoGenSuccess then os.exit(0) else os.exit(1) end
end
os.exit(0)