diff options
author | Ignacio Etcheverry <ignalfonsore@gmail.com> | 2017-10-24 22:47:27 +0200 |
---|---|---|
committer | Ignacio Etcheverry <ignalfonsore@gmail.com> | 2017-10-29 04:26:13 +0100 |
commit | 9f469887fc72c98f4a5fac736860546cf54f87ee (patch) | |
tree | cffdb3fda1ede95c5457065f98a291b0245bb40d /modules/mono/editor/GodotSharpTools/Build/BuildSystem.cs | |
parent | 43967121378c796f3780c64af4f2da07cf85c54c (diff) | |
download | redot-engine-9f469887fc72c98f4a5fac736860546cf54f87ee.tar.gz |
Buildsystem improvements for the Mono module
- Make sure to search the mono installation directory for the right architecture in the windows registry.
- Do not build GodotSharpTools directly to #bin dir. Instead build to the default output path and copy it. This way we avoid MSBuild adding files we don't want to #bin.
- Add hint path for MSBuild in OSX.
- Copy shared library on Unix if not statically linking.
- Use vswhere to search MSBuild and search for 14.0 tools version in the registry instead of 4.0.
- SCons will only fallback xbuild when msbuild is not found if 'xbuild_fallback=yes' is passed to the command.
- Use mono's assembly path as FrameworkPathOverride if using with system's MSBuild (not mono's fork).
- Cleanup.
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; |