Skip to content

Commit

Permalink
automatically handle assembly redirection
Browse files Browse the repository at this point in the history
  • Loading branch information
Kielek committed Jul 25, 2023
1 parent 49ca5fb commit fc0fa43
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
14 changes: 13 additions & 1 deletion build/AssemblyRedirectionSourceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,15 @@ private static string GenerateSourceContents(SortedDictionary<string, AssemblyNa
#include "cor_profiler.h"

#ifdef _WIN32
#define STR(Z1) #Z1
#define AUTO_MAJOR STR(OTEL_AUTO_VERSION_MAJOR)

namespace trace
{
void CorProfiler::InitNetFxAssemblyRedirectsMap()
{
const USHORT auto_major = atoi(AUTO_MAJOR);

assembly_version_redirect_map_.insert({
{{GenerateEntries(assemblies)}}
});
Expand All @@ -73,7 +78,14 @@ private static string GenerateEntries(SortedDictionary<string, AssemblyNameDefin
foreach (var kvp in assemblies)
{
var v = kvp.Value.Version!;
sb.AppendLine($" {{ L\"{kvp.Key}\", {{{v.Major}, {v.Minor}, {v.Build}, {v.Revision}}} }},");
if(kvp.Key != "OpenTelemetry.AutoInstrumentation")
{
sb.AppendLine($" {{ L\"{kvp.Key}\", {{{v.Major}, {v.Minor}, {v.Build}, {v.Revision}}} }},");
}
else
{
sb.AppendLine($" {{ L\"{kvp.Key}\", {{auto_major, 0, 0, 0}} }},");
}
}

return sb.ToString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
<ConformanceMode>true</ConformanceMode>
<SDLCheck>true</SDLCheck>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<PreprocessorDefinitions>SPDLOG_COMPILED_LIB;SPDLOG_FMT_EXTERNAL;BIT64;HOST_64BIT;AMD64;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>SPDLOG_COMPILED_LIB;SPDLOG_FMT_EXTERNAL;BIT64;HOST_64BIT;AMD64;_UNICODE;UNICODE;OTEL_AUTO_VERSION_MAJOR=$(OTEL_AUTO_VERSION_MAJOR);OTEL_AUTO_VERSION_MINOR=$(OTEL_AUTO_VERSION_MINOR);OTEL_AUTO_VERSION_PATCH=$(OTEL_AUTO_VERSION_PATCH);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(LIB_INCLUDES);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
Expand All @@ -116,7 +116,7 @@
<ConformanceMode>true</ConformanceMode>
<SDLCheck>true</SDLCheck>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<PreprocessorDefinitions>SPDLOG_COMPILED_LIB;SPDLOG_FMT_EXTERNAL;_UNICODE;UNICODE;X86;HOST_X86;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>SPDLOG_COMPILED_LIB;SPDLOG_FMT_EXTERNAL;_UNICODE;UNICODE;X86;HOST_X86;OTEL_AUTO_VERSION_MAJOR=$(OTEL_AUTO_VERSION_MAJOR);OTEL_AUTO_VERSION_MINOR=$(OTEL_AUTO_VERSION_MINOR);OTEL_AUTO_VERSION_PATCH=$(OTEL_AUTO_VERSION_PATCH);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(LIB_INCLUDES);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
Expand All @@ -143,7 +143,7 @@
<ConformanceMode>true</ConformanceMode>
<SDLCheck>true</SDLCheck>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<PreprocessorDefinitions>SPDLOG_COMPILED_LIB;SPDLOG_FMT_EXTERNAL;_TARGET_64BIT;BIT64;HOST_64BIT;AMD64;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>SPDLOG_COMPILED_LIB;SPDLOG_FMT_EXTERNAL;_TARGET_64BIT;BIT64;HOST_64BIT;AMD64;_UNICODE;UNICODE;OTEL_AUTO_VERSION_MAJOR=$(OTEL_AUTO_VERSION_MAJOR);OTEL_AUTO_VERSION_MINOR=$(OTEL_AUTO_VERSION_MINOR);OTEL_AUTO_VERSION_PATCH=$(OTEL_AUTO_VERSION_PATCH);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(LIB_INCLUDES);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
Expand All @@ -169,7 +169,7 @@
<ConformanceMode>true</ConformanceMode>
<SDLCheck>true</SDLCheck>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<PreprocessorDefinitions>SPDLOG_COMPILED_LIB;SPDLOG_FMT_EXTERNAL;_UNICODE;UNICODE;X86;HOST_X86;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>SPDLOG_COMPILED_LIB;SPDLOG_FMT_EXTERNAL;_UNICODE;UNICODE;X86;HOST_X86;OTEL_AUTO_VERSION_MAJOR=$(OTEL_AUTO_VERSION_MAJOR);OTEL_AUTO_VERSION_MINOR=$(OTEL_AUTO_VERSION_MINOR);OTEL_AUTO_VERSION_PATCH=$(OTEL_AUTO_VERSION_PATCH);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(LIB_INCLUDES);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@
#include "cor_profiler.h"

#ifdef _WIN32
#define STR(Z1) #Z1
#define AUTO_MAJOR STR(OTEL_AUTO_VERSION_MAJOR)

namespace trace
{
void CorProfiler::InitNetFxAssemblyRedirectsMap()
{
const USHORT auto_major = atoi(AUTO_MAJOR);

assembly_version_redirect_map_.insert({
{ L"Google.Protobuf", {3, 23, 4, 0} },
{ L"Grpc.Core", {2, 0, 0, 0} },
Expand All @@ -33,7 +38,7 @@ void CorProfiler::InitNetFxAssemblyRedirectsMap()
{ L"OpenTelemetry", {1, 0, 0, 0} },
{ L"OpenTelemetry.Api", {1, 0, 0, 0} },
{ L"OpenTelemetry.Api.ProviderBuilderExtensions", {1, 0, 0, 0} },
{ L"OpenTelemetry.AutoInstrumentation", {1, 0, 0, 0} },
{ L"OpenTelemetry.AutoInstrumentation", {auto_major, 0, 0, 0} },
{ L"OpenTelemetry.Exporter.Console", {1, 0, 0, 0} },
{ L"OpenTelemetry.Exporter.OpenTelemetryProtocol", {1, 0, 0, 0} },
{ L"OpenTelemetry.Exporter.Prometheus.HttpListener", {1, 0, 0, 0} },
Expand Down
4 changes: 2 additions & 2 deletions src/OpenTelemetry.AutoInstrumentation.Native/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#define STRTMP4(V1, V2, V3, V4) #V1 "." #V2 "." #V3 "." #V4
#define STR4(V1, V2, V3, V4) STRTMP4(V1, V2, V3, V4)
#define VERSION_3PARTS STR3(OTEL_AUTO_VERSION_MAJOR, OTEL_AUTO_VERSION_MINOR, OTEL_AUTO_VERSION_PATCH)
#define VERSION_4PARTS STR4(OTEL_AUTO_VERSION_MAJOR, OTEL_AUTO_VERSION_MINOR, OTEL_AUTO_VERSION_PATCH, 0)
#define VERSION_4PARTS STR4(OTEL_AUTO_VERSION_MAJOR, 0, 0, 0)

const auto PROFILER_VERSION = VERSION_3PARTS;
const auto FILE_VERSION = VERSION_4PARTS;
const auto FILE_VERSION = VERSION_4PARTS;

0 comments on commit fc0fa43

Please sign in to comment.