mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-11-04 12:51:48 +00:00
Only write to solution and project files when they changed
This commit is contained in:
@@ -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]
|
||||||
|
|||||||
@@ -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,31 +317,48 @@ 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);
|
|
||||||
defer delete modifiedSolution;
|
|
||||||
solution.SaveToString(modifiedSolution);
|
|
||||||
|
|
||||||
if (File.WriteAllText(solutionPath, modifiedSolution) case .Err)
|
if (changedContent)
|
||||||
{
|
{
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If necessary adds or removes the reference to ScriptCore.dll from the project (.csproj) file.
|
/// If necessary adds or removes the reference to ScriptCore.dll from the project (.csproj) file.
|
||||||
private Result<void> FixupScriptProjectFile(bool referenceScriptCoreProject)
|
private Result<void> FixupScriptProjectFile(bool referenceScriptCoreProject)
|
||||||
{
|
{
|
||||||
@@ -372,8 +392,19 @@ 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)
|
||||||
{
|
{
|
||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user