Nuke.Unreal
Build Unreal apps in Style.
Loading...
Searching...
No Matches
XRepoUtils.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Threading.Tasks;
5using Nuke.Common.Utilities.Collections;
6
8
9public static class XRepoUtils
10{
11 public static string ToCorrectString(this XRepoArch arch) => arch.ToString().Replace("__", "-");
12
13 public static XRepoArch GetArch(string from) => Enum.Parse<XRepoArch>(from.Replace("-", "__"));
14
15 public static XRepoArch GetDefaultArch(this XRepoPlatform xrepoPlatform)
16 => xrepoPlatform switch
17 {
18 XRepoPlatform.android => XRepoArch.arm64__v8a,
19 XRepoPlatform.appletvos => XRepoArch.arm64,
20 XRepoPlatform.applexros => XRepoArch.arm64,
21 XRepoPlatform.bsd => XRepoArch.x86_64,
22 XRepoPlatform.cygwin => XRepoArch.x86_64,
23 XRepoPlatform.haiku => XRepoArch.x86_64,
24 XRepoPlatform.harmony => XRepoArch.arm64__v8a,
25 XRepoPlatform.iphoneos => XRepoArch.arm64,
26 XRepoPlatform.linux => XRepoArch.x86_64,
27 XRepoPlatform.macos => XRepoArch.arm64,
28 XRepoPlatform.mingw => XRepoArch.x86_64,
29 XRepoPlatform.msys => XRepoArch.x86_64,
30 XRepoPlatform.wasm => XRepoArch.wasm32,
31 XRepoPlatform.watchos => XRepoArch.armv7k,
32 XRepoPlatform.windows => XRepoArch.x64,
33 _ => XRepoArch.x86_64,
34 };
35
36 public static UnrealPlatform? InferUnrealPlatform(this XRepoPlatform xrepoPlatform)
37 => xrepoPlatform switch
38 {
39 XRepoPlatform.windows => UnrealPlatform.Win64,
40 XRepoPlatform.macos => UnrealPlatform.Mac,
41 XRepoPlatform.linux => UnrealPlatform.Linux,
42 XRepoPlatform.android => UnrealPlatform.Android,
43 XRepoPlatform.iphoneos => UnrealPlatform.IOS,
44 XRepoPlatform.appletvos => UnrealPlatform.TVOS,
45 XRepoPlatform.applexros => UnrealPlatform.VisionOS,
46 _ => null
47 };
48
49 public static UnrealPlatform? GetUnrealPlatform(this XRepoPlatformArch xrepoPlatform)
50 => xrepoPlatform switch
51 {
52 { Platform: XRepoPlatform.windows, Arch: XRepoArch.x64 } => UnrealPlatform.Win64,
53 { Platform: XRepoPlatform.windows, Arch: XRepoArch.x86_64 } => UnrealPlatform.Win64,
54 { Platform: XRepoPlatform.windows, Arch: XRepoArch.x86 } => UnrealPlatform.Win32,
55 // TODO: Windows ARM64?
56
57 { Platform: XRepoPlatform.linux, Arch: XRepoArch.x64 } => UnrealPlatform.Linux,
58 { Platform: XRepoPlatform.linux, Arch: XRepoArch.x86_64 } => UnrealPlatform.Linux,
59 { Platform: XRepoPlatform.linux, Arch: XRepoArch.arm64 } => UnrealPlatform.LinuxArm64,
60 { Platform: XRepoPlatform.linux, Arch: XRepoArch.arm64__v8a } => UnrealPlatform.LinuxArm64,
61 { Platform: XRepoPlatform.linux, Arch: XRepoArch.arm64ec } => UnrealPlatform.LinuxArm64,
62
63 { Platform: XRepoPlatform.android } => UnrealPlatform.Android,
64
65 { Platform: XRepoPlatform.macos } => UnrealPlatform.Mac,
66 { Platform: XRepoPlatform.iphoneos } => UnrealPlatform.IOS,
67 { Platform: XRepoPlatform.appletvos } => UnrealPlatform.TVOS,
68 { Platform: XRepoPlatform.applexros } => UnrealPlatform.VisionOS,
69
70 _ => null
71 };
72
73 public static XRepoPlatformArch GetXRepoPlatformArch(this UnrealPlatform platform)
74 {
75 if (platform == UnrealPlatform.Win64) return new(XRepoPlatform.windows, XRepoArch.x64);
76 if (platform == UnrealPlatform.Win32) return new(XRepoPlatform.windows, XRepoArch.x86);
77 if (platform == UnrealPlatform.Linux) return new(XRepoPlatform.linux, XRepoArch.x86_64);
78 if (platform == UnrealPlatform.LinuxArm64) return new(XRepoPlatform.linux, XRepoArch.arm64);
79 if (platform == UnrealPlatform.Android) return new(XRepoPlatform.android, XRepoPlatform.android.GetDefaultArch());
80 if (platform == UnrealPlatform.Mac) return new(XRepoPlatform.macos, XRepoPlatform.macos.GetDefaultArch());
81 if (platform == UnrealPlatform.IOS) return new(XRepoPlatform.iphoneos, XRepoPlatform.iphoneos.GetDefaultArch());
82 if (platform == UnrealPlatform.TVOS) return new(XRepoPlatform.appletvos, XRepoPlatform.appletvos.GetDefaultArch());
83 if (platform == UnrealPlatform.VisionOS) return new(XRepoPlatform.applexros, XRepoPlatform.applexros.GetDefaultArch());
84 throw new Exception($"{platform} platform was invalid.");
85 }
86
87 public static IEnumerable<UnrealPlatform> ParseSupportedPlatforms(string xrepoPlatforms, string arch)
88 => xrepoPlatforms switch
89 {
90 "all" => [
93 UnrealPlatform.Linux,
94 UnrealPlatform.LinuxArm64,
95 UnrealPlatform.Android,
97 UnrealPlatform.TVOS,
98 UnrealPlatform.VisionOS,
99 ],
100 _ => xrepoPlatforms.Split(',')
101 .Select(p => new XRepoPlatformArch(p.Trim(), arch).GetUnrealPlatform())
102 .WhereNotNull()
103 .Select(p => p!)
104 };
105}
High level representation of common platforms supported by Unreal Engine (NDA ones excluded) and extr...
static readonly UnrealPlatform Win64
Any platform name containing 'Windows' is also mapped to this platform.
static readonly UnrealPlatform Mac
Any platform name containing 'Mac' is also mapped to this platform.