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

simplify ifdef #1010

Merged
merged 2 commits into from
May 24, 2021
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Adjust parameter type in `AddBreadcrumb` to use `IReadOnlyDictionary<...>` instead of `Dictionary<...>` ([#1000](https://github.com/getsentry/sentry-dotnet/pull/1000))
- await dispose everywhere ([#1009](https://github.com/getsentry/sentry-dotnet/pull/1009))
- simplify ifdef ([#1010](https://github.com/getsentry/sentry-dotnet/pull/1010))

### Features

Expand Down
4 changes: 2 additions & 2 deletions src/Sentry/DefaultSentryScopeStateProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if HAS_VALUE_TUPLE
#if !NET461
using System;
#endif
using System.Collections.Generic;
Expand Down Expand Up @@ -38,7 +38,7 @@ public void Apply(Scope scope, object state)

break;
}
#if HAS_VALUE_TUPLE
#if !NET461
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: we can bring ValueTuple to .NET461 with: https://www.nuget.org/packages/System.ValueTuple/
This will remove the need for this if/defs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had that originally and it cause a WORLD of pain (binding redirects), so I removed it

case ValueTuple<string, string> tupleStringString:
if (!string.IsNullOrEmpty(tupleStringString.Item2))
{
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry/IHasBreadcrumbs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface IHasBreadcrumbs
/// </summary>
public static class HasBreadcrumbsExtensions
{
#if HAS_VALUE_TUPLE
#if !NET461
/// <summary>
/// Adds a breadcrumb to the object.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry/Integrations/NetFxInstallationsIntegration.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NETFX
#if NET461
using Sentry.PlatformAbstractions;

namespace Sentry.Integrations
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry/PlatformAbstractions/FrameworkInfo.NetFx.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NETFX
#if NET461
using System;
using System.Collections.Generic;
using Microsoft.Win32;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !NETFX
#if !NET461

using System.Collections.Generic;
using System.Linq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NETFX
#if NET461
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry/PlatformAbstractions/RegistryKeyExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NETFX
#if NET461
using Microsoft.Win32;

namespace Sentry.PlatformAbstractions
Expand Down
12 changes: 6 additions & 6 deletions src/Sentry/PlatformAbstractions/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Runtime
/// 4.7.2633.0
/// </example>
public string? Version { get; internal set; }
#if NETFX
#if NET461
/// <summary>
/// The .NET Framework installation which is running the process
/// </summary>
Expand All @@ -51,14 +51,14 @@ public class Runtime
public Runtime(
string? name = null,
string? version = null,
#if NETFX
#if NET461
FrameworkInstallation? frameworkInstallation = null,
#endif
#endif
string? raw = null)
{
Name = name;
Version = version;
#if NETFX
#if NET461
FrameworkInstallation = frameworkInstallation;
#endif
Raw = raw;
Expand Down Expand Up @@ -95,7 +95,7 @@ public bool Equals(Runtime other)
if (ReferenceEquals(this, other)) return true;
return string.Equals(Name, other.Name)
&& string.Equals(Version, other.Version)
#if NETFX
#if NET461
&& Equals(FrameworkInstallation, other.FrameworkInstallation)
#endif
&& string.Equals(Raw, other.Raw);
Expand Down Expand Up @@ -124,7 +124,7 @@ public override int GetHashCode()
{
var hashCode = Name != null ? Name.GetHashCode() : 0;
hashCode = (hashCode * 397) ^ (Version != null ? Version.GetHashCode() : 0);
#if NETFX
#if NET461
hashCode = (hashCode * 397) ^ (FrameworkInstallation != null ? FrameworkInstallation.GetHashCode() : 0);
#endif
hashCode = (hashCode * 397) ^ (Raw != null ? Raw.GetHashCode() : 0);
Expand Down
10 changes: 5 additions & 5 deletions src/Sentry/PlatformAbstractions/RuntimeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ internal static Runtime GetRuntime()

runtime ??= GetFromEnvironmentVariable();

#if NETFX
#if NET461
SetNetFxReleaseAndVersion(runtime);
#elif NETSTANDARD || NETCOREAPP // Possibly .NET Core
#else
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we had a bug here since NETCOREAPP was not defined in the csproj

SetNetCoreVersion(runtime);
#endif
return runtime;
Expand Down Expand Up @@ -52,7 +52,7 @@ internal static Runtime GetRuntime()
return new Runtime(name, raw: rawRuntimeDescription);
}

#if NETFX
#if NET461
internal static void SetNetFxReleaseAndVersion(Runtime runtime)
{
if (runtime?.IsNetFx() == true)
Expand All @@ -75,15 +75,15 @@ internal static void SetNetFxReleaseAndVersion(Runtime runtime)
}
#endif

#if NETSTANDARD || NETCOREAPP // Possibly .NET Core
#if !NET461
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here

// Known issue on Docker: https://github.com/dotnet/BenchmarkDotNet/issues/448#issuecomment-361027977
internal static void SetNetCoreVersion(Runtime runtime)
{
if (runtime.IsNetCore())
{
// https://github.com/dotnet/BenchmarkDotNet/issues/448#issuecomment-308424100
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
#if NET5_0 || NETCOREAPP3_0
#if NETCOREAPP3_0_OR_GREATER
var assemblyPath = assembly.Location.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
#else
var assemblyPath = assembly.CodeBase.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
Expand Down
12 changes: 0 additions & 12 deletions src/Sentry/Sentry.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,6 @@
</ItemGroup>
<!-- Ben.Demystifier -->

<PropertyGroup Condition="'$(TargetFramework)' != 'net461'">
<DefineConstants>$(DefineConstants);HAS_VALUE_TUPLE</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="$(TargetFramework.StartsWith('netstandard'))">
<DefineConstants>$(DefineConstants);NETSTANDARD</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net461'">
<DefineConstants>$(DefineConstants);NETFX</DefineConstants>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
<Reference Include="System.Net.Http" />
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry/SentryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ public SentryOptions()
new AppDomainUnhandledExceptionIntegration(),
new AppDomainProcessExitIntegration(),
new TaskUnobservedTaskExceptionIntegration(),
#if NETFX
#if NET461
new NetFxInstallationsIntegration(),
#endif
};
Expand Down
4 changes: 2 additions & 2 deletions src/Sentry/SentryOptionsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Sentry.Infrastructure;
using Sentry.Integrations;
using Sentry.Internal;
#if NETFX
#if NET461
using Sentry.PlatformAbstractions;
#endif

Expand Down Expand Up @@ -46,7 +46,7 @@ public static void DisableAppDomainUnhandledExceptionCapture(this SentryOptions
public static void DisableTaskUnobservedTaskExceptionCapture(this SentryOptions options) =>
options.RemoveIntegration<TaskUnobservedTaskExceptionIntegration>();

#if NETFX
#if NET461
/// <summary>
/// Disables the list addition of .Net Frameworks into events.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NETFX
#if NET461
using Sentry.Integrations;
using Sentry.PlatformAbstractions;
using Xunit;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NETFX
#if NET461
using Sentry.PlatformAbstractions;
using Xunit;
using System;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !NETFX
#if !NET461
using Sentry.PlatformAbstractions;
using Xunit;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NETFX
#if NET461
using Xunit;
using System.Collections.Generic;
using Sentry.PlatformAbstractions;
Expand Down
5 changes: 3 additions & 2 deletions test/Sentry.Tests/PlatformAbstractions/RuntimeInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void Parse_TestCases(ParseTestCase parseTestCase)
}
}

#if NETFX
#if NET461
[SkippableFact]
public void SetReleaseAndVersionNetFx_OnNetFx_NonNullReleaseAndVersion()
{
Expand All @@ -57,7 +57,7 @@ public void SetReleaseAndVersionNetFx_OnNetFx_NonNullReleaseAndVersion()
}
#endif

#if NETCOREAPP
#if NETCOREAPP2_1 || NETCOREAPP3_0
[Fact]
public void SetNetCoreVersion_NetCoreAsName()
{
Expand All @@ -69,6 +69,7 @@ public void SetNetCoreVersion_NetCoreAsName()
}
#endif

// TODO: Should be NET5_0_OR_GREATER which isn't available (to be added when NET6 lands)
#if NET5_0
[Fact]
public void SetNetCoreVersion_Net5Runtime_NullNetCoreVersion()
Expand Down
2 changes: 1 addition & 1 deletion test/Sentry.Tests/Protocol/ScopeExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ public void AddBreadcrumb_DropOldest()
Assert.Equal("5", sut.Breadcrumbs.Last().Message);
}

#if HAS_VALUE_TUPLE
#if !NET461
[Fact]
public void AddBreadcrumb_ValueTuple_AllArgumentsMatch()
{
Expand Down
4 changes: 0 additions & 4 deletions test/Sentry.Tests/Sentry.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
<TargetFrameworks>net5.0;netcoreapp3.1;netcoreapp3.0;netcoreapp2.1;net461</TargetFrameworks>
</PropertyGroup>

<PropertyGroup Condition="$(TargetFramework.StartsWith('net4'))">
<DefineConstants>NETFX;$(AdditionalConstants)</DefineConstants>
</PropertyGroup>

<!-- From Ben.Demystifier -->
<PropertyGroup Condition="'$(TargetFramework)' != 'netcoreapp2.1' and !$(TargetFramework.StartsWith('net4'))">
<DefineConstants>$(DefineConstants);HAS_ASYNC_ENUMERATOR</DefineConstants>
Expand Down
5 changes: 2 additions & 3 deletions test/Sentry.Tests/SentryOptionsExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
using Sentry.Extensibility;
using Sentry.Integrations;
using Sentry.Internal;
using Sentry.Testing;
#if NETFX
#if NET461
using Sentry.PlatformAbstractions;
#endif
using Xunit;
Expand All @@ -24,7 +23,7 @@ public void DisableDuplicateEventDetection_RemovesDisableDuplicateEventDetection
p => p.GetType() == typeof(DuplicateEventDetectionEventProcessor));
}

#if NETFX
#if NET461
[Fact]
public void DisableNetFxInstallationsEventProcessor_RemovesDisableNetFxInstallationsEventProcessorEventProcessor()
{
Expand Down
5 changes: 2 additions & 3 deletions test/Sentry.Tests/SentryOptionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.IO.Compression;
using System.Net;
#if NETFX
#if NET461
using Sentry.Internal;
using Sentry.PlatformAbstractions;
using Xunit.Sdk;
Expand All @@ -24,7 +23,7 @@ public void RequestBodyCompressionLevel_ByDefault_Optimal()
var sut = new SentryOptions();
Assert.Equal(CompressionLevel.Optimal, sut.RequestBodyCompressionLevel);
}
#if NETFX
#if NET461
[SkippableFact(typeof(IsTypeException))]
public void StackTraceFactory_RunningOnMono_HasMonoStackTraceFactory()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
#if RELEASE
using System.Threading;
#endif
using NSubstitute;
using Sentry.Integrations;
using Sentry.Internal;
Expand Down Expand Up @@ -43,15 +40,15 @@ public void Handle_WithException_CaptureEvent()
public void Handle_UnobservedTaskException_CaptureEvent()
{
_fixture.AppDomain = AppDomainAdapter.Instance;
var captureCalledEvent = new ManualResetEvent(false);
var captureCalledEvent = new System.Threading.ManualResetEvent(false);
_fixture.Hub.When(x => x.CaptureEvent(Arg.Any<SentryEvent>()))
.Do(_ => captureCalledEvent.Set());

var sut = _fixture.GetSut();
sut.Register(_fixture.Hub, SentryOptions);
try
{
var taskStartedEvent = new ManualResetEvent(false);
var taskStartedEvent = new System.Threading.ManualResetEvent(false);
_ = Task.Run(() =>
{
_ = taskStartedEvent.Set();
Expand Down