-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathphobos_profiles
More file actions
291 lines (257 loc) · 8.72 KB
/
Copy pathphobos_profiles
File metadata and controls
291 lines (257 loc) · 8.72 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
local profiles = require("phobos_profiles")
local util = require("util")
local io_util = require("io_util")
local gen_util = require("scripts.generate_docs_util")
local args = profiles.parse_extra_args({...}, {
options = {
{
field = "platform",
long = "platform",
short = "p",
description = "When omitted no standalone profiles will be added.\n\z
Possible values: 'linux', 'osx' or 'windows'.",
type = "string",
single_param = true,
optional = true,
},
{
field = "generate_docs",
long = "generate-docs",
short = "d",
description = "Generate documentation in the docs folder.",
flag = true,
},
},
})
local platform_arg = args.platform
if platform_arg then
util.assert(util.invert{"linux", "osx", "windows"}[platform_arg],
"Expected 'linux', 'osx' or 'windows', got '"..platform_arg.."' for --platform."
)
end
local phobos_extension = ".lua"
local function exclude(profile, path)
profiles.exclude{
profile = profile,
source_path = "src/"..path,
}
end
local function exclude_delete(profile, path)
profiles.exclude_delete{
profile = profile,
output_path = path,
}
end
local function include_copy(profile, path, output_path)
profiles.include_copy{
profile = profile,
source_path = path,
output_path = output_path or path,
}
end
local function apply_general_changes(profile)
-- delete every single file that is not currently being outputted
profiles.include_delete{
profile = profile,
output_path = ".",
}
exclude(profile, "classes"..phobos_extension)
exclude(profile, "profile_classes"..phobos_extension)
-- TODO: replace thumbnail_1080_1080.png with thumbnail_144_144.png in the output, without using some hack
include_copy(profile, "README.md")
include_copy(profile, "changelog.txt")
include_copy(profile, "LICENSE.txt")
include_copy(profile, "LICENSE_THIRD_PARTY.txt")
include_copy(profile, "thumbnail_1080_1080.png")
-- docs specific
-- these get added regardless of the generate_docs flag because it's incremental anyway
exclude_delete(profile, "docs/phobos_profiles.html")
exclude_delete(profile, "docs/concepts.html")
include_copy(profile, "docs/styles.css")
include_copy(profile, "docs/images/favicon.png")
-- NOTE: maybe, probably render these markdown files as html. If so, also render the readme,
-- or change it somehow to either be in the docs folder or have a different "index" file in the docs folder
profiles.include_copy{
profile = profile,
source_path = "docs",
output_path = "docs",
filename_pattern = "%.md$",
}
end
local function copy_emmy_lua_docs(profile)
include_copy(profile, "docs/emmy_lua")
profiles.exclude_copy{
profile = profile,
source_path = "docs/emmy_lua/profiles/profile_classes.lua",
}
include_copy(profile, "src/profile_classes.lua", "docs/emmy_lua/profiles/profile_classes.lua")
include_copy(profile, "src/lib/LuaArgParser/classes.lua", "docs/emmy_lua/profiles/arg_parser_classes.lua")
end
local function apply_standalone_specific_changes(profile, platform)
exclude(profile, "control"..phobos_extension)
-- NOTE: this might actually be using .lua no matter what
exclude(profile, "lib/LuaArgParser/classes"..phobos_extension)
copy_emmy_lua_docs(profile)
if platform then
include_copy(profile, "bin/"..platform, "bin")
local launch_script_file = "phobos"..(platform == "windows" and ".bat" or "")
include_copy(profile, "launch_scripts/"..launch_script_file, launch_script_file)
if platform == "windows" then
-- don't have install and uninstall scripts for windows (yet?)
else
include_copy(profile, "launch_scripts/install_phobos", "install_phobos")
include_copy(profile, "launch_scripts/uninstall_phobos", "uninstall_phobos")
end
end
end
local function apply_factorio_specific_changes(profile)
exclude(profile, "lib/LFSClasses")
exclude(profile, "lib/LuaArgParser")
exclude(profile, "lib/LuaPath")
exclude(profile, "cache"..phobos_extension)
exclude(profile, "entry_point"..phobos_extension)
exclude(profile, "io_util"..phobos_extension)
exclude(profile, "main"..phobos_extension)
exclude(profile, "phobos_profiles"..phobos_extension)
exclude(profile, "profile_classes"..phobos_extension)
exclude(profile, "profile_util"..phobos_extension)
exclude(profile, "sandbox_util"..phobos_extension)
exclude(profile, "shell_util"..phobos_extension)
include_copy(profile, "info.json")
include_copy(profile, "thumbnail_144_144_padded.png", "thumbnail.png")
end
local function generate_docs(output_root)
print("generating docs")
gen_util.generate_docs(output_root)
end
local function standalone_profile(params)
local output_dir = params.publish
and "temp/publish/"..params.name
or "out/"..params.name
local profile = profiles.add_profile{
name = params.name,
output_dir = output_dir,
cache_dir = params.publish
and "temp/publish/cache/"..params.name
or "temp/cache/"..params.name,
phobos_extension = phobos_extension,
optimizations = params.optimizations,
-- HACK: until https://github.com/tomblind/local-lua-debugger-vscode/issues/56 is implemented
use_load = not params.publish,
}
profiles.include{
profile = profile,
source_path = "src",
source_name = "@src/?",
output_path = ".",
}
apply_general_changes(profile)
apply_standalone_specific_changes(profile, params.platform)
if params.publish or args.generate_docs then
function profile.on_post_profile_ran()
local output_root = profiles.get_current_root_dir().."/"..output_dir
generate_docs(output_root)
end
end
end
local function factorio_profile(params)
local output_dir = params.publish
and "temp/publish/"..params.name.."_factorio/phobos"
or "out/"..params.name.."_factorio/phobos"
local profile = profiles.add_profile{
name = params.name.."_factorio",
output_dir = output_dir,
cache_dir = params.publish
and "temp/publish/cache/"..params.name.."_factorio"
or "temp/cache/"..params.name.."_factorio",
phobos_extension = phobos_extension,
optimizations = params.optimizations,
use_load = true,
inject_scripts = {"scripts/build_factorio_mod_ast_inject.pho"},
}
profiles.include{
profile = profile,
source_path = "src",
source_name = "@__phobos__/src/?",
output_path = ".",
}
-- For the debugger to find source files. Not the most convenient solution, but it works.
if not params.publish then
profiles.include_copy{
profile = profile,
source_path = "src",
output_path = "src",
filename_pattern = "%.lua$",
}
end
-- TODO: either change doc generation to not need the files in the output
-- or remove docs from teh mod entirely
copy_emmy_lua_docs(profile)
apply_general_changes(profile)
apply_factorio_specific_changes(profile)
function profile.on_post_profile_ran()
local output_root = profiles.get_current_root_dir().."/"..output_dir
if params.publish or args.generate_docs then
generate_docs(output_root)
end
if not params.publish then
local function link(old, new)
if not io_util.exists(new) then
io_util.symlink(old, new)
end
end
-- create symlinks for the 2 other mods needed to use the minimal-no-base-mod debug launch profiles
-- these links are in the parent directory of the output directory, so no need to exclude_delete them
link("../../debugging/minimal-no-base-mod", output_root.."/../minimal-no-base-mod")
link("../../debugging/JanSharpDevEnv", output_root.."/../JanSharpDevEnv")
end
end
end
if platform_arg then
standalone_profile{
name = "debug",
platform = platform_arg,
}
standalone_profile{
name = "release",
platform = platform_arg,
optimizations = profiles.get_all_optimizations(),
}
else
print("Info: Standalone profiles 'debug' and 'release' only get added if the \z
'--platform' extra arg was provided."
)
end
standalone_profile{
name = "debug_raw",
platform = nil,
}
standalone_profile{
name = "release_raw",
platform = nil,
optimizations = profiles.get_all_optimizations(),
}
factorio_profile{
name = "debug",
}
factorio_profile{
name = "release",
optimizations = profiles.get_all_optimizations(),
}
factorio_profile{
name = "publish",
publish = true,
optimizations = profiles.get_all_optimizations(),
}
local function standalone_publish_profile(platform)
standalone_profile{
name = "publish_"..platform,
publish = true,
platform = platform ~= "raw" and platform or nil,
optimizations = profiles.get_all_optimizations(),
}
end
standalone_publish_profile("linux")
standalone_publish_profile("osx")
standalone_publish_profile("windows")
standalone_publish_profile("raw")