11#include " ecsact/cli/commands/build.hh"
22
33#include < memory>
4- #include < iostream>
54#include < format>
65#include < filesystem>
76#include < array>
@@ -58,6 +57,33 @@ constexpr auto allowed_recipe_extensions = std::array{
5857 " .json" sv, // json works since yaml is a superset
5958};
6059
60+ auto resolve_builtin_recipe ( //
61+ std::string recipe_str,
62+ const char * argv[]
63+ ) -> std::optional<fs::path> {
64+ using namespace std ::string_literals;
65+
66+ auto exec_path = ecsact::cli::detail::canon_argv0 (argv[0 ]);
67+ auto install_prefix = exec_path.parent_path ().parent_path ();
68+ auto recipes_dir = install_prefix / " share" / " ecsact" / " recipes" ;
69+
70+ if (fs::exists (recipes_dir)) {
71+ for (auto & entry : fs::directory_iterator (recipes_dir)) {
72+ auto filename = entry.path ().filename ().replace_extension (" " ).string ();
73+ const auto prefix = " ecsact_" s;
74+
75+ auto stripped_filename = filename.substr (prefix.size (), filename.size ());
76+
77+ if (recipe_str == stripped_filename) {
78+ auto path = fs::path (filename);
79+ path.replace_extension (" .ecsact-recipe-bundle" );
80+ return recipes_dir / path;
81+ }
82+ }
83+ }
84+ return std::nullopt ;
85+ }
86+
6187auto ecsact::cli::detail::build_command ( //
6288 int argc,
6389 const char * argv[]
@@ -82,7 +108,15 @@ auto ecsact::cli::detail::build_command( //
82108 auto recipe_composite = std::optional<build_recipe>{};
83109 auto recipe_paths = args.at (" --recipe" ).asStringList ();
84110 for (auto & recipe_path_str : recipe_paths) {
85- auto recipe_path = fs::path{recipe_path_str};
111+ auto builtin_path = resolve_builtin_recipe (recipe_path_str, argv);
112+
113+ fs::path recipe_path;
114+ if (builtin_path) {
115+ recipe_path = *builtin_path;
116+ } else {
117+ recipe_path = fs::path{recipe_path_str};
118+ }
119+
86120 if (std::ranges::find (allowed_recipe_extensions, recipe_path.extension ()) ==
87121 allowed_recipe_extensions.end ()) {
88122 ecsact::cli::report_error (
@@ -168,8 +202,8 @@ auto ecsact::cli::detail::build_command( //
168202 }
169203 ecsact::cli::report_error (
170204 " Build recipes do not resolve all imports. Make sure all imported "
171- " functions in provided recipes are also exported by another recipe. If "
172- " you would like to allow unresolved imports you may provide the "
205+ " functions in provided recipes are also exported by another recipe. "
206+ " If you would like to allow unresolved imports you may provide the "
173207 " --allow-unresolved-imports flag to suppress this error."
174208 );
175209 return 1 ;
0 commit comments