Skip to content

Commit

Permalink
Add alternative search locations for msbuild
Browse files Browse the repository at this point in the history
  • Loading branch information
neikeq committed Oct 4, 2017
1 parent d5caf71 commit b4d758e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 9 deletions.
10 changes: 9 additions & 1 deletion modules/mono/editor/GodotSharpTools/Build/BuildSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ public class BuildInstance : IDisposable

private static string MSBuildPath
{
get { return godot_icall_BuildInstance_get_MSBuildPath(); }
get
{
string ret = godot_icall_BuildInstance_get_MSBuildPath();

if (ret == null)
throw new FileNotFoundException("Cannot find the MSBuild executable.");

return ret;
}
}

private string solution;
Expand Down
54 changes: 46 additions & 8 deletions modules/mono/editor/godotsharp_builds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@
/*************************************************************************/
#include "godotsharp_builds.h"

#include "main/main.h"

#include "../godotsharp_dirs.h"
#include "../mono_gd/gd_mono_class.h"
#include "../mono_gd/gd_mono_marshal.h"
#include "../utils/path_utils.h"
#include "bindings_generator.h"
#include "godotsharp_editor.h"
#include "main/main.h"

void godot_icall_BuildInstance_ExitCallback(MonoString *p_solution, MonoString *p_config, int p_exit_code) {

Expand All @@ -44,11 +45,37 @@ void godot_icall_BuildInstance_ExitCallback(MonoString *p_solution, MonoString *
GodotSharpBuilds::get_singleton()->build_exit_callback(MonoBuildInfo(solution, config), p_exit_code);
}

#ifdef UNIX_ENABLED
String _find_build_engine_on_unix(const String &p_name) {
String ret = path_which(p_name);

if (ret.length())
return ret;

const char *locations[] = {
#ifdef OSX_ENABLED
"/Library/Frameworks/Mono.framework/Versions/Current/bin/",
#endif
"/opt/novell/mono/bin/"
};

for (int i = 0; i < sizeof(locations) / sizeof(char); i++) {
String location = locations[i];

if (FileAccess::exists(location + p_name)) {
return location;
}
}

return String();
}
#endif

MonoString *godot_icall_BuildInstance_get_MSBuildPath() {

GodotSharpBuilds::BuildTool build_tool = GodotSharpBuilds::BuildTool(int(EditorSettings::get_singleton()->get("mono/builds/build_tool")));

#ifdef WINDOWS_ENABLED
#if defined(WINDOWS_ENABLED)
switch (build_tool) {
case GodotSharpBuilds::MSBUILD: {
static String msbuild_tools_path = MonoRegUtils::find_msbuild_tools_path();
Expand Down Expand Up @@ -84,14 +111,25 @@ MonoString *godot_icall_BuildInstance_get_MSBuildPath() {
ERR_EXPLAIN("You don't deserve to live");
CRASH_NOW();
}
#else
static bool msbuild_found = path_which("msbuild").length();

if (build_tool != GodotSharpBuilds::XBUILD && !msbuild_found) {
WARN_PRINT("Cannot find msbuild ('mono/builds/build_tool').");
#elif defined(UNIX_ENABLED)
static String msbuild_path = _find_build_engine_on_unix("msbuild");
static String xbuild_path = _find_build_engine_on_unix("xbuild");

if (build_tool != GodotSharpBuilds::XBUILD) {
if (msbuild_path.empty()) {
WARN_PRINT("Cannot find msbuild ('mono/builds/build_tool').");
return NULL;
}
} else {
if (xbuild_path.empty()) {
WARN_PRINT("Cannot find xbuild ('mono/builds/build_tool').");
return NULL;
}
}

return GDMonoMarshal::mono_string_from_godot(build_tool != GodotSharpBuilds::XBUILD ? "msbuild" : "xbuild");
return GDMonoMarshal::mono_string_from_godot(build_tool != GodotSharpBuilds::XBUILD ? msbuild_path : xbuild_path);
#else
return NULL;
#endif
}

Expand Down

0 comments on commit b4d758e

Please sign in to comment.