Nuke.Unreal
Build Unreal apps in Style.
Loading...
Searching...
No Matches
LibraryGenerator.cs
1using System.Linq;
2using System;
3using System.IO;
4using Newtonsoft.Json;
5using Newtonsoft.Json.Linq;
6using Nuke.Common.IO;
7using Nuke.Common.Tooling;
8using System.ComponentModel;
9using Nuke.Cola;
10using System.Text.RegularExpressions;
12using System.Collections.Generic;
13using Humanizer;
14
16
17[TypeConverter(typeof(TypeConverter<LibraryType>))]
18[JsonConverter(typeof(EnumerationJsonConverter<LibraryType>))]
19public class LibraryType : Enumeration
20{
21 public static readonly LibraryType Header = new()
22 {
23 Value = nameof(Header),
24 TemplateSubfolder = "HeaderLibrary"
25 };
26
27 public static readonly LibraryType CMake = new()
28 {
29 Value = nameof(CMake),
30 TemplateSubfolder = "CMakeLibrary"
31 };
32
33 public static readonly LibraryType XRepo = new()
34 {
35 Value = nameof(XRepo),
36 TemplateSubfolder = "XRepoLibrary",
37 ParseSpec = XRepoLibrary.ParseSpec
38 };
39
40 public required string TemplateSubfolder { init; get; }
41 public Func<string, LibrarySpec> ParseSpec { get; private set; } = s => new LibrarySpec(s, s);
42}
43
44public record class LibrarySpec(
45 string Spec,
46 string Name,
47 string? Version = null,
48 string? Provider = null,
49 string? Options = null,
50 string? Features = null
51) {
52 public string UnrealName => Name
53 .Replace("-", "_")
54 .Replace(".", "_")
55 .Pascalize();
56}
57
58public record class SuffixRecord(string? Text, string? Us, string? Dot)
59{
60 public SuffixRecord(string? suffix) : this(suffix, suffix.PrependNonEmpty("_"), suffix.PrependNonEmpty(".")) {}
61}
62
63public record class LibraryModel(
64 LibrarySpec Spec,
65 string? Copyright,
66 SuffixRecord Suffix,
67 IEnumerable<UnrealPlatform> Platforms
68) : CommonModelBase(Spec.Name, Copyright);
69
71{
72 protected LibraryModel? Model;
73
74 public void Generate(UnrealBuild build, AbsolutePath templatesPath, AbsolutePath currentFolder, string fullSpec, LibraryType libraryType, string? suffix)
75 {
76 var project = new UnrealProject(build);
77 var spec = libraryType.ParseSpec(fullSpec);
78 Model = new(
79 Spec: spec,
80 Copyright: Unreal.ReadCopyrightFromProject(project.Folder!),
81 Suffix: new(suffix),
82 Platforms: UnrealPlatform.Platforms.Where(p => Unreal.Version(build).IsCompatibleWith(p.Compatibility))
83 );
84
85 if ((currentFolder / (spec.Name + Model.Suffix.Us)).DirectoryExists())
86 {
87 throw new InvalidOperationException($"The library module folder of {spec.Name} already exists in the current folder.");
88 }
89
90 if(!(templatesPath / libraryType.TemplateSubfolder).DirectoryExists())
91 templatesPath = DefaultTemplateFolder;
92
93 var templateDir = templatesPath / libraryType.TemplateSubfolder;
94
95 RenderFolder(templateDir, currentFolder, Model);
96 }
97}
bool IsCompatibleWith(UnrealCompatibility compatibility)
Check if given compatibility mask applies to this version too.
The main build class Unreal projects using Nuke.Unreal should inherit from. This class contains all b...
High level representation of common platforms supported by Unreal Engine (NDA ones excluded) and extr...
static readonly List< UnrealPlatform > Platforms
List of all "real" platforms.
A collection of utilities around basic functions regarding the environment of the Engine we're workin...
Definition Unreal.cs:24
static string ReadCopyrightFromProject(AbsolutePath projectFolder)
Read copyright info from the project's DefaultGame.ini
Definition Unreal.cs:321
static EngineVersion Version(UnrealBuild build)
Get high-level version of currently used Engine.