Skip to content

Commit

Permalink
Merge branch 'dev' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
Noggog committed Sep 23, 2024
2 parents c1a8367 + 344aac1 commit be0f7d6
Show file tree
Hide file tree
Showing 15 changed files with 169 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<Version>2.65.1-nightly-20240911-092507</Version>
</PackageVersion>
<PackageVersion Include="Noggog.GitRepository">
<Version>1.2</Version>
<Version>1.3</Version>
</PackageVersion>
<PackageVersion Include="Noggog.SourceGenerators">
<Version>2.65.1-nightly-20240911-092507</Version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ void AddResult(string s)
&& meta != null
&& buildMetaPath != null)
{
meta.DoesNotHaveRunnability = true;
meta = meta with
{
DoesNotHaveRunnability = true
};
_writeShortCircuitMeta.WriteMeta(buildMetaPath, meta);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ public async Task<SettingsConfiguration> Get(
if (meta != null
&& buildMetaPath != null)
{
meta.SettingsConfiguration = settingsConfig;
meta = meta with
{
SettingsConfiguration = settingsConfig
};
_writeShortCircuitMeta.WriteMeta(buildMetaPath.Value, meta);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Xml.Linq;
using Noggog;
using NuGet.Versioning;
using Serilog;
using Synthesis.Bethesda.Execution.Patchers.Solution;
using Synthesis.Bethesda.Execution.Versioning;

Expand All @@ -21,6 +22,7 @@ public class ModifyRunnerProjects : IModifyRunnerProjects
public static readonly System.Version NewtonSoftRemoveMutaVersion = new(0, 28);
public static readonly System.Version NewtonSoftRemoveSynthVersion = new(0, 17, 5);
public static readonly System.Version NamespaceMutaVersion = new(0, 30, 0);
private readonly ILogger _logger;
private readonly IFileSystem _fileSystem;
private readonly IAvailableProjectsRetriever _availableProjectsRetriever;
private readonly ISwapToProperNetVersion _swapToProperNetVersion;
Expand All @@ -35,6 +37,7 @@ public class ModifyRunnerProjects : IModifyRunnerProjects
private readonly AddAllReleasesToOldVersions _addAllReleasesToOldVersions;

public ModifyRunnerProjects(
ILogger logger,
IFileSystem fileSystem,
IAvailableProjectsRetriever availableProjectsRetriever,
ISwapToProperNetVersion swapToProperNetVersion,
Expand All @@ -48,6 +51,7 @@ public ModifyRunnerProjects(
IRemoveProject removeProject,
AddAllReleasesToOldVersions addAllReleasesToOldVersions)
{
_logger = logger;
_fileSystem = fileSystem;
_availableProjectsRetriever = availableProjectsRetriever;
_swapToProperNetVersion = swapToProperNetVersion;
Expand Down Expand Up @@ -83,6 +87,7 @@ public void Modify(
foreach (var subProj in _availableProjectsRetriever.Get(solutionPath))
{
var proj = Path.Combine(Path.GetDirectoryName(solutionPath)!, subProj);
_logger.Information("Modifying {ProjPath}", proj);
var txt = _fileSystem.File.ReadAllText(proj);
var projXml = XElement.Parse(txt);
_swapDesiredVersions.Swap(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Xml.Linq;
using NuGet.Versioning;
using Serilog;
using Synthesis.Bethesda.Execution.Versioning;

namespace Synthesis.Bethesda.Execution.Patchers.Git.ModifyProject;
Expand All @@ -11,12 +12,19 @@ public interface ISwapToProperNetVersion

public class SwapToProperNetVersion : ISwapToProperNetVersion
{
private readonly ILogger _logger;
private const int NetNum = 8;
private readonly Version Net8Version = new Version(0, 45);

public SwapToProperNetVersion(ILogger logger)
{
_logger = logger;
}

private void ProcessTargetFrameworkNode(XElement elem, Version targetMutagenVersion)
{
if (!elem.Name.LocalName.Equals("TargetFramework")) return;
_logger.Information("Target mutagen version: {Target}", targetMutagenVersion);
if (targetMutagenVersion < Net8Version)
{
ProcessLegacy(elem);
Expand All @@ -27,16 +35,18 @@ private void ProcessTargetFrameworkNode(XElement elem, Version targetMutagenVers
}
}

private static void ProcessLegacy(XElement elem)
private void ProcessLegacy(XElement elem)
{
_logger.Information("Processing as legacy mutagen version");
if (elem.Value.Equals("netcoreapp3.1", StringComparison.Ordinal)
|| elem.Value.StartsWith("net5", StringComparison.Ordinal))
{
_logger.Information("Swapping to net6.0");
elem.Value = "net6.0";
}
}

private static void ProcessNet8(XElement elem, Version targetMutagenVersion)
private void ProcessNet8(XElement elem, Version targetMutagenVersion)
{
if (!elem.Value.StartsWith("net"))
{
Expand All @@ -49,6 +59,7 @@ private static void ProcessNet8(XElement elem, Version targetMutagenVersion)
return;
}

_logger.Information("Swapping to net8.0");
elem.Value = $"net{NetNum}.0";
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.IO.Abstractions;
using Noggog;
using Serilog;
using Synthesis.Bethesda.Execution.DotNet.Dto;
using Synthesis.Bethesda.Execution.Patchers.Git;

namespace Synthesis.Bethesda.Execution.Patchers.Running.Git;

public class BuildDirectoryCleaner
{
private readonly IFileSystem _fileSystem;
private readonly ILogger _logger;

public BuildDirectoryCleaner(
IFileSystem fileSystem,
ILogger logger)
{
_fileSystem = fileSystem;
_logger = logger;
}

public void Clean(
RunnerRepoInfo info,
DotNetVersion dotNetVersion,
GitCompilationMeta? meta)
{
if (dotNetVersion.Version == meta?.NetSdkVersion) return;
var buildFolder = Path.Combine(info.Project.ProjPath.Directory!, "bin");
var objFolder = Path.Combine(info.Project.ProjPath.Directory!, "obj");
_logger.Information("Deleting build folder", buildFolder);
_fileSystem.Directory.DeleteEntireFolder(buildFolder);
_logger.Information("Deleting obj folder", objFolder);
_fileSystem.Directory.DeleteEntireFolder(objFolder);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
namespace Synthesis.Bethesda.Execution.Patchers.Running.Git;

public class GitCompilationMeta
public record GitCompilationMeta
{
public string MutagenVersion { get; set; } = string.Empty;
public string SynthesisVersion { get; set; } = string.Empty;
public string Sha { get; set; } = string.Empty;
public bool DoesNotHaveRunnability { get; set; }
public SettingsConfiguration? SettingsConfiguration { get; set; }
public required string SynthesisUiVersion { get; init; }
public required string NetSdkVersion { get; init; }
public required string MutagenVersion { get; init; }
public required string SynthesisVersion { get; init; }
public required string Sha { get; init; }
public bool DoesNotHaveRunnability { get; init; }
public SettingsConfiguration? SettingsConfiguration { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
using Noggog;
using Serilog;
using Synthesis.Bethesda.Execution.DotNet.Builder;
using Synthesis.Bethesda.Execution.DotNet.Dto;
using Synthesis.Bethesda.Execution.Patchers.Git;

namespace Synthesis.Bethesda.Execution.Patchers.Running.Git;

public interface IGitPatcherCompilation
{
Task<ErrorResponse> Compile(RunnerRepoInfo info, CancellationToken cancel);
Task<ErrorResponse> Compile(
RunnerRepoInfo info,
DotNetVersion dotNetVersion,
CancellationToken cancel);
}

public class GitPatcherCompilation : IGitPatcherCompilation
Expand All @@ -17,31 +21,43 @@ public class GitPatcherCompilation : IGitPatcherCompilation
private readonly IFileSystem _fs;
private readonly IBuild _build;
private readonly IWriteShortCircuitMeta _writeShortCircuitMeta;
private readonly IShouldShortCircuitCompilation _shortCircuitCompilation;
private readonly ShouldShortCircuitCompilation _shortCircuitCompilation;
private readonly BuildDirectoryCleaner _buildDirectoryCleaner;
private readonly IBuildMetaFileReader _metaFileReader;

public GitPatcherCompilation(
ILogger logger,
IFileSystem fs,
IBuild build,
IWriteShortCircuitMeta writeShortCircuitMeta,
IShouldShortCircuitCompilation shortCircuitCompilation)
ShouldShortCircuitCompilation shortCircuitCompilation,
BuildDirectoryCleaner buildDirectoryCleaner,
IBuildMetaFileReader metaFileReader)
{
_logger = logger;
_fs = fs;
_build = build;
_writeShortCircuitMeta = writeShortCircuitMeta;
_shortCircuitCompilation = shortCircuitCompilation;
_buildDirectoryCleaner = buildDirectoryCleaner;
_metaFileReader = metaFileReader;
}

public async Task<ErrorResponse> Compile(RunnerRepoInfo info, CancellationToken cancel)
public async Task<ErrorResponse> Compile(
RunnerRepoInfo info,
DotNetVersion dotNetVersion,
CancellationToken cancel)
{
try
{
if (_shortCircuitCompilation.ShouldShortCircuit(info))
var meta = _metaFileReader.Read(info.MetaPath);
if (_shortCircuitCompilation.ShouldShortCircuit(info, meta))
{
_logger.Information("Short circuiting {Path} compilation because meta matched", info.Project.ProjPath);
return ErrorResponse.Success;
}

_buildDirectoryCleaner.Clean(info, dotNetVersion, meta);
}
catch (Exception e)
{
Expand All @@ -58,13 +74,13 @@ public async Task<ErrorResponse> Compile(RunnerRepoInfo info, CancellationToken
{
_logger.Error(e, "Failed when clearing short circuit meta");
}

var resp = await _build.Compile(info.Project.ProjPath, cancel).ConfigureAwait(false);
if (resp.Failed) return resp;

try
{
_writeShortCircuitMeta.WriteMeta(info);
_writeShortCircuitMeta.WriteMeta(info, dotNetVersion);
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
using Synthesis.Bethesda.Execution.Patchers.Git;
using Mutagen.Bethesda.Synthesis.Versioning;
using Synthesis.Bethesda.Execution.Patchers.Git;

namespace Synthesis.Bethesda.Execution.Patchers.Running.Git;

public interface IShouldShortCircuitCompilation
{
bool ShouldShortCircuit(RunnerRepoInfo info);
}

public class ShouldShortCircuitCompilation : IShouldShortCircuitCompilation
public class ShouldShortCircuitCompilation
{
private readonly IShortCircuitSettingsProvider _settingsProvider;
private readonly IBuildMetaFileReader _metaFileReader;
private readonly IProvideCurrentVersions _provideCurrentVersions;

public ShouldShortCircuitCompilation(
IShortCircuitSettingsProvider settingsProvider,
IBuildMetaFileReader metaFileReader)
IBuildMetaFileReader metaFileReader,
IProvideCurrentVersions provideCurrentVersions)
{
_settingsProvider = settingsProvider;
_metaFileReader = metaFileReader;
_provideCurrentVersions = provideCurrentVersions;
}

public bool ShouldShortCircuit(RunnerRepoInfo info)
public bool ShouldShortCircuit(RunnerRepoInfo info, GitCompilationMeta? meta)
{
if (!_settingsProvider.Shortcircuit) return false;
var meta = _metaFileReader.Read(info.MetaPath);
if (meta == null) return false;
if (meta.Sha != info.Target.TargetSha) return false;
if (meta.MutagenVersion != info.TargetVersions.Mutagen) return false;
if (meta.SynthesisVersion != info.TargetVersions.Synthesis) return false;
if (meta.SynthesisUiVersion != _provideCurrentVersions.SynthesisVersion) return false;
return true;
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
using System.IO.Abstractions;
using Mutagen.Bethesda.Synthesis.Versioning;
using Newtonsoft.Json;
using Synthesis.Bethesda.Execution.DotNet.Dto;
using Synthesis.Bethesda.Execution.Patchers.Git;

namespace Synthesis.Bethesda.Execution.Patchers.Running.Git;

public interface IWriteShortCircuitMeta
{
void WriteMeta(RunnerRepoInfo info);
void WriteMeta(RunnerRepoInfo info, DotNetVersion dotNetVersion);
void WriteMeta(string metaPath, GitCompilationMeta meta);
}

public class WriteShortCircuitMeta : IWriteShortCircuitMeta
{
private readonly IFileSystem _fs;
private readonly IProvideCurrentVersions _provideCurrentVersions;

public WriteShortCircuitMeta(IFileSystem fs)
public WriteShortCircuitMeta(
IFileSystem fs,
IProvideCurrentVersions provideCurrentVersions)
{
_fs = fs;
_provideCurrentVersions = provideCurrentVersions;
}

public void WriteMeta(RunnerRepoInfo info)
public void WriteMeta(RunnerRepoInfo info, DotNetVersion dotNetVersion)
{
WriteMeta(info.MetaPath, new GitCompilationMeta()
{
NetSdkVersion = dotNetVersion.Version,
SynthesisUiVersion = _provideCurrentVersions.SynthesisVersion,
MutagenVersion = info.TargetVersions.Mutagen ?? string.Empty,
SynthesisVersion = info.TargetVersions.Synthesis ?? string.Empty,
Sha = info.Target.TargetSha
Expand Down
Loading

0 comments on commit be0f7d6

Please sign in to comment.