Skip to content

Commit d54b531

Browse files
authored
fix: merge ppy upstream, fix iOS build error, fix trimming/AOT warnings
- Merge ppy/osu commit 45234b5 (add beatmap difficulty before mods as context for score multiplier calculations) - Fix iOS build error: remove ServerGarbageCollection/ConcurrentGarbageCollection from iOS dotnet publish step (not supported by .NET for iOS) - Add [DynamicallyAccessedMembers] annotations to SettingSourceAttribute: declaringType param, SettingControlType property - Add [RequiresUnreferencedCode] to SettingSourceAttribute extension methods: CreateSettingsControls, GetSettingsSourceProperties, GetOrderedSettingsSourceProperties, GetUnderlyingSettingValue - Add [RequiresUnreferencedCode] to BindableValueAccessor.GetValue/SetValue - Add [RequiresUnreferencedCode] to SnakeCaseKeyContractResolver class - Fix Assembly.Location → AppContext.BaseDirectory in Icons.cs, MacOSAppLocationChecker.cs, WindowsAssociationManager.cs - Add [RequiresUnreferencedCode] to LegacyTcpIpcProvider class - Add [RequiresUnreferencedCode] to DiscordRichPresence class - Add [RequiresAssemblyFiles] to WindowsKey.Disable() - Add #pragma warning disable IL2026 around AsQueryable() in DatabasedKeyBindingContainer.LoadComplete() - Add [RequiresUnreferencedCode] to BackgroundDataStoreProcessor processScoresWithMissingStatistics() and LoadComplete()
1 parent a45b4fe commit d54b531

12 files changed

Lines changed: 30 additions & 10 deletions

File tree

.github/workflows/release.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,6 @@ jobs:
598598
-p:BuildIpa=false
599599
-p:CodesignKey=""
600600
-p:CodesignProvision=""
601-
-p:ServerGarbageCollection=true
602-
-p:ConcurrentGarbageCollection=true
603601
604602
- name: Package iOS build
605603
run: |

osu.Desktop/DiscordRichPresence.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// See the LICENCE file in the repository root for full licence text.
33

44
using System;
5+
using System.Diagnostics.CodeAnalysis;
56
using System.Text;
67
using DiscordRPC;
78
using DiscordRPC.Message;
@@ -27,6 +28,7 @@
2728

