This commit is contained in:
Raul Santos 2021-11-09 15:42:28 +01:00 committed by GitHub
commit 86e4992ba8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 4 deletions

View file

@ -84,7 +84,7 @@
<GodotPlatformConstants Condition=" '$(GodotTargetPlatform)' == 'iphone' ">GODOT_IPHONE;GODOT_IOS;GODOT_MOBILE</GodotPlatformConstants>
<GodotPlatformConstants Condition=" '$(GodotTargetPlatform)' == 'javascript' ">GODOT_JAVASCRIPT;GODOT_HTML5;GODOT_WASM;GODOT_WEB</GodotPlatformConstants>
<GodotDefineConstants>$(GodotDefineConstants);$(GodotPlatformConstants)</GodotDefineConstants>
<GodotDefineConstants>$(GodotDefineConstants);$(GodotPlatformConstants);$(GodotFeatures)</GodotDefineConstants>
</PropertyGroup>
<PropertyGroup>

View file

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using GodotTools.Ides.Rider;
@ -159,9 +160,9 @@ namespace GodotTools.Build
}
}
public static bool BuildProjectBlocking(string config, [CanBeNull] string[] targets = null, [CanBeNull] string platform = null)
public static bool BuildProjectBlocking(string config, [CanBeNull] string[] targets = null, [CanBeNull] string platform = null, [CanBeNull] string[] features = null)
{
var buildInfo = new BuildInfo(GodotSharpDirs.ProjectSlnPath, targets ?? new[] {"Build"}, config, restore: true);
var buildInfo = new BuildInfo(GodotSharpDirs.ProjectSlnPath, targets ?? new[] { "Build" }, config, restore: true);
// If a platform was not specified, try determining the current one. If that fails, let MSBuild auto-detect it.
if (platform != null || OS.PlatformNameMap.TryGetValue(Godot.OS.GetName(), out platform))
@ -170,9 +171,32 @@ namespace GodotTools.Build
if (Internal.GodotIsRealTDouble())
buildInfo.CustomProperties.Add("GodotRealTIsDouble=true");
if (features != null && features.Length > 0)
buildInfo.CustomProperties.Add($"GodotFeatures={string.Join("%3B", SanitizeFeatures(features))}");
return BuildProjectBlocking(buildInfo);
}
private static List<string> SanitizeFeatures(string[] features)
{
var sanitizedFeatures = new List<string>();
foreach (string feature in features)
{
if (string.IsNullOrWhiteSpace(feature))
continue;
string sanitizedFeature = feature.ToUpperInvariant()
.Replace("-", "_")
.Replace(" ", "_")
.Replace(";", "_");
sanitizedFeatures.Add($"GODOT_FEATURE_{sanitizedFeature}");
}
return sanitizedFeatures;
}
private static bool BuildProjectBlocking(BuildInfo buildInfo)
{
if (!File.Exists(buildInfo.Solution))

View file

@ -157,7 +157,7 @@ namespace GodotTools.Export
string buildConfig = isDebug ? "ExportDebug" : "ExportRelease";
if (!BuildManager.BuildProjectBlocking(buildConfig, platform: platform))
if (!BuildManager.BuildProjectBlocking(buildConfig, platform: platform, features: features))
throw new Exception("Failed to build project");
// Add dependency assemblies