blob: 75beac8807cd0510f42b800fb93be0240f9767e7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
# =============================================================================
# ProjT Launcher - CI Utility Functions
# =============================================================================
# Helper functions for build configuration analysis and comparison.
# =============================================================================
{ lib, ... }:
rec {
# Get unique strings from a list
uniqueStrings = list: builtins.attrNames (builtins.groupBy lib.id list);
# =============================================================================
# File Path Analysis
# =============================================================================
# Get the category of a file based on its path
getFileCategory =
filePath:
if lib.hasPrefix "launcher/ui/" filePath then
"ui"
else if lib.hasPrefix "launcher/qtquick/" filePath then
"ui"
else if lib.hasPrefix "launcher/minecraft/" filePath then
"minecraft"
else if lib.hasPrefix "launcher/modplatform/" filePath then
"modplatform"
else if lib.hasPrefix "launcher/java/" filePath then
"java"
else if lib.hasPrefix "launcher/net/" filePath then
"networking"
else if lib.hasPrefix "launcher/" filePath then
"core"
else if lib.hasPrefix "cmake/" filePath then
"build"
else if lib.hasSuffix "CMakeLists.txt" filePath then
"build"
else if lib.hasPrefix "translations/" filePath then
"translations"
else if lib.hasPrefix "docs/" filePath then
"documentation"
else if lib.hasPrefix ".github/" filePath then
"ci"
else if lib.hasPrefix "ci/" filePath then
"ci"
else
"other";
# Get platform from file path if applicable
getPlatformFromPath =
filePath:
if lib.hasInfix "linux" filePath then
"linux"
else if lib.hasInfix "darwin" filePath || lib.hasInfix "macos" filePath then
"macos"
else if lib.hasInfix "windows" filePath || lib.hasInfix "win32" filePath then
"windows"
else
null;
# =============================================================================
# Change Classification
# =============================================================================
# Classify changed files by category
classifyChanges =
changedFiles:
let
categorized = map (f: {
file = f;
category = getFileCategory f;
platform = getPlatformFromPath f;
}) changedFiles;
in
lib.groupBy (c: c.category) categorized;
# =============================================================================
# Build Impact Analysis
# =============================================================================
# Determine if a file change requires rebuild
requiresRebuild =
filePath:
let
category = getFileCategory filePath;
in
builtins.elem category [
"core"
"ui"
"minecraft"
"modplatform"
"java"
"networking"
"libraries"
"build"
];
# Get list of files that require rebuild
getFilesRequiringRebuild = changedFiles: builtins.filter requiresRebuild changedFiles;
# =============================================================================
# Platform Analysis
# =============================================================================
# Group changes by affected platform
groupByPlatform =
changes:
let
platformChanges = map (c: {
inherit (c) file category;
platform = c.platform or "all";
}) changes;
in
lib.groupBy (c: c.platform) platformChanges;
# =============================================================================
# Label Generation
# =============================================================================
# Generate labels based on changes
getLabels =
classifiedChanges:
let
categories = builtins.attrNames classifiedChanges;
categoryLabels = map (cat: "category:${cat}") categories;
rebuildCount = builtins.length (
builtins.filter (c: requiresRebuild c.file) (lib.flatten (builtins.attrValues classifiedChanges))
);
rebuildLabels =
if rebuildCount == 0 then
[ ]
else if rebuildCount <= 10 then
[ "rebuild:small" ]
else if rebuildCount <= 50 then
[ "rebuild:medium" ]
else
[ "rebuild:large" ];
in
lib.listToAttrs (
map (l: {
name = l;
value = true;
}) (categoryLabels ++ rebuildLabels)
);
# =============================================================================
# Component Analysis
# =============================================================================
# Extract affected components from file paths
extractComponents =
changedFiles:
let
components = map (
f:
let
parts = lib.splitString "/" f;
in
if builtins.length parts >= 2 then builtins.elemAt parts 1 else null
) changedFiles;
in
uniqueStrings (builtins.filter (c: c != null) components);
# Check if core functionality is affected
isCoreAffected =
changedFiles:
builtins.any (
f:
lib.hasPrefix "launcher/Application" f
|| lib.hasPrefix "launcher/BaseInstance" f
|| lib.hasPrefix "launcher/FileSystem" f
) changedFiles;
# =============================================================================
# Summary Generation
# =============================================================================
# Generate change summary
generateSummary =
changedFiles:
let
classified = classifyChanges changedFiles;
components = extractComponents changedFiles;
rebuildsNeeded = getFilesRequiringRebuild changedFiles;
in
{
totalFiles = builtins.length changedFiles;
categories = builtins.attrNames classified;
categoryCount = lib.mapAttrs (_: v: builtins.length v) classified;
inherit components;
rebuildRequired = builtins.length rebuildsNeeded > 0;
rebuildCount = builtins.length rebuildsNeeded;
coreAffected = isCoreAffected changedFiles;
labels = getLabels classified;
};
}
|