Only write to solution and project files when they changed

This commit is contained in:
Simon Lübeß
2026-08-17 22:14:31 +02:00
parent 8c53dcb9ca
commit 1cc604cd51
2 changed files with 85 additions and 32 deletions
+1 -1
View File
@@ -21,7 +21,7 @@ IconFile = "$(ProjectDir)/Resources/Textures/GlitchyEngineIcon.ico"
[Configs.Debug.Win64] [Configs.Debug.Win64]
PostBuildCmds = ["CopyFilesIfNewer(\"$(WorkspaceDir)/bin/vswhere.exe\", \"$(TargetDir)\")"] PostBuildCmds = ["CopyFilesIfNewer(\"$(WorkspaceDir)/bin/vswhere.exe\", \"$(TargetDir)\")"]
DebugCommandArguments = "\"D:\\Development\\Git\\SingleStateToOrbit\"" DebugCommandArguments = "\"$(ProjectDir)/../GlitchyEngine.Test/content/TestProject\""
PreprocessorMacros = ["DEBUG", "IMGUI"] PreprocessorMacros = ["DEBUG", "IMGUI"]
[Configs.Release.Win64] [Configs.Release.Win64]
+81 -28
View File
@@ -36,7 +36,8 @@ class Project
[AllowAppend] [AllowAppend]
private this(StringView workspacePath) private this(StringView workspacePath)
{ {
_workspacePath = new String(workspacePath); _workspacePath = new String(workspacePath.Length);
Path.GetFullPath(workspacePath, _workspacePath);
_assetsFolder = new String(); _assetsFolder = new String();
PathInProject(_assetsFolder, "Assets"); PathInProject(_assetsFolder, "Assets");
@@ -306,6 +307,8 @@ class Project
} }
} }
bool changedContent = false;
if (referenceScriptCoreProject) if (referenceScriptCoreProject)
{ {
Log.EngineLogger.Info("Debug mode enabled. Referencing ScriptCore.csproj in Script-Solution."); Log.EngineLogger.Info("Debug mode enabled. Referencing ScriptCore.csproj in Script-Solution.");
@@ -314,26 +317,43 @@ class Project
{ {
Log.EngineLogger.Warning("No reference to ScriptCore.csproj found. Adding..."); Log.EngineLogger.Warning("No reference to ScriptCore.csproj found. Adding...");
scriptCoreProjectReference = solution.DocumentElement.AddChild("Project"); scriptCoreProjectReference = solution.DocumentElement.AddChild("Project");
changedContent = true;
} }
String projectFilePath = scope .(); String projectFilePath = scope .();
GetScriptCoreProjectFilePath(projectFilePath); GetScriptCoreProjectFilePath(projectFilePath);
scriptCoreProjectReference["Path"] = projectFilePath;
if (!Path.Equals(scriptCoreProjectReference["Path"], projectFilePath))
{
scriptCoreProjectReference["Path"] = projectFilePath;
changedContent = true;
}
} }
else if (scriptCoreProjectReference != null) else if (scriptCoreProjectReference != null)
{ {
Log.EngineLogger.Warning("Reference to ScriptCore.csproj found. Removing..."); Log.EngineLogger.Warning("Reference to ScriptCore.csproj found. Removing...");
scriptCoreProjectReference.RemoveFromParent(true); scriptCoreProjectReference.RemoveFromParent(true);
changedContent = true;
} }
String modifiedSolution = new String(solutionFileContent.Length * 2); if (changedContent)
defer delete modifiedSolution;
solution.SaveToString(modifiedSolution);
if (File.WriteAllText(solutionPath, modifiedSolution) case .Err)
{ {
Log.EngineLogger.Error($"Failed to modify {solutionPath}"); Log.EngineLogger.Info("Script solution file updated, saving...");
return .Err;
String modifiedSolution = new String(solutionFileContent.Length * 2);
defer delete modifiedSolution;
solution.SaveToString(modifiedSolution);
if (File.WriteAllText(solutionPath, modifiedSolution) case .Err)
{
Log.EngineLogger.Error($"Failed to modify {solutionPath}");
return .Err;
}
}
else
{
Log.EngineLogger.Info("Script solution file already up to date.");
} }
return .Ok; return .Ok;
@@ -372,9 +392,20 @@ class Project
} }
} }
bool changedContent = false;
// Try to find a reference to the dll // Try to find a reference to the dll
XmlNode dllReferenceNode = project.DocumentElement.Find("Reference", "Include", "ScriptCore", recursive: true); XmlNode dllReferenceNode = project.DocumentElement.Find("Reference", "Include", "ScriptCore", recursive: true);
mixin SetIfDifferent(XmlNode node, StringView attributeName, StringView wantedValue)
{
if (node.GetAttribute(attributeName)?.Value != wantedValue)
{
node.SetAttribute(attributeName, wantedValue);
changedContent = true;
}
}
if (referenceScriptCoreProject) if (referenceScriptCoreProject)
{ {
Log.EngineLogger.Info("Debug mode enabled. Referencing ScriptCore.csproj in Script-Project."); Log.EngineLogger.Info("Debug mode enabled. Referencing ScriptCore.csproj in Script-Project.");
@@ -383,6 +414,7 @@ class Project
{ {
Log.EngineLogger.Warning("Reference to ScriptCore.dll found. Removing..."); Log.EngineLogger.Warning("Reference to ScriptCore.dll found. Removing...");
dllReferenceNode.RemoveFromParent(true); dllReferenceNode.RemoveFromParent(true);
changedContent = true;
} }
if (scriptCoreProjectReference == null) if (scriptCoreProjectReference == null)
@@ -392,16 +424,21 @@ class Project
XmlNode itemGroup = project.DocumentElement.Find("ItemGroup", recursive: true); XmlNode itemGroup = project.DocumentElement.Find("ItemGroup", recursive: true);
scriptCoreProjectReference = itemGroup.AddChild("ProjectReference"); scriptCoreProjectReference = itemGroup.AddChild("ProjectReference");
changedContent = true;
String scriptCoreProjectPath = scope .();
Directory.GetCurrentDirectory(scriptCoreProjectPath);
Path.Combine(scriptCoreProjectPath, "../ScriptCore/ScriptCore.csproj");
Path.ToActualPath(scriptCoreProjectPath);
scriptCoreProjectReference.SetAttribute("Include", scriptCoreProjectPath);
scriptCoreProjectReference.SetAttribute("OutputItemType", "Analyzer");
scriptCoreProjectReference.SetAttribute("ReferenceOutputAssembly", "true");
} }
String scriptCoreProjectPath = scope .();
Directory.GetCurrentDirectory(scriptCoreProjectPath);
Path.Combine(scriptCoreProjectPath, "../ScriptCore/ScriptCore.csproj");
Path.ToActualPath(scriptCoreProjectPath);
if (!Path.Equals(scriptCoreProjectReference.GetAttribute("Include")?.Value, scriptCoreProjectPath))
{
scriptCoreProjectReference.SetAttribute("Include", scriptCoreProjectPath);
changedContent = true;
}
SetIfDifferent!(scriptCoreProjectReference, "OutputItemType", "Analyzer");
SetIfDifferent!(scriptCoreProjectReference, "ReferenceOutputAssembly", "true");
} }
else else
{ {
@@ -409,6 +446,7 @@ class Project
{ {
Log.EngineLogger.Warning("Reference to ScriptCore.csproj found. Removing..."); Log.EngineLogger.Warning("Reference to ScriptCore.csproj found. Removing...");
scriptCoreProjectReference.RemoveFromParent(true); scriptCoreProjectReference.RemoveFromParent(true);
changedContent = true;
} }
if (dllReferenceNode == null) if (dllReferenceNode == null)
@@ -418,16 +456,18 @@ class Project
XmlNode itemGroup = project.DocumentElement.Find("ItemGroup", recursive: true); XmlNode itemGroup = project.DocumentElement.Find("ItemGroup", recursive: true);
dllReferenceNode = itemGroup.AddChild("Reference"); dllReferenceNode = itemGroup.AddChild("Reference");
changedContent = true;
} }
dllReferenceNode.SetAttribute("Include", "ScriptCore"); SetIfDifferent!(dllReferenceNode, "Include", "ScriptCore");
dllReferenceNode.SetAttribute("OutputItemType", "Analyzer"); SetIfDifferent!(dllReferenceNode, "OutputItemType", "Analyzer");
dllReferenceNode.SetAttribute("ReferenceOutputAssembly", "true"); SetIfDifferent!(dllReferenceNode, "ReferenceOutputAssembly", "true");
XmlNode hintPathNode = dllReferenceNode.Find("HintPath"); XmlNode hintPathNode = dllReferenceNode.Find("HintPath");
if (hintPathNode == null) if (hintPathNode == null)
{ {
hintPathNode = dllReferenceNode.AddChild("HintPath"); hintPathNode = dllReferenceNode.AddChild("HintPath");
changedContent = true;
} }
String pathToScriptCoreDll = scope .(); String pathToScriptCoreDll = scope .();
@@ -441,16 +481,29 @@ class Project
return .Err; return .Err;
} }
hintPathNode.SetText(pathToScriptCoreDll); if (!Path.Equals(hintPathNode.Text, pathToScriptCoreDll))
{
hintPathNode.SetText(pathToScriptCoreDll);
changedContent = true;
}
} }
String modfiedProject = new String(projectFileContent.Length * 2); if (changedContent)
defer delete modfiedProject;
project.SaveToString(modfiedProject);
if (File.WriteAllText(csprojPath, modfiedProject) case .Err)
{ {
Log.EngineLogger.Error($"Failed to modify {csprojPath}"); Log.EngineLogger.Info("Script project file updated, saving...");
String modfiedProject = new String(projectFileContent.Length * 2);
defer delete modfiedProject;
project.SaveToString(modfiedProject);
if (File.WriteAllText(csprojPath, modfiedProject) case .Err)
{
Log.EngineLogger.Error($"Failed to modify {csprojPath}");
}
}
else
{
Log.EngineLogger.Info("Script project file already up to date.");
} }
return .Ok; return .Ok;