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 cd0bd79
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 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
2 changes: 1 addition & 1 deletion src/OpenTelemetry.AutoInstrumentation.Native/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
#define VERSION_4PARTS STR4(OTEL_AUTO_VERSION_MAJOR, OTEL_AUTO_VERSION_MINOR, OTEL_AUTO_VERSION_PATCH, 0)

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

0 comments on commit cd0bd79

Please sign in to comment.