Skip to content

Commit 72ca046

Browse files
committed
feat: allow ecsact as a project plugin in codegen tool
1 parent d752883 commit 72ca046

File tree

1 file changed

+84
-39
lines changed

1 file changed

+84
-39
lines changed

Tools/EcsactUnrealCodegen/EcsactUnrealCodegen.cpp

Lines changed: 84 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <iostream>
2+
#include <ranges>
23
#include <filesystem>
34
#ifdef __cpp_lib_execution
45
# include <execution>
@@ -152,6 +153,34 @@ auto is_clang_formattable(const fs::path& p) -> bool {
152153
ext == ".hh" || ext == ".hpp";
153154
}
154155

156+
auto trim_prefix(std::string_view str) -> std::string_view {
157+
auto index = 0;
158+
for(auto& c : str) {
159+
if(!std::isspace(c)) {
160+
break;
161+
}
162+
index += 1;
163+
}
164+
165+
return str.substr(0, index);
166+
}
167+
168+
auto trim_suffix(std::string_view str) -> std::string_view {
169+
auto trim_count = 0;
170+
for(auto& c : str | std::views::reverse) {
171+
if(!std::isspace(c)) {
172+
break;
173+
}
174+
trim_count += 1;
175+
}
176+
177+
return str.substr(0, str.size() - trim_count);
178+
}
179+
180+
auto trim(std::string_view str) -> std::string_view {
181+
return trim_prefix(trim_suffix(str));
182+
}
183+
155184
auto main(int argc, char* argv[]) -> int {
156185
auto desc = po::options_description{};
157186
auto pos_desc = po::positional_options_description{};
@@ -190,44 +219,6 @@ auto main(int argc, char* argv[]) -> int {
190219
}
191220

192221
auto engine_dir = fs::path{vm.at("engine-dir").as<std::string>()};
193-
auto engine_plugins_dir = engine_dir / "Plugins" / "Marketplace";
194-
std::cout //
195-
<< "INFO: engine directory is '" << engine_dir.generic_string() << "'\n";
196-
197-
auto ecsact_plugin_info = std::optional<plugin_dir_info>{};
198-
199-
for(auto entry : fs::directory_iterator{engine_plugins_dir}) {
200-
auto info = get_plugin_dir_info(entry.path());
201-
if(!info) {
202-
continue;
203-
}
204-
205-
if(info->plugin_name == "Ecsact") {
206-
ecsact_plugin_info = info;
207-
}
208-
}
209-
210-
if(!ecsact_plugin_info) {
211-
std::cerr //
212-
<< "ERROR: unable to find the Ecsact Unreal plugin in '"
213-
<< engine_plugins_dir.generic_string() << "'\n"
214-
<< "INFO: see https://ecsact.dev/start/unreal for installation "
215-
"instructions\n";
216-
return 1;
217-
}
218-
219-
auto ecsact_unreal_codegen_plugin =
220-
ecsact_plugin_info->plugin_path.parent_path() / "Binaries" / "Win64" /
221-
"UnrealEditor-EcsactUnrealCodegenPlugin.dll";
222-
223-
if(!fs::exists(ecsact_unreal_codegen_plugin)) {
224-
std::cerr //
225-
<< "ERROR: the Ecsact Unreal plugin does not contain the built "
226-
"EcsactUnrealCodegenPlugin - please make sure you have installed the "
227-
"Ecsact Unreal plugin correctly\n";
228-
return 1;
229-
}
230-
231222
auto project_dir = fs::path{};
232223
auto project_file = fs::path{};
233224
if(vm.count("project-path") == 0) {
@@ -280,6 +271,60 @@ auto main(int argc, char* argv[]) -> int {
280271
assert(!project_dir.empty());
281272
assert(!project_file.empty());
282273

274+
auto engine_plugins_dir = engine_dir / "Plugins" / "Marketplace";
275+
auto project_plugins_dir = project_dir / "Plugins";
276+
std::cout //
277+
<< "INFO: engine directory is '" << engine_dir.generic_string() << "'\n";
278+
279+
auto ecsact_plugin_info = std::optional<plugin_dir_info>{};
280+
281+
if(fs::exists(project_plugins_dir)) {
282+
for(auto entry : fs::directory_iterator{project_plugins_dir}) {
283+
auto info = get_plugin_dir_info(entry.path());
284+
if(!info) {
285+
continue;
286+
}
287+
288+
if(info->plugin_name == "Ecsact") {
289+
ecsact_plugin_info = info;
290+
}
291+
}
292+
}
293+
294+
if(!ecsact_plugin_info && fs::exists(engine_plugins_dir)) {
295+
for(auto entry : fs::directory_iterator{engine_plugins_dir}) {
296+
auto info = get_plugin_dir_info(entry.path());
297+
if(!info) {
298+
continue;
299+
}
300+
301+
if(info->plugin_name == "Ecsact") {
302+
ecsact_plugin_info = info;
303+
}
304+
}
305+
}
306+
307+
if(!ecsact_plugin_info) {
308+
std::cerr //
309+
<< "ERROR: unable to find the Ecsact Unreal plugin in '"
310+
<< engine_plugins_dir.generic_string() << "'\n"
311+
<< "INFO: see https://ecsact.dev/start/unreal for installation "
312+
"instructions\n";
313+
return 1;
314+
}
315+
316+
auto ecsact_unreal_codegen_plugin =
317+
ecsact_plugin_info->plugin_path.parent_path() / "Binaries" / "Win64" /
318+
"UnrealEditor-EcsactUnrealCodegenPlugin.dll";
319+
320+
if(!fs::exists(ecsact_unreal_codegen_plugin)) {
321+
std::cerr //
322+
<< "ERROR: the Ecsact Unreal plugin does not contain the built "
323+
"EcsactUnrealCodegenPlugin - please make sure you have installed the "
324+
"Ecsact Unreal plugin correctly\n";
325+
return 1;
326+
}
327+
283328
auto env = boost::process::native_environment{};
284329
auto ecsact_cli = find_ecsact_exe(argv[0]);
285330
if(!ecsact_cli) {
@@ -299,7 +344,7 @@ auto main(int argc, char* argv[]) -> int {
299344
return 1;
300345
}
301346

302-
std::cout << "INFO: ecsact version " << *version << "\n";
347+
std::cout << "INFO: ecsact version " << trim(*version) << "\n";
303348

304349
auto source_dir = project_dir / "Source";
305350
if(!fs::exists(source_dir)) {

0 commit comments

Comments
 (0)