Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[APM] Exclude windows only definitions from non windows dlls #6270

Open
wants to merge 3 commits into
base: dani/apm/NativeCallTargets
Choose a base branch
from
Open
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
23 changes: 21 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,25 @@ 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()));
}

if (inWin32Section)
{
inWin32Section = false;
sb.AppendLine("#endif");
}
}

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

public TargetFrameworks Tfms = TargetFrameworks.None;

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


//Write all CallTargets
bool inWin32Section = false;
sb.AppendLine();
sb.AppendLine("std::vector<CallTargetDefinition3> g_callTargets=");
sb.AppendLine("{");
Expand All @@ -485,9 +486,27 @@ 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++));
}

if (inWin32Section)
{
inWin32Section = false;
sb.AppendLine("#endif");
}

sb.AppendLine("""
};
}
Expand Down Expand Up @@ -536,14 +555,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 @@ -576,7 +587,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 @@ -27,3 +27,12 @@ internal enum TargetFrameworks : uint
NET8_0 = 512,
NET0_0 = 1024,
}


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