Skip to content

Commit

Permalink
Add #if _WIN32 clauses for windows only definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-romano-DD committed Nov 11, 2024
1 parent 17bc420 commit 86827a9
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 11 deletions.
17 changes: 15 additions & 2 deletions tracer/build/_build/CodeGenerators/CallSitesGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ static string GetArgument(Mono.Cecil.CustomAttributeArgument customAttributeArgu
internal static void GenerateFile(Dictionary<string, AspectClass> aspectClasses, AbsolutePath outputPath)
{
var sb = new StringBuilder();
bool inWin32Section = false;
sb.AppendLine("""
// <copyright company="Datadog">
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
Expand All @@ -260,7 +261,19 @@ namespace trace

foreach (var method in aspectClass.Value.Aspects.OrderBy(static k => k.Key.ToString(), StringComparer.OrdinalIgnoreCase))
{
sb.AppendLine(Format(" " + method.Key + method.Value.Subfix()));
bool win32Only = method.Value.Tfms.IsNetFxOnly();
if (win32Only && !inWin32Section)
{
inWin32Section = true;
sb.AppendLine("#if _WIN32");
}
else if (!win32Only && inWin32Section)
{
inWin32Section = false;
sb.AppendLine("#endif");
}

sb.AppendLine(Format(" " + method.Key + method.Value.Suffix()));
}
}

Expand Down Expand Up @@ -306,7 +319,7 @@ public Aspect() { }

public TargetFrameworks Tfms = TargetFrameworks.None;

public string Subfix()
public string Suffix()
{
return $" {((long)Tfms).ToString()}";
}
Expand Down
22 changes: 13 additions & 9 deletions tracer/build/_build/CodeGenerators/CallTargetsGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ namespace trace


//Write all CallTargets
bool inWin32Section = false;
sb.AppendLine();
sb.AppendLine("std::vector<CallTargetDefinition3> g_callTargets=");
sb.AppendLine("{");
Expand All @@ -484,6 +485,18 @@ namespace trace
.ThenBy(static x => x.Key.TargetTypeName)
.ThenBy(static x => x.Key.TargetMethodName))
{
bool win32Only = definition.Value.IsNetFxOnly();
if (win32Only && !inWin32Section)
{
inWin32Section = true;
sb.AppendLine("#if _WIN32");
}
else if (!win32Only && inWin32Section)
{
inWin32Section = false;
sb.AppendLine("#endif");
}

sb.AppendLine(GetCallTarget(definition.Key, signatures[GetSignature(definition.Key)], definition.Value, x++));
}

Expand Down Expand Up @@ -535,14 +548,6 @@ static string GetCallTarget(CallTargetDefinitionSource definition, string signat

static string GetCallTargetKind(int kind)
{
/*
enum class CallTargetKind : UINT8
{
Default = 0,
Derived = 1,
Interface = 2
};
*/
return kind switch
{
0 => "CallTargetKind::Default",
Expand Down Expand Up @@ -575,7 +580,6 @@ internal static void GenerateJsonFile(Dictionary<CallTargetDefinitionSource, Tar
Serilog.Log.Information("CallTarget definitions File saved: {File}", fileName);
}


internal static TargetFrameworks GetCategory(TargetFramework tfm)
{
return (TargetFrameworks)Enum.Parse<TargetFrameworks>(tfm.ToString().ToUpper().Replace('.', '_'));
Expand Down
9 changes: 9 additions & 0 deletions tracer/build/_build/CodeGenerators/TargetFrameworks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,12 @@ internal enum TargetFrameworks : uint
NET7_0 = 256,
NET8_0 = 512
}


internal static class TargetFrameworksExtensions
{
public static bool IsNetFxOnly(this TargetFrameworks tfm)
{
return ((uint)(tfm & (~(TargetFrameworks.NET461 | TargetFrameworks.NET462)))) == 0;
}
}
Loading

0 comments on commit 86827a9

Please sign in to comment.