generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
flake.nix
374 lines (357 loc) · 18.2 KB
/
flake.nix
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
{
description = "UI Surveyor plugin for Idea IDE";
inputs = {
nixpkgs = {
url = "nixpkgs/release-23.11";
};
nixpkgsForSwift = {
url = "nixpkgs/007ccf2f4f1da567903ae392cbf19966eb30cf20";
};
gitignore = {
url = "github:hercules-ci/gitignore.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
ipredicateKt.url = "path:./ipredicate";
flake-parts.url = "github:hercules-ci/flake-parts";
# For ipredicate:
gnuStepBaseSrc = {
url = "github:gnustep/libs-base/cc38f2f4a1ce2d3f0a5f478ead595d2b011ecf41";
flake = false;
};
webDriverAgentSrc = {
url = "github:appium/WebDriverAgent/v3.16.0";
flake = false;
};
# For thirdparty/objc2swift:
objc2swift-src = {
url = "github:okaxaki/objc2swift/ee82a541de19e075f197abf307082a19bdfac7c6";
flake = false;
};
# For thirdparty/gryphon:
gryphon-src = {
url = "github:vinivendra/Gryphon/v0.18.1";
flake = false;
};
};
outputs = inputs@{ flake-parts, gitignore, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
# To import a flake module
# 1. Add foo to inputs
# 2. Add foo as a parameter to the outputs function
# 3. Add here: foo.flakeModule
./ipredicate/flake-module.nix
];
debug = true;
systems = [ "x86_64-linux" ]; # TODO
flake = {
# TODO: extract to a helper instead of copy-paste
generateVerificationMetadata = let
lib = inputs.nixpkgs.lib;
in let
gradleUrls = builtins.filter
(x: x != "")
(lib.strings.splitString "\n" (builtins.readFile ./artifacts.lst));
gradleArtifacts =
(builtins.concatMap
(componentPart:
(builtins.map
(artifactPart:
rec {
group = builtins.elemAt componentPart 0;
name = builtins.elemAt componentPart 1;
version = builtins.elemAt componentPart 2;
file = builtins.elemAt artifactPart 0;
path = (
(builtins.replaceStrings ["."] ["/"] group) +
"/" +
name +
"/" +
version +
"/" +
file
);
sha256 = builtins.elemAt artifactPart 1;
origin = builtins.elemAt artifactPart 2;
}
)
(builtins.filter
(x: builtins.isList x)
(builtins.split
''<artifact[[:space:]]+name="([^"]+)">[^<]+<sha256[[:space:]]+value="([^"]+)"[[:space:]]+origin="([^"]+)"''
(builtins.elemAt componentPart 3)
)
)
)
)
(builtins.filter
(x: builtins.isList x)
(builtins.split
''<component[[:space:]]+group="([^"]+)"[[:space:]]+name="([^"]+)"[[:space:]]+version="([^"]+)">(([^<]+</?(artifact|sha256))+)''
(builtins.readFile ./gradle/verification-metadata.xml)
)
)
);
in let
# TODO: Sort in the same way Gradle does
# TODO: Remove duplicate entries
# TODO: Copy okio-2.4.3.jar metadata as okio-jvm-2.4.3.jar metadata
# TODO: Calculate hashes for libraries extracted for IDE zips
verificationList = (builtins.map
(artifacts: let
firstArtifact = builtins.elemAt artifacts 0;
artifactString = builtins.concatStringsSep
"\n"
(builtins.map
(artifact:
''
${""} <artifact name="${artifact.file}">
${""} <sha256 value="${artifact.sha256}" origin="${artifact.origin}"/>
${""} </artifact>''
)
artifacts
);
in # This set should match function in first argument of the groupBy below
''
${""} <component group="${firstArtifact.group}" name="${firstArtifact.name}" version="${firstArtifact.version}">
${artifactString}
${""} </component>''
)
(builtins.sort
(l1: l2: let # lessThan
e1 = builtins.elemAt l1 0;
e2 = builtins.elemAt l2 0;
in if e1.group == e2.group then
if e1.name == e2.name then
builtins.lessThan e1.version e2.version
else
builtins.lessThan e1.name e2.name
else
builtins.lessThan e1.group e2.group
)
(builtins.attrValues (builtins.groupBy
(artifact: artifact.group + ":" + artifact.name + ":" + artifact.version)
(builtins.map # TODO: Remove duplicate artifacts from the list
(url:
(lib.lists.findFirst
(artifactItem: lib.strings.hasSuffix
artifactItem.path
url
)
(let
knownRepos = [
"https://dl.google.com/dl/android/maven2/"
"https://jitpack.io/"
"https://plugins.gradle.org/m2/"
"https://repo1.maven.org/maven2/"
"https://repo.maven.apache.org/maven2/"
"https://cache-redirector.jetbrains.com/www.jetbrains.com/intellij-repository/releases/"
];
artiPath = builtins.fetchurl url;
urlParts = builtins.elemAt
(builtins.split "^(.+)/([^/]+)/([^/]+)/([^/]+)$" url)
1;
in let
groupPath = (builtins.elemAt urlParts 0);
in let
artifactRepoBaseUrl = lib.lists.findFirst
(repository: lib.strings.hasPrefix
repository
groupPath
)
(abort ("Unknown repository is used in the path: " + groupPath))
knownRepos;
in let
repoRelativePath = (lib.strings.removePrefix
artifactRepoBaseUrl
groupPath
);
in {
sha256 = builtins.hashFile "sha256" artiPath;
path = artiPath;
group = builtins.replaceStrings ["/"] ["."] repoRelativePath;
name = builtins.elemAt urlParts 1;
version = builtins.elemAt urlParts 2;
file = builtins.elemAt urlParts 3;
origin = "Generated by flake.nix";
})
gradleArtifacts
)
)
gradleUrls
)
))
)
);
in ''
${""} <components>
${builtins.concatStringsSep "\n" verificationList}
${""} </components>'';
};
perSystem = { config, self', inputs', pkgs, lib, ... }: {
packages.default = let
stdenv = pkgs.stdenv;
ipredicateKt = self'.packages.ipredicateKt;
in
let
pluginSource = ./.;
customGitIgnoreFilter = src:
let
# Use a let binding like this to memoize info about the git directories.
# MDs are included in during the build as parts of CHANGELOG and README are copied
# into the plugin manifest.
srcIgnored = gitignore.lib.gitignoreFilterWith { basePath = src; extraRules = ''
/.*
/ci
/docs
/*.yml
/*.txt
/prepare4nix.sh
flake.lock
*.nix
''; };
in path: type: srcIgnored path type;
in let
gradleUrls = builtins.filter
(x: x != "")
(lib.strings.splitString "\n" (builtins.readFile ./artifacts.lst));
gradleArtifacts =
(builtins.concatMap
(componentPart:
(builtins.map
(artifactPart:
{
path = (
(builtins.replaceStrings ["."] ["/"] (builtins.elemAt componentPart 0)) +
"/" +
(builtins.elemAt componentPart 1) +
"/" +
(builtins.elemAt componentPart 2) +
"/" +
(builtins.elemAt artifactPart 0)
);
sha256 = builtins.elemAt artifactPart 1;
}
)
(builtins.filter
(x: builtins.isList x)
(builtins.split
''<artifact[[:space:]]+name="([^"]+)">[^<]+<sha256[[:space:]]+value="([^"]+)"''
(builtins.elemAt componentPart 3)
)
)
)
)
(builtins.filter
(x: builtins.isList x)
(builtins.split
''<component[[:space:]]+group="([^"]+)"[[:space:]]+name="([^"]+)"[[:space:]]+version="([^"]+)">(([^<]+</?(artifact|sha256))+)''
(builtins.readFile ./gradle/verification-metadata.xml)
)
)
);
in stdenv.mkDerivation rec {
name = "gradleBuild";
gradleLines = lib.strings.splitString "\n" (builtins.readFile ./gradle/wrapper/gradle-wrapper.properties);
gradleDist = lib.strings.stringAsChars (x: if x == "\\" then "" else x) (
lib.strings.removePrefix "distributionUrl=" (lib.lists.findSingle (it: lib.strings.hasPrefix "distributionUrl=" it) (abort "Unexpected gradle-wrapper content") (abort "Unexpected gradle-wrapper content") (
gradleLines
)));
gradleSha256 = lib.strings.stringAsChars (x: if x == "\\" then "" else x) (
lib.strings.removePrefix "distributionSha256Sum=" (lib.lists.findSingle (it: lib.strings.hasPrefix "distributionSha256Sum=" it) (abort "Unexpected gradle-wrapper content") (abort "Unexpected gradle-wrapper content") (
gradleLines
)));
gradleWrapper = builtins.fetchurl {
url = gradleDist;
sha256 = gradleSha256;
};
gradleInit = pkgs.writeText "init.gradle" ''
gradle.projectsLoaded {
rootProject.allprojects {
buildscript {
repositories {
clear()
maven { url "''${System.env.out}/m2" }
maven { url "''${System.env.out}/gradleDeps" }
}
}
repositories {
clear()
maven { url "''${System.env.out}/m2" }
maven { url "''${System.env.out}/gradleDeps" }
}
}
}
settingsEvaluated { settings ->
settings.pluginManagement {
repositories {
clear()
maven { url "''${System.env.out}/m2" }
maven { url "''${System.env.out}/gradleDeps" }
}
}
}
'';
src = lib.cleanSourceWith {
src = pluginSource;
filter = customGitIgnoreFilter pluginSource;
};
buildInputs = [
pkgs.autoPatchelfHook
pkgs.jdk17
pkgs.perl
pkgs.unzip
ipredicateKt
];
dontBuild = true;
# TODO: also build and package sources jar
installPhase = ''
set -ex
mkdir -p $out/gradleDeps
pushd $out/gradleDeps
'' + builtins.concatStringsSep
"\n"
(builtins.map
(url:
let
artifact = (lib.lists.findFirst
(artifactItem: lib.strings.hasSuffix
artifactItem.path
url
)
(abort ("Artifact is missing in gradle/verification-metadata.xml: " + url))
gradleArtifacts
);
in
"install -Dm444 ${builtins.fetchurl {url = url; sha256 = artifact.sha256;}} ./${artifact.path}"
)
gradleUrls
)
+ ''
popd
mkdir -p $out/build
cp -R ./* $out/build
pushd $out/build
perl -i -0pe 's|(distributionUrl=)|#$1|' gradle/wrapper/gradle-wrapper.properties
install -Dm444 ${gradleWrapper} gradle/wrapper/
echo "" >> gradle/wrapper/gradle-wrapper.properties
echo "distributionUrl=$(cd gradle/wrapper/ && ls *.zip)" >> gradle/wrapper/gradle-wrapper.properties
patchShebangs .
install -Dm444 ${ipredicateKt}/* ipredicate/project/src/main/kotlin/com/github/tarcv/testingteam/surveyor/ipredicate/
export JAVA_HOME=${pkgs.jdk17.home}
# Use '--debug' to debug dependency downloads by plugins
./gradlew -Dorg.gradle.jvmargs=-XX:MaxMetaspaceSize=1g \
-PNIX_GRADLE_DEPS_1=$out/gradleDeps \
--no-build-cache --no-configuration-cache \
--init-script ${gradleInit} check buildPlugin -x :plugin-test:test
cp -v plugin/build/distributions/*.zip $out
cp ${ipredicateKt}/* $out
popd
pushd $out
find . -maxdepth 1 -mindepth 1 -type d -exec rm -rfv '{}' \; # remove directories only
popd
'';
};
};
};
}