1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-11 13:10:58 +00:00

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.
This commit is contained in:
Ignacio Etcheverry
2017-10-24 22:47:27 +02:00
parent 4396712137
commit 9f469887fc
6 changed files with 341 additions and 115 deletions

View File

@@ -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,22 +13,36 @@ 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 path;
string frameworkPathOverride;
public string MSBuildPath
{
string ret = godot_icall_BuildInstance_get_MSBuildPath();
if (ret == null)
throw new FileNotFoundException("Cannot find the MSBuild executable.");
return ret;
get { return path; }
}
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;
@@ -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();
ProcessStartInfo startInfo = new ProcessStartInfo(MSBuildPath, compilerArgs);
List<string> customPropertiesList = new List<string>();
if (customProperties != null)
customPropertiesList.AddRange(customProperties);
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();
ProcessStartInfo startInfo = new ProcessStartInfo("msbuild", compilerArgs);
List<string> customPropertiesList = new List<string>();
if (customProperties != null)
customPropertiesList.AddRange(customProperties);
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;
@@ -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;