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 Oct 15, 2020
2 parents 726452d + 8592fbe commit 41bb3c1
Show file tree
Hide file tree
Showing 19 changed files with 628 additions and 163 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<PropertyGroup>
<Nullable>enable</Nullable>
<WarningsAsErrors>nullable</WarningsAsErrors>
<Version>0.10.1</Version>
<Version>0.10.2</Version>
</PropertyGroup>
</Project>
13 changes: 13 additions & 0 deletions Mutagen.Bethesda.Synthesis/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Noggog;
using System;
using System.Diagnostics;
using BaseSynthesis = Synthesis.Bethesda;

namespace Mutagen.Bethesda.Synthesis
{
public static class Constants
{
public static string MutagenVersion => FileVersionInfo.GetVersionInfo(typeof(FormKey).Assembly.Location)!.ProductVersion.TrimEnd(".0").TrimEnd(".0");
public static string SynthesisVersion => FileVersionInfo.GetVersionInfo(typeof(BaseSynthesis.Constants).Assembly.Location)!.ProductVersion.TrimEnd(".0").TrimEnd(".0");
}
}
9 changes: 3 additions & 6 deletions Mutagen.Bethesda.Synthesis/InternalUtility.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using Mutagen.Bethesda.Internals;
using Mutagen.Bethesda.Synthesis.CLI;
using Noggog;
using Synthesis.Bethesda;
using System;
using System.Linq;
using Constants = Synthesis.Bethesda.Constants;
using BaseSynthesis = Synthesis.Bethesda;

