Use source generation for VersionInfo (#3625)
* Use source generator for VersionInfo * Remove leftover hacks * Use same fallbacks as NixHawk when Git not available --------- Co-authored-by: YoshiRulz <OSSYoshiRulz@gmail.com>
This commit is contained in:
parent
03aa420bd5
commit
ddc3e929e9
|
@ -29,8 +29,6 @@
|
|||
/BizHawk.Client.EmuHawk/tools/TAStudio/HistoryBox.resx
|
||||
|
||||
|
||||
/src/BizHawk.Common/VersionInfo.gen.cs
|
||||
|
||||
/src/BizHawk.Tests*/res/*_artifact
|
||||
/src/BizHawk.Tests*/res/fw
|
||||
|
||||
|
|
|
@ -99,9 +99,7 @@ check_style:
|
|||
when: always
|
||||
allow_failure: false
|
||||
script:
|
||||
- cd src/BizHawk.Version
|
||||
- dotnet build -c Release # configuration doesn't really matter as the assembly is empty
|
||||
- ../../Dist/BuildRelease.sh -p:RunAnalyzersDuringBuild=true
|
||||
- Dist/BuildRelease.sh -p:RunAnalyzersDuringBuild=true
|
||||
stage: test
|
||||
|
||||
.disabled_job_infersharp:
|
||||
|
|
27
BizHawk.sln
27
BizHawk.sln
|
@ -2,46 +2,23 @@
|
|||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.28729.10
|
||||
MinimumVisualStudioVersion = 16.0.28729.10
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BizHawk.Version", "src\BizHawk.Version\BizHawk.Version.csproj", "{0CE8B337-08E3-4602-BF10-C4D4C75D2F13}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BizHawk.Client.Common", "src\BizHawk.Client.Common\BizHawk.Client.Common.csproj", "{24A0AA3C-B25F-4197-B23D-476D6462DBA0}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{0CE8B337-08E3-4602-BF10-C4D4C75D2F13} = {0CE8B337-08E3-4602-BF10-C4D4C75D2F13}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BizHawk.Common", "src\BizHawk.Common\BizHawk.Common.csproj", "{866F8D13-0678-4FF9-80A4-A3993FD4D8A3}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{0CE8B337-08E3-4602-BF10-C4D4C75D2F13} = {0CE8B337-08E3-4602-BF10-C4D4C75D2F13}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BizHawk.Client.EmuHawk", "src\BizHawk.Client.EmuHawk\BizHawk.Client.EmuHawk.csproj", "{DD448B37-BA3F-4544-9754-5406E8094723}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{0CE8B337-08E3-4602-BF10-C4D4C75D2F13} = {0CE8B337-08E3-4602-BF10-C4D4C75D2F13}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BizHawk.Client.DiscoHawk", "src\BizHawk.Client.DiscoHawk\BizHawk.Client.DiscoHawk.csproj", "{C4366030-6D03-424B-AE53-F4F43BB217C3}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{0CE8B337-08E3-4602-BF10-C4D4C75D2F13} = {0CE8B337-08E3-4602-BF10-C4D4C75D2F13}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BizHawk.Emulation.DiscSystem", "src\BizHawk.Emulation.DiscSystem\BizHawk.Emulation.DiscSystem.csproj", "{F51946EA-827F-4D82-B841-1F2F6D060312}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{0CE8B337-08E3-4602-BF10-C4D4C75D2F13} = {0CE8B337-08E3-4602-BF10-C4D4C75D2F13}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BizHawk.Emulation.Common", "src\BizHawk.Emulation.Common\BizHawk.Emulation.Common.csproj", "{E1A23168-B571-411C-B360-2229E7225E0E}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{0CE8B337-08E3-4602-BF10-C4D4C75D2F13} = {0CE8B337-08E3-4602-BF10-C4D4C75D2F13}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Client", "Client", "{B51F1139-3D2C-41BE-A762-EF1F9B41EACA}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Emulation", "Emulation", "{3627C08B-3E43-4224-9DA4-40BD69495FBC}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BizHawk.Emulation.Cores", "src\BizHawk.Emulation.Cores\BizHawk.Emulation.Cores.csproj", "{197D4314-8A9F-49BA-977D-54ACEFAEB6BA}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{0CE8B337-08E3-4602-BF10-C4D4C75D2F13} = {0CE8B337-08E3-4602-BF10-C4D4C75D2F13}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BizHawk.Bizware.BizwareGL", "src\BizHawk.Bizware.BizwareGL\BizHawk.Bizware.BizwareGL.csproj", "{9F84A0B2-861E-4EF4-B89B-5E2A3F38A465}"
|
||||
EndProject
|
||||
|
@ -63,10 +40,6 @@ Global
|
|||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{0CE8B337-08E3-4602-BF10-C4D4C75D2F13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0CE8B337-08E3-4602-BF10-C4D4C75D2F13}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0CE8B337-08E3-4602-BF10-C4D4C75D2F13}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0CE8B337-08E3-4602-BF10-C4D4C75D2F13}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{24A0AA3C-B25F-4197-B23D-476D6462DBA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{24A0AA3C-B25F-4197-B23D-476D6462DBA0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{24A0AA3C-B25F-4197-B23D-476D6462DBA0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
|
|
Binary file not shown.
|
@ -1,64 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{9BDF5B40-2547-4BAE-8FA7-C9BA0002CF03}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>BizHawk.Build.Tool</RootNamespace>
|
||||
<AssemblyName>BizHawk.Build.Tool</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile>
|
||||
</TargetFrameworkProfile>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<OutputPath>..\</OutputPath>
|
||||
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<OutputPath>..\</OutputPath>
|
||||
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="FileLocator.cs" />
|
||||
<Compile Include="Tool.cs" />
|
||||
<Compile Include="ToolPathUtil.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
|
@ -1,20 +0,0 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual Studio 2010
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BizHawk.Build.Tool", "BizHawk.Build.Tool.csproj", "{9BDF5B40-2547-4BAE-8FA7-C9BA0002CF03}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{9BDF5B40-2547-4BAE-8FA7-C9BA0002CF03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9BDF5B40-2547-4BAE-8FA7-C9BA0002CF03}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9BDF5B40-2547-4BAE-8FA7-C9BA0002CF03}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9BDF5B40-2547-4BAE-8FA7-C9BA0002CF03}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -1,51 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Microsoft.Win32;
|
||||
|
||||
static class FileLocator
|
||||
{
|
||||
public static string LocateTool(string _toolName)
|
||||
{
|
||||
string t = ToolPathUtil.MakeToolName(_toolName);
|
||||
string dir = null;
|
||||
try
|
||||
{
|
||||
dir = FindToolPath(t);
|
||||
}
|
||||
catch { }
|
||||
if (dir == null)
|
||||
return "";
|
||||
else
|
||||
return System.IO.Path.Combine(dir, t);
|
||||
|
||||
}
|
||||
|
||||
//stolen from MSBuild.Community.Tasks
|
||||
static string FindToolPath(string toolName)
|
||||
{
|
||||
string toolPath =
|
||||
ToolPathUtil.FindInRegistry(toolName) ??
|
||||
ToolPathUtil.FindInPath(toolName) ??
|
||||
ToolPathUtil.FindInProgramFiles(toolName,
|
||||
@"Subversion\bin",
|
||||
@"CollabNet Subversion Server",
|
||||
@"CollabNet Subversion",
|
||||
@"CollabNet Subversion Client",
|
||||
@"VisualSVN\bin",
|
||||
@"VisualSVN Server\bin",
|
||||
@"TortoiseSVN\bin",
|
||||
@"SlikSvn\bin",
|
||||
@"Git\bin"
|
||||
);
|
||||
|
||||
if (toolPath == null)
|
||||
{
|
||||
throw new Exception("Could not find svn.exe. Looked in PATH locations and various common folders inside Program Files.");
|
||||
}
|
||||
|
||||
return toolPath;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,249 +0,0 @@
|
|||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace BizHawk.Build.Tool
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
string cmd = args[0];
|
||||
string[] cmdArgs = Crop(args, 1);
|
||||
switch (cmd.ToUpperInvariant())
|
||||
{
|
||||
case "SVN_REV": SVN_REV(true,cmdArgs); break;
|
||||
case "GIT_REV": SVN_REV(false,cmdArgs); break;
|
||||
case "NXCOMPAT": NXCOMPAT(cmdArgs); break;
|
||||
case "LARGEADDRESS": LARGEADDRESS(cmdArgs); break;
|
||||
case "TIMESTAMP": TIMESTAMP(cmdArgs); break;
|
||||
}
|
||||
}
|
||||
|
||||
static string[] Crop(string[] arr, int from)
|
||||
{
|
||||
return arr.Reverse().Take(arr.Length - from).Reverse().ToArray();
|
||||
}
|
||||
|
||||
static string EscapeArgument(string s)
|
||||
{
|
||||
return "\"" + Regex.Replace(s, @"(\\+)$", @"$1$1") + "\"";
|
||||
}
|
||||
|
||||
static string RunTool(string path, params string[] args)
|
||||
{
|
||||
string args_combined = "";
|
||||
foreach (var a in args)
|
||||
args_combined += EscapeArgument(a) + " ";
|
||||
args_combined.TrimEnd(' ');
|
||||
|
||||
var psi = new System.Diagnostics.ProcessStartInfo();
|
||||
psi.Arguments = args_combined;
|
||||
psi.FileName = path;
|
||||
psi.UseShellExecute = false;
|
||||
psi.CreateNoWindow = true;
|
||||
psi.RedirectStandardOutput = true;
|
||||
var proc = new System.Diagnostics.Process();
|
||||
proc.StartInfo = psi;
|
||||
proc.Start();
|
||||
|
||||
string output = "";
|
||||
while (!proc.StandardOutput.EndOfStream)
|
||||
{
|
||||
output += proc.StandardOutput.ReadLine();
|
||||
// do something with line
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
static void WriteTextIfChanged(string path, string content)
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
goto WRITE;
|
||||
string old = File.ReadAllText(path);
|
||||
if (old == content) return;
|
||||
WRITE:
|
||||
File.WriteAllText(path, content);
|
||||
}
|
||||
|
||||
static void LARGEADDRESS(string[] args)
|
||||
{
|
||||
string target = null, strValue = "0";
|
||||
int idx = 0;
|
||||
while (idx < args.Length)
|
||||
{
|
||||
string a = args[idx++];
|
||||
string au = a.ToUpperInvariant();
|
||||
if (au == "--TARGET")
|
||||
target = args[idx++];
|
||||
if (au == "--VALUE")
|
||||
strValue = args[idx++];
|
||||
}
|
||||
if (target == null)
|
||||
{
|
||||
Console.WriteLine("LARGEADDRESS: No target EXE specified");
|
||||
return;
|
||||
}
|
||||
|
||||
//http://stackoverflow.com/questions/9054469/how-to-check-if-exe-is-set-as-largeaddressaware
|
||||
using (var fs = new FileStream(target, FileMode.Open, FileAccess.ReadWrite, FileShare.Read))
|
||||
{
|
||||
var br = new BinaryReader(fs);
|
||||
|
||||
if (br.ReadInt16() != 0x5A4D) //No MZ Header
|
||||
return;
|
||||
|
||||
br.BaseStream.Position = 0x3C;
|
||||
var peloc = br.ReadInt32(); //Get the PE header location.
|
||||
|
||||
br.BaseStream.Position = peloc;
|
||||
if (br.ReadInt32() != 0x4550) //No PE header
|
||||
return;
|
||||
|
||||
br.BaseStream.Position += 0x12;
|
||||
var characteristics = br.ReadUInt16();
|
||||
characteristics &= unchecked((ushort)~0x20); //IMAGE_FILE_LARGE_ADDRESS_AWARE
|
||||
if (strValue == "1") characteristics |= 0x20;
|
||||
fs.Position -= 2; //move back to characteristics
|
||||
var bw = new BinaryWriter(fs);
|
||||
bw.Write(characteristics);
|
||||
bw.Flush();
|
||||
}
|
||||
}
|
||||
|
||||
//clears the timestamp in PE header (for deterministic builds)
|
||||
static void TIMESTAMP(string[] args)
|
||||
{
|
||||
using (var fs = new FileStream(args[0], FileMode.Open, FileAccess.ReadWrite, FileShare.Read))
|
||||
{
|
||||
fs.Position = 0x88;
|
||||
fs.WriteByte(0); fs.WriteByte(0); fs.WriteByte(0); fs.WriteByte(0);
|
||||
}
|
||||
}
|
||||
|
||||
//sets NXCOMPAT bit in PE header
|
||||
static void NXCOMPAT(string[] args)
|
||||
{
|
||||
string target = null, strValue = "0";
|
||||
int idx = 0;
|
||||
while (idx < args.Length)
|
||||
{
|
||||
string a = args[idx++];
|
||||
string au = a.ToUpperInvariant();
|
||||
if (au == "--TARGET")
|
||||
target = args[idx++];
|
||||
if (au == "--VALUE")
|
||||
strValue = args[idx++];
|
||||
}
|
||||
if (target == null)
|
||||
{
|
||||
Console.WriteLine("NXCOMPAT: No target EXE specified");
|
||||
return;
|
||||
}
|
||||
|
||||
//we're going to skip around through the file and edit only the minimum required bytes (to speed things up by avoiding loading and rewriting the entire exe)
|
||||
using(var fs = new FileStream(target,FileMode.Open,FileAccess.ReadWrite,FileShare.Read))
|
||||
{
|
||||
var br = new BinaryReader(fs);
|
||||
fs.Position = 0x3C;
|
||||
fs.Position = br.ReadUInt16(); //move to NT_HEADERS
|
||||
fs.Position += 0x18; //move to OPTIONAL_HEADER
|
||||
fs.Position += 0x46; //move to DllCharacteristics
|
||||
var dllCharacteristics = br.ReadUInt16();
|
||||
dllCharacteristics &= unchecked((ushort)~0x100);
|
||||
if (strValue == "1") dllCharacteristics |= 0x100;
|
||||
fs.Position -= 2; //move back to DllCharacteristics
|
||||
var bw = new BinaryWriter(fs);
|
||||
bw.Write(dllCharacteristics);
|
||||
bw.Flush();
|
||||
}
|
||||
}
|
||||
|
||||
//gets the working copy version. use this command:
|
||||
//BizHawk.Build.Tool.exe SCM_REV --wc c:\path\to\wcdir --template c:\path\to\templatefile --out c:\path\to\outputfile.cs
|
||||
//if the required tools aren't found
|
||||
static void SVN_REV(bool svn, string[] args)
|
||||
{
|
||||
string wcdir = null, templatefile = null, outfile = null;
|
||||
int idx=0;
|
||||
while (idx < args.Length)
|
||||
{
|
||||
string a = args[idx++];
|
||||
string au = a.ToUpperInvariant();
|
||||
if(au == "--WC")
|
||||
wcdir = args[idx++];
|
||||
if(au == "--TEMPLATE")
|
||||
templatefile = args[idx++];
|
||||
if (au == "--OUT")
|
||||
outfile = args[idx++];
|
||||
}
|
||||
|
||||
//first read the template
|
||||
string templateContents = File.ReadAllText(templatefile);
|
||||
|
||||
//pick revision 0 in case the WC investigation fails
|
||||
int rev = 0;
|
||||
|
||||
//pick branch unnamed in case investigation fails (or isnt git)
|
||||
string branch = "";
|
||||
|
||||
//pick no hash in case investigation fails (or isnt git)
|
||||
string shorthash = "";
|
||||
|
||||
//try to find an SVN or GIT and run it
|
||||
if (svn)
|
||||
{
|
||||
string svntool = FileLocator.LocateTool("svnversion");
|
||||
if (svntool != "")
|
||||
{
|
||||
try
|
||||
{
|
||||
string output = RunTool(svntool, wcdir);
|
||||
var parts = output.Split(':');
|
||||
var rstr = parts[parts.Length - 1];
|
||||
rstr = Regex.Replace(rstr, "[^0-9]", "");
|
||||
rev = int.Parse(rstr);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string gittool = FileLocator.LocateTool("git");
|
||||
if (gittool != "")
|
||||
{
|
||||
try
|
||||
{
|
||||
string output = RunTool(gittool, "-C", wcdir, "rev-list", "HEAD", "--count");
|
||||
if(int.TryParse(output, out rev))
|
||||
{
|
||||
output = RunTool(gittool, "-C", wcdir, "rev-parse", "--abbrev-ref", "HEAD");
|
||||
if(output.StartsWith("fatal")) {}
|
||||
else branch = output;
|
||||
|
||||
output = RunTool(gittool, "-C", wcdir, "log", "-1", "--format=\"%h\"");
|
||||
if (output.StartsWith("fatal")) { }
|
||||
else shorthash = output;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//replace the template and dump the results if needed
|
||||
templateContents = templateContents.Replace("$WCREV$", rev.ToString());
|
||||
templateContents = templateContents.Replace("$WCBRANCH$", branch);
|
||||
templateContents = templateContents.Replace("$WCSHORTHASH$", shorthash);
|
||||
WriteTextIfChanged(outfile, templateContents);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Microsoft.Win32;
|
||||
|
||||
//This is stolen from MSBuild Community Tasks
|
||||
static class ToolPathUtil
|
||||
{
|
||||
public static bool SafeFileExists(string path, string toolName)
|
||||
{
|
||||
return SafeFileExists(Path.Combine(path, toolName));
|
||||
}
|
||||
|
||||
public static bool SafeFileExists(string file)
|
||||
{
|
||||
try { return File.Exists(file); }
|
||||
catch { } // eat exception
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static string MakeToolName(string name)
|
||||
{
|
||||
return (Environment.OSVersion.Platform == PlatformID.Unix) ?
|
||||
name : name + ".exe";
|
||||
}
|
||||
|
||||
public static string FindInRegistry(string toolName)
|
||||
{
|
||||
try
|
||||
{
|
||||
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\" + toolName, false);
|
||||
if (key != null)
|
||||
{
|
||||
string possiblePath = key.GetValue(null) as string;
|
||||
if (SafeFileExists(possiblePath))
|
||||
return Path.GetDirectoryName(possiblePath);
|
||||
}
|
||||
}
|
||||
catch (System.Security.SecurityException) { }
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string FindInPath(string toolName)
|
||||
{
|
||||
string pathEnvironmentVariable = Environment.GetEnvironmentVariable("PATH") ?? string.Empty;
|
||||
string[] paths = pathEnvironmentVariable.Split(new[] { Path.PathSeparator }, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string path in paths)
|
||||
{
|
||||
if (SafeFileExists(path, toolName))
|
||||
{
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string FindInProgramFiles(string toolName, params string[] commonLocations)
|
||||
{
|
||||
var trials = new[] { Environment.GetEnvironmentVariable("ProgramFiles(x86)"), Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) };
|
||||
foreach (var t in trials)
|
||||
{
|
||||
if (t == null) continue;
|
||||
foreach (string location in commonLocations)
|
||||
{
|
||||
string path = Path.Combine(t, location);
|
||||
if (SafeFileExists(path, toolName))
|
||||
{
|
||||
return path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string FindInLocalPath(string toolName, string localPath)
|
||||
{
|
||||
if (localPath == null)
|
||||
return null;
|
||||
|
||||
string path = new DirectoryInfo(localPath).FullName;
|
||||
if (SafeFileExists(localPath, toolName))
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
#!/bin/sh
|
||||
sed -e "s;\\\$WCREV\\\$;$(git rev-list HEAD --count);" -e "s;\\\$WCBRANCH\\\$;$(git rev-parse --abbrev-ref HEAD);" -e "s;\\\$WCSHORTHASH\\\$;$(git log -1 --format="%h");" "$1" >"$2"
|
|
@ -14,11 +14,6 @@ dotnet build ..\BizHawk.sln -c Release --no-incremental
|
|||
rem -p:Platform="Any CPU"
|
||||
rem -p:RunAnalyzersDuringBuild=true
|
||||
|
||||
rem we have to do this twice right now
|
||||
dotnet build ..\BizHawk.sln -c Release
|
||||
|
||||
@if errorlevel 1 goto DOTNETBUILDFAILED
|
||||
|
||||
rmdir /s /q temp
|
||||
del /s %NAME%
|
||||
cd ..\output
|
||||
|
@ -27,7 +22,7 @@ rem slimdx has a way of not making it into the output directory, so this is a go
|
|||
copy ..\..\SlimDx.dll
|
||||
|
||||
rem Now, we're about to zip and then unzip. Why, you ask? Because that's just the way this evolved.
|
||||
..\dist\zip.exe -X -r ..\Dist\%NAME% EmuHawk.exe EmuHawk.exe.config DiscoHawk.exe DiscoHawk.exe.config defctrl.json EmuHawkMono.sh dll Shaders gamedb Tools NES\Palettes Lua Gameboy\Palettes overlay -x *.pdb -x *.lib -x *.pgd -x *.ipdb -x *.iobj -x *.exp -x dll\libsneshawk-64*.exe -x *.ilk -x dll\gpgx.elf -x dll\miniclient.*
|
||||
..\dist\zip.exe -X -r ..\Dist\%NAME% EmuHawk.exe EmuHawk.exe.config DiscoHawk.exe DiscoHawk.exe.config defctrl.json EmuHawkMono.sh dll Shaders gamedb Tools NES\Palettes Lua Gameboy\Palettes overlay -x *.pdb -x *.lib -x *.pgd -x *.ipdb -x *.iobj -x *.exp -x dll\libsneshawk-64*.exe -x *.ilk -x dll\gpgx.elf -x dll\miniclient.*
|
||||
|
||||
cd ..\Dist
|
||||
.\unzip.exe %NAME% -d temp
|
||||
|
@ -81,4 +76,3 @@ goto END
|
|||
set ERRORLEVEL=1
|
||||
@echo missing git.exe. can't make distro without that.
|
||||
:END
|
||||
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<Import Project="../AnalyzersCommon.props" />
|
||||
</Project>
|
|
@ -0,0 +1,66 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.CodeAnalysis;
|
||||
|
||||
namespace BizHawk.SrcGen.VersionInfo;
|
||||
|
||||
[Generator]
|
||||
public class VersionInfoGenerator : ISourceGenerator
|
||||
{
|
||||
public void Initialize(GeneratorInitializationContext context)
|
||||
{
|
||||
}
|
||||
|
||||
private static string? ExecuteGitWithArguments(string arguments)
|
||||
{
|
||||
var startInfo = new ProcessStartInfo("git", arguments)
|
||||
{
|
||||
RedirectStandardOutput = true,
|
||||
CreateNoWindow = true,
|
||||
UseShellExecute = false // this is just required for visual studio (:
|
||||
};
|
||||
try
|
||||
{
|
||||
using Process git = Process.Start(startInfo) ?? throw new Exception("Failed to start git process");
|
||||
git.WaitForExit();
|
||||
return git.StandardOutput.ReadLine();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
#if DEBUG
|
||||
return $"{e.GetType()}: {e.Message}";
|
||||
#else
|
||||
return null;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute(GeneratorExecutionContext context)
|
||||
{
|
||||
// Finds the current project directory in order to pass to git commands.
|
||||
// This is written in a way to (hopefully) work both for build and IDE analyzers
|
||||
// FIXME: This should probably be done in a better way, but I haven't found any
|
||||
string projectDir = Path.GetDirectoryName(context.Compilation.SyntaxTrees.First(x => x.HasCompilationUnitRoot && x.FilePath.Contains("BizHawk.Common")).FilePath)!;
|
||||
|
||||
var rev = ExecuteGitWithArguments($"-C {projectDir} rev-list HEAD --count") ?? string.Empty;
|
||||
var branch = ExecuteGitWithArguments($"-C {projectDir} rev-parse --abbrev-ref HEAD") ?? "master";
|
||||
var shortHash = ExecuteGitWithArguments($"-C {projectDir} log -1 --format=\"%h\"") ?? "000000000";
|
||||
|
||||
// Generated source code
|
||||
string source = $@"namespace BizHawk.Common
|
||||
{{
|
||||
public static partial class VersionInfo
|
||||
{{
|
||||
public const string SVN_REV = ""{rev}"";
|
||||
public const string GIT_BRANCH = ""{branch}"";
|
||||
public const string GIT_SHORTHASH = ""{shortHash}"";
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
// Add the source code to the compilation
|
||||
context.AddSource("VersionInfo.g.cs", source);
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
../.build_debug.sh
|
|
@ -0,0 +1 @@
|
|||
../.build_release.sh
|
Binary file not shown.
|
@ -14,8 +14,6 @@
|
|||
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<!-- target in Version project generates VersionInfo.gen.cs; note that the Version project MUST BE FIRST in solution file -->
|
||||
<ProjectReference Include="$(ProjectDir)../BizHawk.Version/BizHawk.Version.csproj" ReferenceOutputAssembly="false" />
|
||||
<Compile Update="VersionInfo.gen.cs" DependentUpon="VersionInfo.cs" />
|
||||
<Analyzer Include="$(MSBuildProjectDirectory)/../../References/BizHawk.SrcGen.VersionInfo.dll" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<Import Project="../../Common.props" />
|
||||
<PropertyGroup>
|
||||
<EnableDefaultCompileItems>false</EnableDefaultCompileItems><!-- no source files; only runs below target to write ../BizHawk.Common/VersionInfo.gen.cs -->
|
||||
<LangVersion>9.0</LangVersion>
|
||||
<NoWarn>$(NoWarn);CS2008</NoWarn>
|
||||
</PropertyGroup>
|
||||
<Target Name="PreBuild" AfterTargets="PreBuildEvent">
|
||||
<Exec Condition=" '$(OS)' == 'Windows_NT' " Command='"$(ProjectDir)..\..\Build\BizHawk.Build.Tool.exe" GIT_REV --wc "$(ProjectDir).." --template "$(ProjectDir)VersionInfo.gen_template.cs" --out "$(ProjectDir)..\BizHawk.Common\VersionInfo.gen.cs"' />
|
||||
<Exec Condition=" '$(OS)' != 'Windows_NT' " Command='"$(ProjectDir)../../Build/standin.sh" "$(ProjectDir)VersionInfo.gen_template.cs" "$(ProjectDir)../BizHawk.Common/VersionInfo.gen.cs"' />
|
||||
</Target>
|
||||
</Project>
|
|
@ -1,11 +0,0 @@
|
|||
// This file (VersionInfo.gen.cs) is auto-generated. Any edits will be overwritten before compilation.
|
||||
|
||||
namespace BizHawk.Common
|
||||
{
|
||||
public static partial class VersionInfo
|
||||
{
|
||||
public const string SVN_REV = "$WCREV$";
|
||||
public const string GIT_BRANCH = "$WCBRANCH$";
|
||||
public const string GIT_SHORTHASH = "$WCSHORTHASH$";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue