3 #include <Strings/components/logger/logger.h>
4 #include <Strings/components/utils/io/io.h>
5 #include <Strings/components/utils/string/string.h>
6 #include <Strings/components/utils/list/list.h>
7 #include <Strings/components/3rdparty/rapidxml/rapidxml.hpp>
8 #include <Strings/components/classes/map/map.h>
9 #include <Strings/components/utils/converters/converters.h>
10 #include <HEKGuerilla/components/projects/projects.h>
12 #include "../ToolCommand.hpp"
13 #include "../console.h"
16 #ifdef TOOL_LIB_EXPORTS
17 #define TOOL_LIB_API __declspec(dllexport)
19 #define TOOL_LIB_API __declspec(dllimport)
31 bool rebuild_scripts =
false;
34 std::vector<std::string> PreprocessArgs(std::vector<std::string> args)
36 std::vector<std::string> processed_args = std::vector<std::string>();
38 for (
int i = 0; i < args.size(); i++)
40 if (args[i] ==
"-verbose")
44 else if (args[i] ==
"-rebuild-scripts")
46 rebuild_scripts =
true;
48 else if (args[i] ==
"-package")
54 processed_args.push_back(args[i]);
58 return processed_args;
65 syntax =
"build <configuration> <platform> [project filename] [game vcxproj filepath] [-verbose] [-rebuild-scripts] [-package]";
66 description =
"builds the current project into a playable game executable";
69 int execute(std::vector<std::string> args)
71 args = PreprocessArgs(args);
75 BlamStrings::Logger::LogEvent(
"failed to build executable: you must supply a configuration and platform", WSV_ERROR);
76 BlamStrings::Logger::LogEvent(
"syntax: " + syntax, WSV_ERROR);
81 std::string project_filename = BlamStrings::Utils::IO::GetFileNameWithoutExtension(project_root) +
".blam";
85 project_filename = args[2];
88 BlamProject* project_info = Guerilla::Projects::LoadProject(project_root + project_filename);
90 if (!project_info->IsLoaded())
92 BlamStrings::Logger::LogEvent(
"failed to create stub project: could not load project info (tried to "
93 "read from file path: " + project_root + project_filename +
")", WSV_ERROR);
97 BlamStrings::Logger::LogEvent(
"project path was assumed from directory path - if your .blam file "
98 "has a different name, use " + syntax +
" to specify the filename", WSV_WARNING);
105 std::string game_vcx_dir = project_root +
"_build/_internal/game/";
106 std::string game_vcx_path = game_vcx_dir +
"game.vcxproj";
110 game_vcx_path = args[3];
113 if (project_info->cpp_script_info.pre_build_commands.length() > 0)
115 BlamStrings::Logger::LogEvent(
"running pre-build commands");
117 std::string input = str_replace(project_info->cpp_script_info.pre_build_commands,
"\r\n",
"\n");
119 for (std::string line : BlamStrings::Utils::String::Split(input,
"\n"))
121 system(line.c_str());
125 int build_result = 0;
130 std::string msbuild_path_base =
"\"" + project_info->GetMSBuildPath() +
"\" \"" + project_info->GetVcxprojPath() +
"\" ";
131 std::string cmd =
"\"" + msbuild_path_base +
"/p:Configuration=\"" + args[0] +
"\" /p:Platform=\"" + args[1] +
"\"" +
"\"";
133 if (verbose) BlamStrings::Logger::LogEvent(
"running system command :: " + cmd);
134 build_result = system(cmd.c_str());
138 if (build_result >= 0)
140 if (!GenerateProjectInfoSourceFile(project_info, game_vcx_dir +
"gameinfo.cpp", !package,
141 BlamStrings::Utils::IO::GetAbsolutePathFromRelative(project_root)))
143 BlamStrings::Logger::LogEvent(
"failed to generate embedded game info file - CreateNewFile returned false", WSV_ERROR);
148 std::string msbuild_path_base =
"\"" + project_info->GetMSBuildPath() +
"\" \"" + game_vcx_path +
"\" ";
149 std::string cmd =
"\"" + msbuild_path_base +
"/p:Configuration=\"" + args[0] +
"\" /p:Platform=\"" + args[1] +
"\"" +
"\"";
151 if (verbose) BlamStrings::Logger::LogEvent(
"running system command :: " + cmd);
152 build_result = system(cmd.c_str());
155 if (build_result < 0)
157 BlamStrings::Logger::LogEvent(
"build failed with code " + std::to_string(build_result) +
" - see log for details", WSV_ERROR);
162 if (project_info->cpp_script_info.post_build_commands.length() > 0)
164 BlamStrings::Logger::LogEvent(
"running post-build commands");
166 std::string input = str_replace(project_info->cpp_script_info.post_build_commands,
"\r\n",
"\n");
168 for (std::string line : BlamStrings::Utils::String::Split(input,
"\n"))
170 system(line.c_str());
174 BlamStrings::Logger::LogEvent(
"finished");
182 std::string template_file = BlamStrings::Utils::IO::GetFileContentsAsString(
"./content/blam/default_stub_project/gameinfo.cpp.template");
184 BlamMap<std::string, std::string> replacements = BlamMap<std::string, std::string>();
186 replacements.Add(
"{project_name}", project_info->project_name);
188 replacements.Add(
"{game_info.title}", project_info->game_info.title);
189 replacements.Add(
"{game_info.codename}", project_info->game_info.codename);
190 replacements.Add(
"{game_info.publisher}", project_info->game_info.publisher);
191 replacements.Add(
"{game_info.developer}", project_info->game_info.developer);
192 replacements.Add(
"{game_info.affiliates}", project_info->game_info.affiliates);
193 replacements.Add(
"{game_info.copyright}", project_info->game_info.copyright);
194 replacements.Add(
"{game_info.website}", project_info->game_info.website);
195 replacements.Add(
"{game_info.version}", project_info->game_info.version);
196 replacements.Add(
"{game_info.icon}", project_info->game_info.icon);
197 replacements.Add(
"{cpp_script_info.uses_cpp_script}", BlamStrings::Converters::BoolToString(project_info->cpp_script_info.uses_cpp_script));
198 replacements.Add(
"{cpp_script_info.vcxproj_path}", project_info->cpp_script_info.vcxproj_path);
199 replacements.Add(
"{cpp_script_info.engine_dependencies_path}", project_info->cpp_script_info.engine_dependencies_path);
200 replacements.Add(
"{cpp_script_info.msbuild_path}", project_info->cpp_script_info.msbuild_path);
201 replacements.Add(
"{cpp_script_info.msbuild_extra_args}", project_info->cpp_script_info.msbuild_extra_args);
202 replacements.Add(
"{cpp_script_info.pre_build_commands}", project_info->cpp_script_info.pre_build_commands);
203 replacements.Add(
"{cpp_script_info.post_build_commands}", project_info->cpp_script_info.post_build_commands);
204 replacements.Add(
"{engine_settings.user_data_folder}", project_info->engine_settings.user_data_folder);
205 replacements.Add(
"{engine_settings.default_cache}", project_info->engine_settings.default_cache);
206 replacements.Add(
"{engine_settings.campaign_info}", project_info->engine_settings.campaign_info);
207 replacements.Add(
"{engine_settings.startup_movie}", project_info->engine_settings.startup_movie);
208 replacements.Add(
"{engine_settings.content_root}", project_info->engine_settings.content_root);
209 replacements.Add(
"{engine_settings.tags_dir}", project_info->engine_settings.tags_dir);
210 replacements.Add(
"{engine_settings.movies_dir}", project_info->engine_settings.movies_dir);
211 replacements.Add(
"{engine_settings.data_dir}", project_info->engine_settings.data_dir);
212 replacements.Add(
"{engine_settings.cache_dir}", project_info->engine_settings.cache_dir);
213 replacements.Add(
"{engine_settings.plugins_dir}", project_info->engine_settings.plugins_dir);
214 replacements.Add(
"{engine_settings.fonts_dir}", project_info->engine_settings.fonts_dir);
215 replacements.Add(
"{engine_settings.allow_user_tag_overrides}", BlamStrings::Converters::BoolToString(project_info->engine_settings.allow_user_tag_overrides));
218 if (use_project_dirs)
220 if (!project_root.ends_with(
"/"))
225 replacements.Add(
"{engine_settings.tags_dir}", project_root + project_info->engine_settings.tags_dir);
226 replacements.Add(
"{engine_settings.movies_dir}", project_root + project_info->engine_settings.movies_dir);
227 replacements.Add(
"{engine_settings.plugins_dir}", project_root + project_info->engine_settings.plugins_dir);
228 replacements.Add(
"{engine_settings.fonts_dir}", project_root + project_info->engine_settings.fonts_dir);
231 for (std::string key : replacements.KeySet())
233 std::string value = replacements.At(key);
235 value = str_replace(value,
"\\",
"\\\\");
236 value = str_replace(value,
"\r\n",
"\n");
237 value = str_replace(value,
"\n",
"\\n");
238 value = str_replace(value,
"\"",
"\\\"");
240 template_file = str_replace(template_file, key, value);
243 return BlamStrings::Utils::IO::CreateNewFile(output_file, template_file);