namespace Mutagen.Bethesda.Synthesis.Internal
{
Expand All @@ -28,7 +25,7 @@ public static SynthesisState<TMod, TModGetter> ToState<TMod, TModGetter>(RunSynt
// Get load order
var loadOrderListing = SynthesisPipeline.Instance.GetLoadOrder(settings, userPrefs)
.ToExtendedList();
var synthIndex = loadOrderListing.IndexOf(Constants.SynthesisModKey, (listing, key) => listing.ModKey == key);
var synthIndex = loadOrderListing.IndexOf(BaseSynthesis.Constants.SynthesisModKey, (listing, key) => listing.ModKey == key);
if (synthIndex != -1)
{
loadOrderListing.RemoveToCount(synthIndex);
Expand All @@ -43,7 +40,7 @@ public static SynthesisState<TMod, TModGetter> ToState<TMod, TModGetter>(RunSynt
settings.GameRelease);

// Get Modkey from output path
var modKey = Constants.SynthesisModKey;
var modKey = BaseSynthesis.Constants.SynthesisModKey;

// Create or import patch mod
TMod patchMod;
Expand Down
6 changes: 2 additions & 4 deletions Mutagen.Bethesda.Synthesis/SynthesisPipeline.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
using CommandLine;
using Mutagen.Bethesda.Internals;
using Mutagen.Bethesda.Synthesis.CLI;
using Mutagen.Bethesda.Synthesis.Internal;
using Noggog;
using Synthesis.Bethesda;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wabbajack.Common;

Expand Down Expand Up @@ -127,6 +123,8 @@ public int Patch<TMod, TModGetter>(
where TMod : class, IMod, TModGetter
where TModGetter : class, IModGetter
{
Console.WriteLine($"Mutagen version: {Constants.MutagenVersion}");
Console.WriteLine($"Synthesis version: {Constants.SynthesisVersion}");
if (args.Length == 0)
{
var prefs = userPreferences ?? new UserPreferences();
Expand Down
2 changes: 0 additions & 2 deletions Synthesis.Bethesda.Execution/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Synthesis.Bethesda.Execution
{
Expand Down
74 changes: 74 additions & 0 deletions Synthesis.Bethesda.Execution/NugetQuery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using Noggog;
using Noggog.Utility;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;

namespace Synthesis.Bethesda.Execution
{
public static class NugetQuery
{
public static async Task<IEnumerable<(string Package, string Requested, string Resolved, string Latest)>> Query(string projectPath, bool queryServer)
{
// Run restore first
{
using var restore = ProcessWrapper.Start(
new ProcessStartInfo("dotnet", $"restore \"{projectPath}\""));
await restore.Start();
}

bool on = false;
List<string> lines = new List<string>();
List<string> errors = new List<string>();
using var process = ProcessWrapper.Start(
new ProcessStartInfo("dotnet", $"list \"{projectPath}\" package{(queryServer ? " --outdated" : null)}"));
using var outSub = process.Output.Subscribe(s =>
{
if (s.Contains("Top-level Package"))
{
on = true;
return;
}
if (!on) return;
lines.Add(s);
});
using var errSub = process.Error.Subscribe(s => errors.Add(s));
var result = await process.Start();
if (errors.Count > 0)
{
throw new ArgumentException($"Error while retrieving nuget listings: \n{string.Join("\n", errors)}");
}

var ret = new List<(string Package, string Requested, string Resolved, string Latest)>();
foreach (var line in lines)
{
var startIndex = line.IndexOf("> ");
if (startIndex == -1) continue;
var split = line.Substring(startIndex + 2).Split(' ', StringSplitOptions.RemoveEmptyEntries);
ret.Add((split[0], split[1], split[2], split[3]));
}
return ret;
}

public static async Task<(string? MutagenVersion, string? SynthesisVersion)> QueryVersions(string projectPath, bool current)
{
string? mutagenVersion = null, synthesisVersion = null;
var queries = await Query(projectPath, !current);
foreach (var item in queries)
{
if (item.Package.StartsWith("Mutagen.Bethesda")
&& !item.Package.EndsWith("Synthesis"))
{
mutagenVersion = current ? item.Resolved : item.Latest;
}
if (item.Package.Equals("Mutagen.Bethesda.Synthesis"))
{
synthesisVersion = current ? item.Resolved : item.Latest;
}
}
return (mutagenVersion, synthesisVersion);
}
}
}
82 changes: 81 additions & 1 deletion Synthesis.Bethesda.Execution/Patcher Runs/GitPatcherRun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
using Mutagen.Bethesda;
using Noggog;
using Synthesis.Bethesda.Execution.Patchers;
using Synthesis.Bethesda.Execution.Reporters;
using Synthesis.Bethesda.Execution.Settings;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reactive.Subjects;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace Synthesis.Bethesda.Execution
{
Expand All @@ -27,6 +28,18 @@ public class GitPatcherRun : IPatcherRun
private Subject<string> _error = new Subject<string>();
public IObservable<string> Error => _error;

private static readonly HashSet<string> MutagenLibraries;

static GitPatcherRun()
{
MutagenLibraries = EnumExt.GetValues<GameCategory>()
.Select(x => $"Mutagen.Bethesda.{x}")
.And("Mutagen.Bethesda")
.And("Mutagen.Bethesda.Core")
.And("Mutagen.Bethesda.Kernel")
.ToHashSet();
}

public GitPatcherRun(
GithubPatcherSettings settings,
string localDir)
Expand Down Expand Up @@ -155,5 +168,72 @@ public static string RunnerRepoDirectory(string profileID, string githubID)
{
return Path.Combine(Execution.Constants.WorkingDirectory, profileID, "Git", githubID, "Runner");
}

public static void SwapInDesiredVersionsForSolution(
string solutionPath,
string drivingProjSubPath,
string? mutagenVersion,
out string? listedMutagenVersion,
string? synthesisVersion,
out string? listedSynthesisVersion)
{
listedMutagenVersion = null;
listedSynthesisVersion = null;
foreach (var subProj in SolutionPatcherRun.AvailableProjects(solutionPath))
{
var proj = Path.Combine(Path.GetDirectoryName(solutionPath), subProj);
File.WriteAllText(proj,
SwapInDesiredVersionsForProjectString(
File.ReadAllText(proj),
mutagenVersion: mutagenVersion,
listedMutagenVersion: out var curListedMutagenVersion,
synthesisVersion: synthesisVersion,
listedSynthesisVersion: out var curListedSynthesisVersion));
if (drivingProjSubPath.Equals(subProj))
{
listedMutagenVersion = curListedMutagenVersion;
listedSynthesisVersion = curListedSynthesisVersion;
}
}
}

public static string SwapInDesiredVersionsForProjectString(
string projStr,
string? mutagenVersion,
out string? listedMutagenVersion,
string? synthesisVersion,
out string? listedSynthesisVersion)
{
var root = XElement.Parse(projStr);
listedMutagenVersion = null;
listedSynthesisVersion = null;
foreach (var group in root.Elements("ItemGroup"))
{
foreach (var elem in group.Elements())
{
if (!elem.Name.LocalName.Equals("PackageReference")) continue;
if (!elem.TryGetAttribute("Include", out var libAttr)) continue;
string swapInStr;
if (libAttr.Value.Equals("Mutagen.Bethesda.Synthesis"))
{
listedSynthesisVersion = elem.Attribute("Version")?.Value;
if (synthesisVersion == null) continue;
swapInStr = synthesisVersion;
}
else if (MutagenLibraries.Contains(libAttr.Value))
{
listedMutagenVersion = elem.Attribute("Version")?.Value;
if (mutagenVersion == null) continue;
swapInStr = mutagenVersion;
}
else
{
continue;
}
elem.SetAttributeValue("Version", swapInStr);
}
}
return root.ToString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,13 @@ public void Dispose()
return (true, default);
}

public static async Task<ErrorResponse> CompileWithDotnet(string url, CancellationToken cancel)
public static async Task<ErrorResponse> CompileWithDotnet(string targetPath, CancellationToken cancel)
{
using var process = ProcessWrapper.Start(
new ProcessStartInfo("dotnet", $"build \"{url}\""),
new ProcessStartInfo("dotnet", $"build \"{Path.GetFileName(targetPath)}\"")
{
WorkingDirectory = Path.GetDirectoryName(targetPath)
},
cancel: cancel);
string? firstError = null;
bool buildFailed = false;
Expand Down
17 changes: 12 additions & 5 deletions Synthesis.Bethesda.Execution/Settings/GithubPatcherSettings.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using Noggog;
using Synthesis.Bethesda.Execution.Reporters;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Synthesis.Bethesda.Execution.Settings
{
Expand All @@ -17,8 +14,15 @@ public enum PatcherVersioningEnum

public enum MutagenVersioningEnum
{
Latest,
Match,
Manual,
}

public enum SynthesisVersioningEnum
{
Latest,
Match,
Manual,
}

Expand All @@ -28,10 +32,13 @@ public class GithubPatcherSettings : PatcherSettings
public string RemoteRepoPath = string.Empty;
public string SelectedProjectSubpath = string.Empty;
public PatcherVersioningEnum PatcherVersioning = PatcherVersioningEnum.Master;
public MutagenVersioningEnum MutagenVersioning = MutagenVersioningEnum.Match;
public string TargetTag = string.Empty;
public string TargetCommit = string.Empty;
public string TargetBranch = string.Empty;
public MutagenVersioningEnum MutagenVersioning = MutagenVersioningEnum.Latest;
public string ManualMutagenVersion = string.Empty;
public SynthesisVersioningEnum SynthesisVersioning = SynthesisVersioningEnum.Latest;
public string ManualSynthesisVersion = string.Empty;

public override void Print(IRunReporter logger)
{
Expand All @@ -42,7 +49,7 @@ public string PatcherVersioningString()
{
return PatcherVersioning switch
{
PatcherVersioningEnum.Master => $"Master Track",
PatcherVersioningEnum.Master => $"Master Tracking",
PatcherVersioningEnum.Tag => $"Tag: {TargetTag}",
PatcherVersioningEnum.Branch => $"Branch: {TargetBranch}",
PatcherVersioningEnum.Commit => $"Commit: {TargetCommit}",
Expand Down
Loading

0 comments on commit 41bb3c1

Please sign in to comment.