Skip to content

Commit

Permalink
Merge pull request #34514 from neikeq/remove-dep-on-mono-posix
Browse files Browse the repository at this point in the history
Mono/C#: Remove GodotTools dependency on the Mono.Posix assembly
  • Loading branch information
akien-mga authored Dec 21, 2019
2 parents 78f1513 + 5a3ccf4 commit a10449b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
4 changes: 0 additions & 4 deletions modules/mono/editor/GodotTools/GodotTools/GodotTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
<HintPath>..\packages\JetBrains.Annotations.2019.1.3\lib\net20\JetBrains.Annotations.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Mono.Posix" />
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
Expand Down Expand Up @@ -100,8 +99,5 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="Ides\Rider\.editorconfig" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
6 changes: 4 additions & 2 deletions modules/mono/editor/GodotTools/GodotTools/Utils/OS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using Mono.Unix.Native;

namespace GodotTools.Utils
{
Expand All @@ -15,6 +14,9 @@ public static class OS
[MethodImpl(MethodImplOptions.InternalCall)]
static extern string GetPlatformName();

[MethodImpl(MethodImplOptions.InternalCall)]
static extern bool UnixFileHasExecutableAccess(string filePath);

public static class Names
{
public const string Windows = "Windows";
Expand Down Expand Up @@ -131,7 +133,7 @@ private static string PathWhichUnix(string name)
searchDirs.Add(System.IO.Directory.GetCurrentDirectory()); // last in the list

return searchDirs.Select(dir => Path.Combine(dir, name))
.FirstOrDefault(path => File.Exists(path) && Syscall.access(path, AccessModes.X_OK) == 0);
.FirstOrDefault(path => File.Exists(path) && UnixFileHasExecutableAccess(path));
}

public static void RunProcess(string command, IEnumerable<string> arguments)
Expand Down
14 changes: 14 additions & 0 deletions modules/mono/editor/editor_internal_calls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@

#include "editor_internal_calls.h"

#ifdef UNIX_ENABLED
#include <unistd.h> // access
#endif

#include "core/os/os.h"
#include "core/version.h"
#include "editor/editor_node.h"
Expand Down Expand Up @@ -370,6 +374,15 @@ MonoString *godot_icall_Utils_OS_GetPlatformName() {
return GDMonoMarshal::mono_string_from_godot(os_name);
}

MonoBoolean godot_icall_Utils_OS_UnixFileHasExecutableAccess(MonoString *p_file_path) {
#ifdef UNIX_ENABLED
String file_path = GDMonoMarshal::mono_string_to_godot(p_file_path);
return access(file_path.utf8().get_data(), X_OK) == 0;
#else
ERR_FAIL_V(false);
#endif
}

void register_editor_internal_calls() {

// GodotSharpDirs
Expand Down Expand Up @@ -442,4 +455,5 @@ void register_editor_internal_calls() {

// Utils.OS
mono_add_internal_call("GodotTools.Utils.OS::GetPlatformName", (void *)godot_icall_Utils_OS_GetPlatformName);
mono_add_internal_call("GodotTools.Utils.OS::UnixFileHasExecutableAccess", (void *)godot_icall_Utils_OS_UnixFileHasExecutableAccess);
}

0 comments on commit a10449b

Please sign in to comment.