Nuke.Unreal
Build Unreal apps in Style.
Loading...
Searching...
No Matches
PlatformSdkManager.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Reflection;
5using Nuke.Cola.BuildPlugins;
6using Nuke.Common;
7using Nuke.Common.IO;
10
11namespace Nuke.Unreal.Platforms;
12
13using PlatformSdkCollection = Dictionary<(UnrealPlatform Host, UnrealPlatform Target), IPlatformSdk>;
14
15/// <summary>
16/// Static class managing <see cref="IPlatformSdk"/> implementations
17/// </summary>
18public static class PlatformSdkManager
19{
20 /// <summary>
21 /// A user folder to store SDK installation files owned by Nuke.Unreal.
22 /// </summary>
23 public static readonly AbsolutePath PlatformSdkRoot = AbsolutePath.Create(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData))
24 / "Nuke.Unreal" / "PlatformSdks"
25 ;
26
27 private static readonly PlatformSdkCollection Sdks = new();
28
29 /// <summary>
30 /// Get a platform SDK instance for the current host-platform and input target platform pair.
31 /// </summary>
32 /// <returns>
33 /// The platform SDK instance, or null. When null is returned then either extra platform SDK considerations are
34 /// not necessary for given platform combination (like Windows targeting Windows), or such an instance is not
35 /// yet implemented.
36 /// </returns>
37 public static IPlatformSdk? GetSdk(this UnrealPlatform platform)
38 => Sdks.TryGetValue((Unreal.GetHostPlatform(), platform), out var sdk) ? sdk : null
39 ;
40
41 internal static void RegisterSdks()
42 {
43 var platformSdks = new []
44 {
45 Assembly.GetEntryAssembly()!,
46 Assembly.GetExecutingAssembly()
47 }
48 .SelectMany(a => a.GetTypes())
49 .Distinct()
50 .Where(t =>
51 !t.IsAbstract
52 && t.GetInterfaces().Any(i => i.FullName == "Nuke.Unreal.Platforms.IPlatformSdk")
53 );
54 foreach (var platformSdkType in platformSdks)
55 {
56 var platformSdk = (IPlatformSdk) Activator.CreateInstance(platformSdkType)!;
57 Sdks[(platformSdk.Host, platformSdk.Target)] = platformSdk;
58 Console.WriteLine($"Registered SDK manager for {platformSdk.Target} on {platformSdk.Host} ({platformSdkType.Name})");
59 }
60 }
61}
Static class managing IPlatformSdk implementations.
static readonly AbsolutePath PlatformSdkRoot
A user folder to store SDK installation files owned by Nuke.Unreal.
static ? IPlatformSdk GetSdk(this UnrealPlatform platform)
Get a platform SDK instance for the current host-platform and input target platform pair.
High level representation of common platforms supported by Unreal Engine (NDA ones excluded) and extr...
A collection of utilities around basic functions regarding the environment of the Engine we're workin...
Definition Unreal.cs:24
static UnrealPlatform GetHostPlatform()
Get the current development platform Nuke.Unreal is ran on.
Base interface for implementing the automatic SDK management for a host-target platform pair.