diff options
Diffstat (limited to 'modules/mono/editor/GodotSharpTools/Build/BuildSystem.cs')
-rw-r--r-- | modules/mono/editor/GodotSharpTools/Build/BuildSystem.cs | 73 |
1 files changed, 54 insertions, 19 deletions
diff --git a/modules/mono/editor/GodotSharpTools/Build/BuildSystem.cs b/modules/mono/editor/GodotSharpTools/Build/BuildSystem.cs index 5544233eb7..bdbef82aad 100644 --- a/modules/mono/editor/GodotSharpTools/Build/BuildSystem.cs +++ b/modules/mono/editor/GodotSharpTools/Build/BuildSystem.cs @@ -4,6 +4,7 @@ using System.Collections.Specialized; using System.Diagnostics; using System.IO; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Security; using Microsoft.Build.Framework; @@ -12,24 +13,38 @@ namespace GodotSharpTools.Build public class BuildInstance : IDisposable { [MethodImpl(MethodImplOptions.InternalCall)] - internal extern static void godot_icall_BuildInstance_ExitCallback(string solution, string config, int exitCode); + private extern static void godot_icall_BuildInstance_ExitCallback(string solution, string config, int exitCode); [MethodImpl(MethodImplOptions.InternalCall)] - internal extern static string godot_icall_BuildInstance_get_MSBuildPath(); + private extern static MSBuildInfo godot_icall_BuildInstance_get_MSBuildInfo(); - private static string MSBuildPath + [StructLayout(LayoutKind.Sequential)] + private struct MSBuildInfo { - get - { - string ret = godot_icall_BuildInstance_get_MSBuildPath(); + string path; + string frameworkPathOverride; - if (ret == null) - throw new FileNotFoundException("Cannot find the MSBuild executable."); + public string MSBuildPath + { + get { return path; } + } - return ret; + public string FrameworkPathOverride + { + get { return frameworkPathOverride; } } } + private static MSBuildInfo GetMSBuildInfo() + { + MSBuildInfo ret = godot_icall_BuildInstance_get_MSBuildInfo(); + + if (ret.MSBuildPath == null) + throw new FileNotFoundException("Cannot find the MSBuild executable."); + + return ret; + } + private string solution; private string config; @@ -48,9 +63,19 @@ namespace GodotSharpTools.Build public bool Build(string loggerAssemblyPath, string loggerOutputDir, string[] customProperties = null) { - string compilerArgs = BuildArguments(loggerAssemblyPath, loggerOutputDir, customProperties); + MSBuildInfo msbuildInfo = GetMSBuildInfo(); + + List<string> customPropertiesList = new List<string>(); + + if (customProperties != null) + customPropertiesList.AddRange(customProperties); - ProcessStartInfo startInfo = new ProcessStartInfo(MSBuildPath, compilerArgs); + if (msbuildInfo.FrameworkPathOverride.Length > 0) + customPropertiesList.Add("FrameworkPathOverride=" + msbuildInfo.FrameworkPathOverride); + + string compilerArgs = BuildArguments(loggerAssemblyPath, loggerOutputDir, customPropertiesList); + + ProcessStartInfo startInfo = new ProcessStartInfo(msbuildInfo.MSBuildPath, compilerArgs); // No console output, thanks startInfo.RedirectStandardOutput = true; @@ -82,9 +107,19 @@ namespace GodotSharpTools.Build if (process != null) throw new InvalidOperationException("Already in use"); - string compilerArgs = BuildArguments(loggerAssemblyPath, loggerOutputDir, customProperties); + MSBuildInfo msbuildInfo = GetMSBuildInfo(); + + List<string> customPropertiesList = new List<string>(); + + if (customProperties != null) + customPropertiesList.AddRange(customProperties); + + if (msbuildInfo.FrameworkPathOverride.Length > 0) + customPropertiesList.Add("FrameworkPathOverride=" + msbuildInfo.FrameworkPathOverride); - ProcessStartInfo startInfo = new ProcessStartInfo("msbuild", compilerArgs); + string compilerArgs = BuildArguments(loggerAssemblyPath, loggerOutputDir, customPropertiesList); + + ProcessStartInfo startInfo = new ProcessStartInfo(msbuildInfo.MSBuildPath, compilerArgs); // No console output, thanks startInfo.RedirectStandardOutput = true; @@ -101,10 +136,13 @@ namespace GodotSharpTools.Build process.Start(); + process.BeginOutputReadLine(); + process.BeginErrorReadLine(); + return true; } - private string BuildArguments(string loggerAssemblyPath, string loggerOutputDir, string[] customProperties) + private string BuildArguments(string loggerAssemblyPath, string loggerOutputDir, List<string> customProperties) { string arguments = string.Format(@"""{0}"" /v:normal /t:Build ""/p:{1}"" ""/l:{2},{3};{4}""", solution, @@ -114,12 +152,9 @@ namespace GodotSharpTools.Build loggerOutputDir ); - if (customProperties != null) + foreach (string customProperty in customProperties) { - foreach (string customProperty in customProperties) - { - arguments += " /p:" + customProperty; - } + arguments += " \"/p:" + customProperty + "\""; } return arguments; |