forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetCoreProgram.cs
More file actions
114 lines (97 loc) · 4.12 KB
/
NetCoreProgram.cs
File metadata and controls
114 lines (97 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using UnityEditor.Scripting.Compilers;
using UnityEditor.Utils;
using UnityEngine;
using Debug = UnityEngine.Debug;
namespace UnityEditor.Scripting
{
internal class NetCoreProgram : Program
{
public NetCoreProgram(string executable, string arguments, Action<ProcessStartInfo> setupStartInfo)
{
if (!IsNetCoreAvailable())
{
Debug.LogError("Creating NetCoreProgram, but IsNetCoreAvailable() == false; fix the caller!");
// let it happen anyway to preserve previous behaviour
}
var startInfo = CreateDotNetCoreStartInfoForArgs(CommandLineFormatter.PrepareFileName(executable) + " " + arguments);
if (setupStartInfo != null)
setupStartInfo(startInfo);
_process.StartInfo = startInfo;
}
private static ProcessStartInfo CreateDotNetCoreStartInfoForArgs(string arguments)
{
var dotnetExe = Paths.Combine(GetSdkRoot(), "dotnet");
if (Application.platform == RuntimePlatform.WindowsEditor)
dotnetExe = CommandLineFormatter.PrepareFileName(dotnetExe + ".exe");
var startInfo = new ProcessStartInfo
{
Arguments = arguments,
CreateNoWindow = true,
FileName = dotnetExe,
WorkingDirectory = Application.dataPath + "/..",
};
if (Application.platform == RuntimePlatform.OSXEditor)
{
// .NET Core needs to be able to find the newer openssl libraries that it requires on OSX
var nativeDepsPath = Path.Combine(Path.Combine(Path.Combine(GetNetCoreRoot(), "NativeDeps"), "osx"), "lib");
if (startInfo.EnvironmentVariables.ContainsKey("DYLD_LIBRARY_PATH"))
startInfo.EnvironmentVariables["DYLD_LIBRARY_PATH"] = string.Format("{0}:{1}", nativeDepsPath, startInfo.EnvironmentVariables["DYLD_LIBRARY_PATH"]);
else
startInfo.EnvironmentVariables.Add("DYLD_LIBRARY_PATH", nativeDepsPath);
}
return startInfo;
}
private static string GetSdkRoot()
{
return Path.Combine(GetNetCoreRoot(), "Sdk");
}
private static string GetNetCoreRoot()
{
return Path.Combine(MonoInstallationFinder.GetFrameWorksFolder(), "NetCore");
}
private static bool s_NetCoreAvailableChecked = false;
private static bool s_NetCoreAvailable = false;
public static bool IsNetCoreAvailable()
{
if (!s_NetCoreAvailableChecked)
{
s_NetCoreAvailableChecked = true;
var startInfo = CreateDotNetCoreStartInfoForArgs("--version");
var getVersionProg = new Program(startInfo);
try
{
getVersionProg.Start();
}
catch (Exception ex)
{
Debug.LogWarningFormat("Disabling CoreCLR, got exception trying to run with --version: {0}", ex);
return false;
}
getVersionProg.WaitForExit(5000);
if (!getVersionProg.HasExited)
{
getVersionProg.Kill();
Debug.LogWarning("Disabling CoreCLR, timed out trying to run with --version");
return false;
}
if (getVersionProg.ExitCode != 0)
{
Debug.LogWarningFormat("Disabling CoreCLR, got non-zero exit code: {0}, stderr: '{1}'",
getVersionProg.ExitCode, getVersionProg.GetErrorOutputAsString());
return false;
}
s_NetCoreAvailable = true;
}
return s_NetCoreAvailable;
}
}
}