Skip to content

Commit c081042

Browse files
authored
Fixed building on Linux doesn't work (#632)
* Fixed building on Linux doesn't work * Forced OvGame to be built before OvEditor
1 parent 12fc181 commit c081042

5 files changed

Lines changed: 40 additions & 5 deletions

File tree

Sources/OvEditor/premake5.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ project "OvEditor"
5050
"OvAudio",
5151
"OvCore",
5252
"OvDebug",
53+
"OvGame", -- Necessary to be built before the editor to allow building
5354
"OvMaths",
5455
"OvPhysics",
5556
"OvRendering",

Sources/OvEditor/src/OvEditor/Core/EditorActions.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,14 @@ void OvEditor::Core::EditorActions::Build(bool p_autoRun, bool p_tempFolder)
216216

217217
void OvEditor::Core::EditorActions::BuildAtLocation(const std::string & p_configuration, const std::filesystem::path& p_buildPath, bool p_autoRun)
218218
{
219-
std::string executableName = m_context.projectSettings.Get<std::string>("executable_name") + ".exe";
219+
const std::string extension =
220+
#if defined(_WIN32)
221+
".exe";
222+
#else
223+
"";
224+
#endif
225+
226+
const std::string executableName = m_context.projectSettings.Get<std::string>("executable_name") + extension;
220227

221228
bool failed = false;
222229

@@ -251,7 +258,8 @@ void OvEditor::Core::EditorActions::BuildAtLocation(const std::string & p_config
251258
err
252259
);
253260

254-
const auto sceneFileName = m_context.projectSettings.Get<std::string>("start_scene");
261+
auto sceneFileName = m_context.projectSettings.Get<std::string>("start_scene");
262+
sceneFileName = OvTools::Utils::PathParser::MakeNonWindowsStyle(sceneFileName);
255263

256264
if (!std::filesystem::exists(p_buildPath / "Data" / "User" / "Assets" / sceneFileName))
257265
{
@@ -330,8 +338,10 @@ void OvEditor::Core::EditorActions::BuildAtLocation(const std::string & p_config
330338
if (!err)
331339
{
332340
OVLOG_INFO("Builder data (Dlls and executable) copied");
341+
342+
const std::string initialExecutableName = "OvGame" + extension;
333343

334-
std::filesystem::rename(p_buildPath / "OvGame.exe", p_buildPath / executableName, err);
344+
std::filesystem::rename(p_buildPath / initialExecutableName, p_buildPath / executableName, err);
335345

336346
if (!err)
337347
{
@@ -344,7 +354,7 @@ void OvEditor::Core::EditorActions::BuildAtLocation(const std::string & p_config
344354

345355
if (std::filesystem::exists(exePath))
346356
{
347-
OvTools::Utils::SystemCalls::OpenFile(exePath.string(), p_buildPath.string());
357+
OvTools::Utils::SystemCalls::RunProgram(exePath.string(), p_buildPath.string());
348358
}
349359
else
350360
{

Sources/OvGame/src/OvGame/Core/Game.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <OvDebug/Logger.h>
1010
#include <OvGame/Core/Game.h>
11+
#include <OvTools/Utils/PathParser.h>
1112
#include <OvUI/Widgets/Texts/Text.h>
1213

1314
#ifdef _DEBUG
@@ -35,7 +36,9 @@ OvGame::Core::Game::Game(Context & p_context) :
3536
>();
3637
#endif
3738

38-
m_context.sceneManager.LoadScene(m_context.projectSettings.Get<std::string>("start_scene"));
39+
std::string startupScenePath = m_context.projectSettings.Get<std::string>("start_scene");
40+
startupScenePath = OvTools::Utils::PathParser::MakeNonWindowsStyle(startupScenePath);
41+
m_context.sceneManager.LoadScene(startupScenePath);
3942
m_context.sceneManager.GetCurrentScene()->Play();
4043
}
4144

Sources/OvTools/include/OvTools/Utils/SystemCalls.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ namespace OvTools::Utils
3232
*/
3333
static void OpenFile(const std::string& p_file, const std::string & p_workingDir = "");
3434

35+
/**
36+
* Run a program
37+
* @param p_file
38+
* @param p_workingDir
39+
*/
40+
static void RunProgram(const std::string& p_file, const std::string& p_workingDir = "");
41+
3542
/**
3643
* Open the given file for edition with the default application
3744
* @param p_file

Sources/OvTools/src/OvTools/Utils/SystemCalls.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@ void OvTools::Utils::SystemCalls::OpenFile(const std::string & p_file, const std
4646
#endif
4747
}
4848

49+
void OvTools::Utils::SystemCalls::RunProgram(const std::string& p_file, const std::string& p_workingDir)
50+
{
51+
#ifdef _WIN32
52+
OpenFile(p_file, p_workingDir);
53+
#else
54+
std::string command = "\"" + p_file + "\" &";
55+
if (!p_workingDir.empty())
56+
{
57+
command = "cd \"" + p_workingDir + "\" && " + command;
58+
}
59+
std::system(command.c_str());
60+
#endif
61+
}
62+
4963
void OvTools::Utils::SystemCalls::EditFile(const std::string & p_file)
5064
{
5165
#ifdef _WIN32

0 commit comments

Comments
 (0)