Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 44 additions & 107 deletions src/tools/Errors2Enum/Program.cs → src/SharpSvn.MSBuild/Errors2Enum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,106 +3,88 @@
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
using System.Linq;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

namespace Errors2Enum
{
class Program
public class Errors2Enum : Task
{
static void Main(string[] args)
{
if (args.Length != 7)
{
Console.Error.WriteLine("Usage: Errors2Enum <VCPath> <SDKPath> <UniversalSDKDir> <apr_errno.h> <serf.h> <libssh2.h> <outputfile>");
foreach (string s in args)
{
Console.Error.WriteLine("'" + s + "'");
}
Environment.ExitCode = 1;
return;
}
[Required]
public string WinErrorHeaderPath { get; set; }

string vcPath = Path.GetFullPath(args[0]);
string sdkPath = Path.GetFullPath(args[1]);
string usdkPath = string.IsNullOrEmpty(args[2].Trim()) ? "C:\\" : Path.GetFullPath(args[2].Split(new char[] { ';' }, 2)[0]);
string winerror = Path.Combine(sdkPath, "include\\winerror.h");
string errno = Path.Combine(vcPath, "include\\errno.h");
string altErrNo = Path.Combine(usdkPath, "errno.h");
if (!File.Exists(errno) && File.Exists(altErrNo))
errno = altErrNo;
string aprerrno = Path.GetFullPath(args[3]);
string serfh = Path.GetFullPath(args[4]);
string libssh2h = Path.GetFullPath(args[5]);
string to = Path.GetFullPath(args[6]);
[Required]
public string ErrnoHeaderPath { get; set; }

if (!File.Exists(winerror))
winerror = Path.Combine(Path.Combine(Path.GetDirectoryName(winerror), "shared"), "winerror.h");
if (!File.Exists(winerror))
winerror = Path.Combine(usdkPath, "..", "shared", "winerror.h");
[Required]
public string AprErrnoHeaderPath { get; set; }

[Required]
public string SerfHeaderPath { get; set; }

[Required]
public string LibSsh2HeaderPath { get; set; }

[Required]
public string OutputFilePath { get; set; }

public override bool Execute()
{
string winerror = WinErrorHeaderPath;
string errno = ErrnoHeaderPath;
string aprerrno = AprErrnoHeaderPath;
string serfh = SerfHeaderPath;
string libssh2h = LibSsh2HeaderPath;
string to = OutputFilePath;

if (!File.Exists(winerror))
{
if (!File.Exists(winerror))
{
Console.Error.WriteLine("'{0}' does not exist", winerror);
Environment.ExitCode = 1;
return;
}
Log.LogError("'{0}' does not exist", winerror);
Environment.ExitCode = 1;
return false;
}

if (!File.Exists(errno))
{
Console.Error.WriteLine("'{0}' does not exist", errno);
Log.LogError("'{0}' does not exist", errno);
Environment.ExitCode = 1;
return;
return false;
}

if (!File.Exists(aprerrno))
{
Console.Error.WriteLine("'{0}' does not exist", aprerrno);
Log.LogError("'{0}' does not exist", aprerrno);
Environment.ExitCode = 1;
return;
return false;
}

if (!File.Exists(serfh))
{
Console.Error.WriteLine("'{0}' does not exist", aprerrno);
Log.LogError("'{0}' does not exist", aprerrno);
Environment.ExitCode = 1;
return;
return false;
}

if (!Directory.Exists(Path.GetDirectoryName(to)))
{
Console.Error.WriteLine("Parent directory of '{0}' does not exist", to);
Log.LogError("Parent directory of '{0}' does not exist", to);
Environment.ExitCode = 1;
return;
return false;
}


string verHeader = "/* " + typeof(Program).Assembly.FullName + " */";

if (File.Exists(to)
&& File.GetLastWriteTime(to) > File.GetLastWriteTime(winerror)
&& File.GetLastWriteTime(to) > File.GetLastWriteTime(errno)
&& File.GetLastWriteTime(to) > File.GetLastWriteTime(aprerrno)
&& File.GetLastWriteTime(to) > File.GetLastWriteTime(serfh)
&& File.GetLastWriteTime(to) > File.GetLastWriteTime(libssh2h)
&& File.GetLastWriteTime(to) > File.GetLastWriteTime(new Uri(typeof(Program).Assembly.CodeBase).LocalPath))
{
using (StreamReader sr = File.OpenText(to))
{
if (sr.ReadLine() == verHeader)
return; // Nothing to do.
}
}
string verHeader = "/* " + typeof(Errors2Enum).Assembly.FullName + " */";

string to_tmp = to + ".tmp";
using (StreamWriter r = File.CreateText(to_tmp))
using (StreamWriter r = File.CreateText(to))
using (StreamReader header = File.OpenText(winerror))
using (StreamReader aprheader = File.OpenText(aprerrno))
using (StreamReader serfheader = File.OpenText(serfh))
using (StreamReader libssh2 = File.OpenText(libssh2h))
using (StreamReader syserrs = File.OpenText(errno))
{
Log.LogMessage("Generating errors enum...");

r.WriteLine(verHeader);
r.WriteLine("/* GENERATED CODE - Don't edit this file */");
r.WriteLine("#pragma once");
Expand Down Expand Up @@ -137,52 +119,7 @@ static void Main(string[] args)
r.WriteLine();
}

if (File.Exists(to))
{
bool same = false;

using(StreamReader orig = File.OpenText(to))
using(StreamReader nw = File.OpenText(to_tmp))
{
string id_orig = orig.ReadLine();
string id_new = nw.ReadLine();

if (string.IsNullOrEmpty(id_new) == string.IsNullOrEmpty(id_orig))
{
string l1, l2;

while(true)
{
l1 = orig.ReadLine();
l2 = nw.ReadLine();

if (l1 != l2)
{
same = false;
break;
}

if (l1 == null)
{
same = true;
break;
}
}
}
}

if (same)
{
// No different definitions. Don't touch the file as that would trigger
// a recompilation of the precompiled header.
File.Delete(to_tmp);
return;
}
else
File.Delete(to);
}

File.Move(to_tmp, to);
return true;
}

private static void WriteWinEnumBody(StreamReader header, StreamWriter r)
Expand Down
17 changes: 17 additions & 0 deletions src/SharpSvn.MSBuild/Errors2Enum.tasks
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project>
<UsingTask TaskName="Errors2Enum"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll" >
<ParameterGroup>
<WinErrorHeaderPath />
<ErrnoHeaderPath />
<AprErrnoHeaderPath />
<SerfHeaderPath />
<LibSsh2HeaderPath />
<OutputFilePath />
</ParameterGroup>
<Task>
<Code Type="Class" Language="cs" Source="$(MSBuildThisFileDirectory)\Errors2Enum.cs" />
</Task>
</UsingTask>
</Project>
26 changes: 0 additions & 26 deletions src/SharpSvn.sln
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SharpSvn", "SharpSvn\SharpSvn.vcxproj", "{6DD8A600-5A7E-4B7A-91EE-86AB78F58AAC}"
ProjectSection(ProjectDependencies) = postProject
{0CC79A1A-463D-40BB-91E0-3B1391B519C6} = {0CC79A1A-463D-40BB-91E0-3B1391B519C6}
{80CA13E9-790A-4DC3-A45A-EDF6996D82D0} = {80CA13E9-790A-4DC3-A45A-EDF6996D82D0}
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpSvn.Tests", "SharpSvn.Tests\SharpSvn.Tests.csproj", "{6D9F8C0B-E3DA-4FB6-BBF9-FB57791B469D}"
Expand All @@ -33,8 +32,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Po2Resx", "tools\Po2Resx\Po
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HookNotifier", "tools\HookNotifier\HookNotifier.csproj", "{3A1D7085-4B6A-4D47-9FA6-B2A63CDD6595}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Errors2Enum", "tools\Errors2Enum\Errors2Enum.csproj", "{80CA13E9-790A-4DC3-A45A-EDF6996D82D0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpSvn.MSBuild", "SharpSvn.MSBuild\SharpSvn.MSBuild.csproj", "{F1ED9F1C-BC63-4FDF-84D4-6194228C9101}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MSBuild", "MSBuild", "{27C2F39C-9D4A-41CC-8CE7-5B649A8D7036}"
Expand Down Expand Up @@ -195,28 +192,6 @@ Global
{3A1D7085-4B6A-4D47-9FA6-B2A63CDD6595}.ReleaseCore|x64.Build.0 = Release|Any CPU
{3A1D7085-4B6A-4D47-9FA6-B2A63CDD6595}.ReleaseCore|x86.ActiveCfg = Release|Any CPU
{3A1D7085-4B6A-4D47-9FA6-B2A63CDD6595}.ReleaseCore|x86.Build.0 = Release|Any CPU
{80CA13E9-790A-4DC3-A45A-EDF6996D82D0}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{80CA13E9-790A-4DC3-A45A-EDF6996D82D0}.Debug|x64.ActiveCfg = Debug|Any CPU
{80CA13E9-790A-4DC3-A45A-EDF6996D82D0}.Debug|x64.Build.0 = Debug|Any CPU
{80CA13E9-790A-4DC3-A45A-EDF6996D82D0}.Debug|x86.ActiveCfg = Debug|Any CPU
{80CA13E9-790A-4DC3-A45A-EDF6996D82D0}.Debug|x86.Build.0 = Debug|Any CPU
{80CA13E9-790A-4DC3-A45A-EDF6996D82D0}.DebugCore|ARM64.ActiveCfg = Debug|Any CPU
{80CA13E9-790A-4DC3-A45A-EDF6996D82D0}.DebugCore|ARM64.Build.0 = Debug|Any CPU
{80CA13E9-790A-4DC3-A45A-EDF6996D82D0}.DebugCore|x64.ActiveCfg = Debug|Any CPU
{80CA13E9-790A-4DC3-A45A-EDF6996D82D0}.DebugCore|x64.Build.0 = Debug|Any CPU
{80CA13E9-790A-4DC3-A45A-EDF6996D82D0}.DebugCore|x86.ActiveCfg = Debug|Any CPU
{80CA13E9-790A-4DC3-A45A-EDF6996D82D0}.DebugCore|x86.Build.0 = Debug|Any CPU
{80CA13E9-790A-4DC3-A45A-EDF6996D82D0}.Release|ARM64.ActiveCfg = Release|Any CPU
{80CA13E9-790A-4DC3-A45A-EDF6996D82D0}.Release|x64.ActiveCfg = Release|Any CPU
{80CA13E9-790A-4DC3-A45A-EDF6996D82D0}.Release|x64.Build.0 = Release|Any CPU
{80CA13E9-790A-4DC3-A45A-EDF6996D82D0}.Release|x86.ActiveCfg = Release|Any CPU
{80CA13E9-790A-4DC3-A45A-EDF6996D82D0}.Release|x86.Build.0 = Release|Any CPU
{80CA13E9-790A-4DC3-A45A-EDF6996D82D0}.ReleaseCore|ARM64.ActiveCfg = Release|Any CPU
{80CA13E9-790A-4DC3-A45A-EDF6996D82D0}.ReleaseCore|ARM64.Build.0 = Release|Any CPU
{80CA13E9-790A-4DC3-A45A-EDF6996D82D0}.ReleaseCore|x64.ActiveCfg = Release|Any CPU
{80CA13E9-790A-4DC3-A45A-EDF6996D82D0}.ReleaseCore|x64.Build.0 = Release|Any CPU
{80CA13E9-790A-4DC3-A45A-EDF6996D82D0}.ReleaseCore|x86.ActiveCfg = Release|Any CPU
{80CA13E9-790A-4DC3-A45A-EDF6996D82D0}.ReleaseCore|x86.Build.0 = Release|Any CPU
{F1ED9F1C-BC63-4FDF-84D4-6194228C9101}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{F1ED9F1C-BC63-4FDF-84D4-6194228C9101}.Debug|x64.ActiveCfg = Debug|Any CPU
{F1ED9F1C-BC63-4FDF-84D4-6194228C9101}.Debug|x64.Build.0 = Debug|Any CPU
Expand Down Expand Up @@ -281,7 +256,6 @@ Global
GlobalSection(NestedProjects) = preSolution
{0CC79A1A-463D-40BB-91E0-3B1391B519C6} = {7B4B080F-80E3-4907-87E4-8038F2470696}
{3A1D7085-4B6A-4D47-9FA6-B2A63CDD6595} = {7B4B080F-80E3-4907-87E4-8038F2470696}
{80CA13E9-790A-4DC3-A45A-EDF6996D82D0} = {7B4B080F-80E3-4907-87E4-8038F2470696}
{F1ED9F1C-BC63-4FDF-84D4-6194228C9101} = {27C2F39C-9D4A-41CC-8CE7-5B649A8D7036}
{3645E16F-6B5A-43D7-A81D-77E681E9A636} = {27C2F39C-9D4A-41CC-8CE7-5B649A8D7036}
EndGlobalSection
Expand Down
39 changes: 39 additions & 0 deletions src/SharpSvn/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<Project>

<Import Project="$(SolutionDir)SharpSvn.MSBuild\Errors2Enum.tasks" />

<PropertyGroup>
<WinErrorHeaderPath>$(KIT_SHARED_IncludePath)\winerror.h</WinErrorHeaderPath>
<ErrnoHeaderPath>$(KIT_SHARED_IncludePath)\..\ucrt\errno.h</ErrnoHeaderPath>
<AprErrnoHeaderPath>$(SolutionDir)..\imports\release\include\apr_errno.h</AprErrnoHeaderPath>
<SerfHeaderPath>$(SolutionDir)..\imports\release\include\serf-1\serf.h</SerfHeaderPath>
<LibSsh2HeaderPath>$(SolutionDir)..\imports\release\include\libssh2\libssh2.h</LibSsh2HeaderPath>
<ErrorsEnumFilePath>$(ProjectDir)\SvnWindowsError.h</ErrorsEnumFilePath>
</PropertyGroup>

<ItemGroup>
<GenerateErrorEnumsInputs Include="$(WinErrorHeaderPath)" />
<GenerateErrorEnumsInputs Include="$(ErrnoHeaderPath)" />
<GenerateErrorEnumsInputs Include="$(AprErrnoHeaderPath)" />
<GenerateErrorEnumsInputs Include="$(SerfHeaderPath)" />
</ItemGroup>

<Target Name="GenerateErrorEnums"
BeforeTargets="ClCompile"
Inputs="@(GenerateErrorEnumsInputs)"
Outputs="$(ErrorsEnumFilePath)">

<Errors2Enum WinErrorHeaderPath="$(WinErrorHeaderPath)"
ErrnoHeaderPath="$(ErrnoHeaderPath)"
AprErrnoHeaderPath="$(AprErrnoHeaderPath)"
SerfHeaderPath="$(SerfHeaderPath)"
LibSsh2HeaderPath="$(LibSsh2HeaderPath)"
OutputFilePath="$(ErrorsEnumFilePath)" />
</Target>

<Target Name="CleanErrorEnums"
BeforeTargets="CoreClean">
<Delete Files="$(ErrorsEnumFilePath)" />
</Target>

</Project>
Loading