summaryrefslogtreecommitdiff
path: root/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectUtils.cs
diff options
context:
space:
mode:
Diffstat (limited to 'modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectUtils.cs')
-rw-r--r--modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectUtils.cs119
1 files changed, 110 insertions, 9 deletions
diff --git a/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectUtils.cs b/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectUtils.cs
index 233aab45b3..af36f125f5 100644
--- a/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectUtils.cs
+++ b/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectUtils.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
+using System.Reflection;
using DotNet.Globbing;
using Microsoft.Build.Construction;
@@ -44,6 +45,7 @@ namespace GodotTools.ProjectEditor
globOptions.Evaluation.CaseInsensitive = false;
var root = ProjectRootElement.Open(projectPath);
+ Debug.Assert(root != null);
foreach (var itemGroup in root.ItemGroups)
{
@@ -85,35 +87,35 @@ namespace GodotTools.ProjectEditor
void AddPropertyIfNotPresent(string name, string condition, string value)
{
if (root.PropertyGroups
- .Any(g => (g.Condition == string.Empty || g.Condition == condition) &&
+ .Any(g => (g.Condition == string.Empty || g.Condition.Trim() == condition) &&
g.Properties
.Any(p => p.Name == name &&
p.Value == value &&
- (p.Condition == condition || g.Condition == condition))))
+ (p.Condition.Trim() == condition || g.Condition.Trim() == condition))))
{
return;
}
- root.AddProperty(name, value).Condition = condition;
+ root.AddProperty(name, value).Condition = " " + condition + " ";
dirty = true;
}
AddPropertyIfNotPresent(name: "ApiConfiguration",
- condition: " '$(Configuration)' != 'Release' ",
+ condition: "'$(Configuration)' != 'ExportRelease'",
value: "Debug");
AddPropertyIfNotPresent(name: "ApiConfiguration",
- condition: " '$(Configuration)' == 'Release' ",
+ condition: "'$(Configuration)' == 'ExportRelease'",
value: "Release");
void SetReferenceHintPath(string referenceName, string condition, string hintPath)
{
foreach (var itemGroup in root.ItemGroups.Where(g =>
- g.Condition == string.Empty || g.Condition == condition))
+ g.Condition.Trim() == string.Empty || g.Condition.Trim() == condition))
{
var references = itemGroup.Items.Where(item =>
item.ItemType == "Reference" &&
item.Include == referenceName &&
- (item.Condition == condition || itemGroup.Condition == condition));
+ (item.Condition.Trim() == condition || itemGroup.Condition.Trim() == condition));
var referencesWithHintPath = references.Where(reference =>
reference.Metadata.Any(m => m.Name == "HintPath"));
@@ -152,7 +154,7 @@ namespace GodotTools.ProjectEditor
}
// Found no Reference item at all. Add it.
- root.AddItem("Reference", referenceName).Condition = condition;
+ root.AddItem("Reference", referenceName).Condition = " " + condition + " ";
dirty = true;
}
@@ -160,7 +162,7 @@ namespace GodotTools.ProjectEditor
const string editorProjectName = "GodotSharpEditor";
const string coreCondition = "";
- const string editorCondition = " '$(Configuration)' == 'Tools' ";
+ const string editorCondition = "'$(Configuration)' == 'Debug'";
var coreHintPath = $"$(ProjectDir)/.mono/assemblies/$(ApiConfiguration)/{coreProjectName}.dll";
var editorHintPath = $"$(ProjectDir)/.mono/assemblies/$(ApiConfiguration)/{editorProjectName}.dll";
@@ -171,5 +173,104 @@ namespace GodotTools.ProjectEditor
if (dirty)
root.Save();
}
+
+ public static void MigrateFromOldConfigNames(string projectPath)
+ {
+ var root = ProjectRootElement.Open(projectPath);
+ Debug.Assert(root != null);
+
+ bool dirty = false;
+
+ bool hasGodotProjectGeneratorVersion = false;
+ bool foundOldConfiguration = false;
+
+ foreach (var propertyGroup in root.PropertyGroups.Where(g => g.Condition == string.Empty))
+ {
+ if (!hasGodotProjectGeneratorVersion && propertyGroup.Properties.Any(p => p.Name == "GodotProjectGeneratorVersion"))
+ hasGodotProjectGeneratorVersion = true;
+
+ foreach (var configItem in propertyGroup.Properties
+ .Where(p => p.Condition.Trim() == "'$(Configuration)' == ''" && p.Value == "Tools"))
+ {
+ configItem.Value = "Debug";
+ foundOldConfiguration = true;
+ dirty = true;
+ }
+ }
+
+ if (!hasGodotProjectGeneratorVersion)
+ {
+ root.PropertyGroups.First(g => g.Condition == string.Empty)?
+ .AddProperty("GodotProjectGeneratorVersion", Assembly.GetExecutingAssembly().GetName().Version.ToString());
+ dirty = true;
+ }
+
+ if (!foundOldConfiguration)
+ {
+ var toolsConditions = new[]
+ {
+ "'$(Configuration)|$(Platform)' == 'Tools|AnyCPU'",
+ "'$(Configuration)|$(Platform)' != 'Tools|AnyCPU'",
+ "'$(Configuration)' == 'Tools'",
+ "'$(Configuration)' != 'Tools'"
+ };
+
+ foundOldConfiguration = root.PropertyGroups
+ .Any(g => toolsConditions.Any(c => c == g.Condition.Trim()));
+ }
+
+ if (foundOldConfiguration)
+ {
+ void MigrateConfigurationConditions(string oldConfiguration, string newConfiguration)
+ {
+ void MigrateConditions(string oldCondition, string newCondition)
+ {
+ foreach (var propertyGroup in root.PropertyGroups.Where(g => g.Condition.Trim() == oldCondition))
+ {
+ propertyGroup.Condition = " " + newCondition + " ";
+ dirty = true;
+ }
+
+ foreach (var propertyGroup in root.PropertyGroups)
+ {
+ foreach (var prop in propertyGroup.Properties.Where(p => p.Condition.Trim() == oldCondition))
+ {
+ prop.Condition = " " + newCondition + " ";
+ dirty = true;
+ }
+ }
+
+ foreach (var itemGroup in root.ItemGroups.Where(g => g.Condition.Trim() == oldCondition))
+ {
+ itemGroup.Condition = " " + newCondition + " ";
+ dirty = true;
+ }
+
+ foreach (var itemGroup in root.ItemGroups)
+ {
+ foreach (var item in itemGroup.Items.Where(item => item.Condition.Trim() == oldCondition))
+ {
+ item.Condition = " " + newCondition + " ";
+ dirty = true;
+ }
+ }
+ }
+
+ foreach (var op in new[] {"==", "!="})
+ {
+ MigrateConditions($"'$(Configuration)|$(Platform)' {op} '{oldConfiguration}|AnyCPU'", $"'$(Configuration)|$(Platform)' {op} '{newConfiguration}|AnyCPU'");
+ MigrateConditions($"'$(Configuration)' {op} '{oldConfiguration}'", $"'$(Configuration)' {op} '{newConfiguration}'");
+ }
+ }
+
+ MigrateConfigurationConditions("Debug", "ExportDebug");
+ MigrateConfigurationConditions("Release", "ExportRelease");
+ MigrateConfigurationConditions("Tools", "Debug"); // Must be last
+ }
+
+
+ if (dirty)
+ root.Save();
+ }
}
}