Merge pull request #11845 from neikeq/music-is-overrated

- Fixed uninitialized local
- Improved msbuild search on Unix platforms
- Add C# script to csproj when attaching it to an object
This commit is contained in:
Ignacio Etcheverry 2017-10-05 19:42:22 +02:00 committed by GitHub
commit 928efe06d6
6 changed files with 110 additions and 27 deletions

View file

@ -50,6 +50,21 @@
#define CACHED_STRING_NAME(m_var) (CSharpLanguage::get_singleton()->string_names.m_var)
static bool _create_project_solution_if_needed() {
String sln_path = GodotSharpDirs::get_project_sln_path();
String csproj_path = GodotSharpDirs::get_project_csproj_path();
if (!FileAccess::exists(sln_path) || !FileAccess::exists(csproj_path)) {
// A solution does not yet exist, create a new one
CRASH_COND(GodotSharpEditor::get_singleton() == NULL);
return GodotSharpEditor::get_singleton()->call("_create_project_solution");
}
return true;
}
CSharpLanguage *CSharpLanguage::singleton = NULL;
String CSharpLanguage::get_name() const {
@ -1359,7 +1374,18 @@ Ref<CSharpScript> CSharpScript::create_for_managed_type(GDMonoClass *p_class) {
bool CSharpScript::can_instance() const {
// TODO does the second condition even make sense?
#ifdef TOOLS_ENABLED
if (Engine::get_singleton()->is_editor_hint()) {
if (_create_project_solution_if_needed()) {
CSharpProject::add_item(GodotSharpDirs::get_project_csproj_path(),
"Compile",
ProjectSettings::get_singleton()->globalize_path(get_path()));
} else {
ERR_PRINTS("Cannot add " + get_path() + " to the C# project because it could not be created.");
}
}
#endif
return valid || (!tool && !ScriptServer::is_scripting_enabled());
}
@ -1545,6 +1571,18 @@ Error CSharpScript::reload(bool p_keep_state) {
if (project_assembly) {
script_class = project_assembly->get_object_derived_class(name);
if (!script_class) {
ERR_PRINTS("Cannot find class " + name + " for script " + get_path());
}
#ifdef DEBUG_ENABLED
else if (OS::get_singleton()->is_stdout_verbose()) {
OS::get_singleton()->print(String("Found class " + script_class->get_namespace() + "." +
script_class->get_name() + " for script " + get_path() + "\n")
.utf8());
}
#endif
valid = script_class != NULL;
if (script_class) {
@ -1791,21 +1829,12 @@ Error ResourceFormatSaverCSharpScript::save(const String &p_path, const RES &p_r
if (!FileAccess::exists(p_path)) {
// The file does not yet exists, let's assume the user just created this script
String sln_path = GodotSharpDirs::get_project_sln_path();
String csproj_path = GodotSharpDirs::get_project_csproj_path();
if (!FileAccess::exists(sln_path) || !FileAccess::exists(csproj_path)) {
// A solution does not yet exist, create a new one
CRASH_COND(GodotSharpEditor::get_singleton() == NULL);
GodotSharpEditor::get_singleton()->call("_create_project_solution");
}
// Add the file to the C# project
if (FileAccess::exists(csproj_path)) {
CSharpProject::add_item(csproj_path, "Compile", ProjectSettings::get_singleton()->globalize_path(p_path));
if (_create_project_solution_if_needed()) {
CSharpProject::add_item(GodotSharpDirs::get_project_csproj_path(),
"Compile",
ProjectSettings::get_singleton()->globalize_path(p_path));
} else {
ERR_PRINT("C# project not found!");
ERR_PRINTS("Cannot add " + p_path + " to the C# project because it could not be created.");
}
}
#endif

View file

@ -19,7 +19,15 @@ namespace GodotSharpTools.Build
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;

View file

@ -27,12 +27,15 @@ namespace GodotSharpTools.Project
return false;
}
public static void AddItemChecked(this ProjectRootElement root, string itemType, string include)
public static bool AddItemChecked(this ProjectRootElement root, string itemType, string include)
{
if (!root.HasItem(itemType, include))
{
root.AddItem(itemType, include);
return true;
}
return false;
}
public static Guid GetGuid(this ProjectRootElement root)

View file

@ -10,8 +10,8 @@ namespace GodotSharpTools.Project
{
var dir = Directory.GetParent(projectPath).FullName;
var root = ProjectRootElement.Open(projectPath);
root.AddItemChecked(itemType, include.RelativeToPath(dir).Replace("/", "\\"));
root.Save();
if (root.AddItemChecked(itemType, include.RelativeToPath(dir).Replace("/", "\\")))
root.Save();
}
}
}

View file

@ -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) {
@ -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();
@ -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();
#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 && !msbuild_found) {
WARN_PRINT("Cannot find msbuild ('mono/builds/build_tool').");
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
}

View file

@ -31,6 +31,7 @@
#include <mono/metadata/mono-config.h>
#include <mono/metadata/mono-debug.h>
#include <mono/metadata/mono-gc.h>
#include "os/dir_access.h"
#include "os/file_access.h"
@ -272,7 +273,7 @@ bool GDMono::_load_assembly(const String &p_name, GDMonoAssembly **r_assembly) {
if (OS::get_singleton()->is_stdout_verbose())
OS::get_singleton()->print((String() + "Mono: Loading assembly " + p_name + "...\n").utf8());
MonoImageOpenStatus status;
MonoImageOpenStatus status = MONO_IMAGE_OK;
MonoAssemblyName *aname = mono_assembly_name_new(p_name.utf8());
MonoAssembly *assembly = mono_assembly_load_full(aname, NULL, &status, false);
mono_assembly_name_free(aname);
@ -438,10 +439,14 @@ Error GDMono::_unload_scripts_domain() {
if (mono_domain_get() != root_domain)
mono_domain_set(root_domain, true);
mono_gc_collect(mono_gc_max_generation());
finalizing_scripts_domain = true;
mono_domain_finalize(scripts_domain, 2000);
finalizing_scripts_domain = false;
mono_gc_collect(mono_gc_max_generation());
_domain_assemblies_cleanup(mono_domain_get_id(scripts_domain));
api_assembly = NULL;