2829
namespace osu.Desktop
2930
{
31+
[RequiresUnreferencedCode("Newtonsoft.Json relies on reflection over types that may be removed when trimming.")]
3032
internal partial class DiscordRichPresence : Component
3133
{
3234
private const string client_id = "1216669957799018608";

osu.Desktop/LegacyIpc/LegacyTcpIpcProvider.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// See the LICENCE file in the repository root for full licence text.
33

44
using System;
5+
using System.Diagnostics.CodeAnalysis;
56
using System.Linq;
67
using Newtonsoft.Json.Linq;
78
using osu.Framework.Logging;
@@ -20,6 +21,7 @@ namespace osu.Desktop.LegacyIpc
2021
/// <summary>
2122
/// Provides IPC to legacy osu! clients.
2223
/// </summary>
24+
[RequiresUnreferencedCode("Newtonsoft.Json relies on reflection over types that may be removed when trimming.")]
2325
public class LegacyTcpIpcProvider : TcpIpcProvider
2426
{
2527
private static readonly Logger logger = Logger.GetLogger("legacy-ipc");

osu.Desktop/MacOS/MacOSAppLocationChecker.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System;
55
using System.IO;
6-
using osu.Framework;
76
using osu.Framework.Allocation;
87
using osu.Framework.Graphics;
98
using osu.Framework.Graphics.Sprites;
@@ -26,7 +25,7 @@ protected override void LoadComplete()
2625
{
2726
base.LoadComplete();
2827

29-
string assemblyPath = RuntimeInfo.EntryAssembly.Location;
28+
string assemblyPath = AppContext.BaseDirectory;
3029

3130
bool inRootApp = assemblyPath.StartsWith("/Applications/", StringComparison.Ordinal);
3231
bool inUserApp = assemblyPath.StartsWith(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Applications/"), StringComparison.Ordinal);

osu.Desktop/Windows/Icons.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
22
// See the LICENCE file in the repository root for full licence text.
33

4+
using System;
45
using System.IO;
56

67
namespace osu.Desktop.Windows
@@ -10,7 +11,7 @@ public static class Icons
1011
/// <summary>
1112
/// Fully qualified path to the directory that contains icons (in the installation folder).
1213
/// </summary>
13-
private static readonly string icon_directory = Path.GetDirectoryName(typeof(Icons).Assembly.Location)!;
14+
private static readonly string icon_directory = AppContext.BaseDirectory;
1415

1516
public static string Lazer => Path.Join(icon_directory, "lazer.ico");
1617

osu.Desktop/Windows/WindowsAssociationManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static class WindowsAssociationManager
3131
/// </summary>
3232
internal const string SHELL_OPEN_COMMAND = @"Shell\Open\Command";
3333

34-
private static readonly string exe_path = Path.ChangeExtension(typeof(WindowsAssociationManager).Assembly.Location, ".exe").Replace('/', '\\');
34+
private static readonly string exe_path = Path.Combine(AppContext.BaseDirectory, Path.ChangeExtension(AppDomain.CurrentDomain.FriendlyName, ".exe")).Replace('/', '\\');
3535

3636
/// <summary>
3737
/// Program ID prefix used for file associations. Should be relatively short since the full program ID has a 39 character limit,

osu.Desktop/Windows/WindowsKey.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// See the LICENCE file in the repository root for full licence text.
33

44
using System;
5+
using System.Diagnostics.CodeAnalysis;
56
using System.Runtime.InteropServices;
67

78
// ReSharper disable IdentifierTypo
@@ -47,6 +48,7 @@ private static int lowLevelKeyboardProc(int nCode, int wParam, ref KdDllHookStru
4748
return callNextHookEx(0, nCode, wParam, ref lParam);
4849
}
4950

51+
[RequiresAssemblyFiles("Uses Marshal.GetHINSTANCE which requires the assembly to be loaded from disk.")]
5052
internal static void Disable()
5153
{
5254
if (keyHook != IntPtr.Zero || isBlocked)

osu.Game/Configuration/SettingSourceAttribute.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Collections.Concurrent;
66
using System.Collections.Generic;
7+
using System.Diagnostics.CodeAnalysis;
78
using System.Linq;
89
using System.Reflection;
910
using JetBrains.Annotations;
@@ -42,9 +43,10 @@ public class SettingSourceAttribute : Attribute, IComparable<SettingSourceAttrib
4243
/// <remarks>
4344
/// Must be a type deriving <see cref="SettingsItem{T}"/> with a public parameterless constructor.
4445
/// </remarks>
46+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
4547
public Type? SettingControlType { get; set; }
4648

47-
public SettingSourceAttribute(Type declaringType, string label, string? description = null)
49+
public SettingSourceAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type declaringType, string label, string? description = null)
4850
{
4951
Label = getLocalisableStringFromMember(label) ?? string.Empty;
5052
Description = getLocalisableStringFromMember(description) ?? string.Empty;
@@ -109,6 +111,7 @@ public int CompareTo(SettingSourceAttribute? other)
109111

110112
public static partial class SettingSourceExtensions
111113
{
114+
[RequiresUnreferencedCode("SettingSourceAttribute uses reflection to instantiate settings controls and may not be compatible with trimming.")]
112115
public static IEnumerable<Drawable> CreateSettingsControls(this object obj)
113116
{
114117
foreach (var (attr, property) in obj.GetOrderedSettingsSourceProperties())
@@ -222,6 +225,7 @@ public static IEnumerable<Drawable> CreateSettingsControls(this object obj)
222225
/// Can be used for serialization and equality comparison purposes.
223226
/// </summary>
224227
/// <param name="setting">A <see cref="SettingSourceAttribute"/> bindable.</param>
228+
[RequiresUnreferencedCode("Uses BindableValueAccessor which relies on reflection and may not be compatible with trimming.")]
225229
public static object GetUnderlyingSettingValue(this object setting)
226230
{
227231
switch (setting)
@@ -250,6 +254,7 @@ public static object GetUnderlyingSettingValue(this object setting)
250254
}
251255
}
252256

257+
[RequiresUnreferencedCode("SettingSourceAttribute uses reflection to retrieve properties and may not be compatible with trimming.")]
253258
public static IEnumerable<(SettingSourceAttribute, PropertyInfo)> GetSettingsSourceProperties(this object obj)
254259
{
255260
var type = obj.GetType();
@@ -260,7 +265,7 @@ public static object GetUnderlyingSettingValue(this object setting)
260265
return properties;
261266
}
262267

263-
private static IEnumerable<(SettingSourceAttribute, PropertyInfo)> getSettingsSourceProperties(Type type)
268+
private static IEnumerable<(SettingSourceAttribute, PropertyInfo)> getSettingsSourceProperties([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] Type type)
264269
{
265270
foreach (var property in type.GetProperties(BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance))
266271
{
@@ -273,6 +278,7 @@ public static object GetUnderlyingSettingValue(this object setting)
273278
}
274279
}
275280

281+
[RequiresUnreferencedCode("SettingSourceAttribute uses reflection to retrieve properties and may not be compatible with trimming.")]
276282
public static ICollection<(SettingSourceAttribute, PropertyInfo)> GetOrderedSettingsSourceProperties(this object obj)
277283
=> obj.GetSettingsSourceProperties()
278284
.OrderBy(attr => attr.Item1)

osu.Game/Database/BackgroundDataStoreProcessor.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Diagnostics;
7+
using System.Diagnostics.CodeAnalysis;
78
using System.Globalization;
89
using System.Linq;
910
using System.Threading;
@@ -77,8 +78,8 @@ public partial class BackgroundDataStoreProcessor : Component
7778

7879
protected virtual int TimeToSleepDuringGameplay => 30000;
7980

80-
protected override void LoadComplete()
81-
{
81+
[RequiresUnreferencedCode("Calls processScoresWithMissingStatistics which uses Newtonsoft.Json reflection.")]
82+
protected override void LoadComplete() {
8283
base.LoadComplete();
8384

8485
localMetadataSource = new LocalCachedBeatmapMetadataSource(storage);
@@ -345,6 +346,7 @@ private void processBeatmapsWithMissingObjectCounts()
345346
completeNotification(notification, processedCount, beatmapIds.Count, failedCount);
346347
}
347348

349+
[RequiresUnreferencedCode("Newtonsoft.Json relies on reflection over types that may be removed when trimming.")]
348350
private void processScoresWithMissingStatistics()
349351
{
350352
HashSet<Guid> scoreIds = new HashSet<Guid>();

osu.Game/IO/Serialization/SnakeCaseKeyContractResolver.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
22
// See the LICENCE file in the repository root for full licence text.
33

4+
using System.Diagnostics.CodeAnalysis;
45
using Newtonsoft.Json.Serialization;
56
using osu.Game.Extensions;
67

78
namespace osu.Game.IO.Serialization
89
{
10+
[RequiresUnreferencedCode("Newtonsoft.Json relies on reflection over types that may be removed when trimming.")]
911
public class SnakeCaseKeyContractResolver : DefaultContractResolver
1012
{
1113
protected override string ResolvePropertyName(string propertyName)

0 commit comments

Comments
 (0)