Skip to content

Commit ca4805d

Browse files
committed
stdout flag working for codegen subcommand
1 parent b225ad7 commit ca4805d

File tree

3 files changed

+87
-33
lines changed

3 files changed

+87
-33
lines changed

.vscode/launch.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
{
22
"version": "0.2.0",
3+
"inputs": [
4+
{
5+
"id": "plugin_name",
6+
"type": "pickString",
7+
"description": "Plugin name",
8+
"options": [
9+
"cpp_header",
10+
"cpp_meta_header",
11+
"cpp_systems_header",
12+
"csharp",
13+
"json",
14+
"systems_header"
15+
]
16+
}
17+
],
318
"configurations": [
419
{
520
"name": "run //cli:ecsact codegen (all plugins)",
@@ -23,6 +38,28 @@
2338
"program": "${workspaceFolder}/bazel-bin/cli/ecsact.exe"
2439
},
2540
"preLaunchTask": "build //..."
41+
},
42+
{
43+
"name": "run //cli:ecsact codegen (stdout)",
44+
"request": "launch",
45+
"program": "${workspaceFolder}/bazel-bin/cli/ecsact",
46+
"cwd": "${workspaceFolder}",
47+
"args": [
48+
"codegen",
49+
"${workspaceFolder}/examples/example.ecsact",
50+
"${workspaceFolder}/examples/extras.ecsact",
51+
"--plugin=${workspaceFolder}/dist/share/ecsact/plugins/ecsact_${input:plugin_name}_codegen",
52+
"--stdout"
53+
],
54+
"type": "cppdbg",
55+
"windows": {
56+
"type": "cppvsdbg",
57+
"program": "${workspaceFolder}/bazel-bin/cli/ecsact.exe"
58+
},
59+
"preLaunchTask": "copy dist plugins",
60+
"sourceFileMap": {
61+
"E:/.cache/bazel/output_base/execroot/ecsact_sdk": "${workspaceFolder}"
62+
}
2663
}
2764
],
2865
"compounds": []

.vscode/tasks.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@
2020
"//..."
2121
],
2222
"group": "build"
23+
},
24+
{
25+
"label": "copy dist plugins",
26+
"command": "bazel",
27+
"type": "shell",
28+
"args": [
29+
"run",
30+
"//:copy_dist_codegen_plugins"
31+
],
32+
"dependsOn": [
33+
"build //..."
34+
]
2335
}
24-
]
36+
],
2537
}

cli/commands/codegen.cc

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ constexpr auto file_readonly_perms =
2626
constexpr auto USAGE = R"(Ecsact Codegen Command
2727
2828
Usage:
29-
ecsact codegen <files> --plugin=<plugin> [--stdout]
29+
ecsact codegen <files>... --plugin=<plugin> [--stdout]
3030
ecsact codegen <files>... --plugin=<plugin>... [--outdir=<directory>]
3131
3232
Options:
@@ -238,42 +238,47 @@ int ecsact::cli::detail::codegen_command(int argc, char* argv[]) {
238238
}
239239
}
240240

241-
for(auto package_id : package_ids) {
242-
fs::path output_file_path = ecsact_meta_package_file_path(package_id);
243-
if(output_file_path.empty()) {
244-
std::cerr
245-
<< "[ERROR] Could not find package source file path from "
246-
<< "'ecsact_meta_package_file_path'\n";
247-
continue;
248-
}
241+
if(args.at("--stdout").asBool()) {
242+
plugin_fn(*package_ids.begin(), &stdout_write_fn);
243+
std::cout.flush();
244+
} else {
245+
for(auto package_id : package_ids) {
246+
fs::path output_file_path = ecsact_meta_package_file_path(package_id);
247+
if(output_file_path.empty()) {
248+
std::cerr
249+
<< "[ERROR] Could not find package source file path from "
250+
<< "'ecsact_meta_package_file_path'\n";
251+
continue;
252+
}
249253

250-
output_file_path.replace_extension(
251-
output_file_path.extension().string() + "." + plugin_name
252-
);
254+
output_file_path.replace_extension(
255+
output_file_path.extension().string() + "." + plugin_name
256+
);
253257

254-
if(outdir) {
255-
output_file_path = *outdir / output_file_path.filename();
256-
}
258+
if(outdir) {
259+
output_file_path = *outdir / output_file_path.filename();
260+
}
257261

258-
if(output_paths.contains(output_file_path.string())) {
259-
has_plugin_error = true;
260-
std::cerr
261-
<< "[ERROR] Plugin '"
262-
<< plugin.location().filename().string()
263-
<< "' has conflicts with another plugin output file '"
264-
<< output_file_path.string() << "'\n";
265-
continue;
266-
}
262+
if(output_paths.contains(output_file_path.string())) {
263+
has_plugin_error = true;
264+
std::cerr
265+
<< "[ERROR] Plugin '"
266+
<< plugin.location().filename().string()
267+
<< "' has conflicts with another plugin output file '"
268+
<< output_file_path.string() << "'\n";
269+
continue;
270+
}
267271

268-
output_paths.emplace(output_file_path.string());
269-
if(fs::exists(output_file_path)) {
270-
fs::permissions(output_file_path, fs::perms::all);
272+
output_paths.emplace(output_file_path.string());
273+
if(fs::exists(output_file_path)) {
274+
fs::permissions(output_file_path, fs::perms::all);
275+
}
276+
file_write_stream.open(output_file_path);
277+
plugin_fn(package_id, &file_write_fn);
278+
file_write_stream.flush();
279+
file_write_stream.close();
280+
fs::permissions(output_file_path, file_readonly_perms);
271281
}
272-
file_write_stream.open(output_file_path);
273-
plugin_fn(package_id, &file_write_fn);
274-
file_write_stream.flush();
275-
file_write_stream.close();
276-
fs::permissions(output_file_path, file_readonly_perms);
277282
}
278283

279284
plugin.unload();

0 commit comments

Comments
 (0)