@@ -4,10 +4,9 @@
44, sourcesFilename
55, name
66, lib
7−, writeScript
7+, writeShellScript
88, jq
9−, runtimeShell
10−, gawk
9+, gnused
1110}:
1211
1312/*
@@ -32,7 +31,7 @@
3231*/
3332
3433let
35− productJavaVersionGraalVersionSep = "|";
34+ separator = "|";
3635
3736 # isDev :: String -> Boolean
3837 isDev = version:
@@ -131,7 +130,7 @@ let
131130 genProductJavaVersionGraalVersionAttrSet = product_javaVersion_graalVersion:
132131 let
133132 attrNames = [ "product" "javaVersion" "graalVersion" ];
134− attrValues = lib.splitString productJavaVersionGraalVersionSep product_javaVersion_graalVersion;
133+ attrValues = lib.splitString separator product_javaVersion_graalVersion;
135134 in
136135 zipListsToAttrs attrNames attrValues;
137136
@@ -153,23 +152,23 @@ let
153152 };
154153
155154 # genArchProductVersionPairs :: String -> AttrSet -> [AttrSet]
156− genArchProductVersionList = javaGraalVersion: archProducts:
155+ genArchProductVersionList = javaVersion: archProducts:
157156 let
158157 arch = archProducts.arch;
159158 products = archProducts.products;
159+ javaGraalVersion = javaVersion + separator + (getLatestVersion archProducts.version);
160160 productJavaGraalVersionList =
161− cartesianZipListsWith (a: b: a + productJavaVersionGraalVersionSep + b)
161+ cartesianZipListsWith (a: b: a + separator + b)
162162 products [ javaGraalVersion ];
163163 in
164164 cartesianZipListsWith (genUrlAndSha256) [ arch ] productJavaGraalVersionList;
165165
166166
167− # genSources :: String -> String -> AttrSet -> Path String
168− genSources = graalVersion: javaVersion: config:
167+ # genSources :: String -> AttrSet -> Path String
168+ genSources = javaVersion: config:
169169 let
170− javaGraalVersion = javaVersion + productJavaVersionGraalVersionSep + graalVersion;
171170 archProducts = builtins.attrValues config;
172− sourcesList = builtins.concatMap (genArchProductVersionList javaGraalVersion) archProducts;
171+ sourcesList = builtins.concatMap (genArchProductVersionList javaVersion) archProducts;
173172 sourcesAttr = builtins.foldl' (lib.recursiveUpdate) { } sourcesList;
174173 in
175174 builtins.toFile "sources.json" (builtins.toJSON sourcesAttr);
@@ -183,32 +182,38 @@ let
183182 }.${builtins.toString (builtins.compareVersions newVersion currentVersion)};
184183
185184 newVersion = getLatestVersion graalVersion;
186− sourcesJson = genSources newVersion javaVersion config;
185+ sourcesJson = genSources javaVersion config;
187186 sourcesJsonPath = lib.strings.escapeShellArg ././${sourcesFilename};
188− defaultNixPath = lib.strings.escapeShellArg ././default.nix;
187+
188+ # versionKeyInDefaultNix String -> String
189+ versionKeyInDefaultNix = graalVersion:
190+ if isDev graalVersion
191+ then "${name}-dev-version"
192+ else "${name}-release-version";
189193
190194 /*
191195 updateScriptText :: String -> String -> String
192− Writes the json file, finds the line number of the current derivation
193− name, which wants to update with awk and replace the first version match
194− after that line.
196+ Writes the json file and updates the version in default.nix using sed
197+ because update-source-version does not work srcs.
195198 */
196199 updateScriptText = newVersion: currentVersion:
200+
197201 if isNew newVersion currentVersion
198202 then
203+ let
204+ versionKey = versionKeyInDefaultNix currentVersion;
205+ in
199206 ''
200207 echo "New version found. Updating ${currentVersion} -> ${newVersion}".
201− export PATH="${lib.makeBinPath [ jq gawk ]}:$PATH"
208+ export PATH="${lib.makeBinPath [ jq gnused ]}:$PATH"
202209 jq . ${sourcesJson} > ${sourcesJsonPath}
203− drvName=$(awk '/${name}/{ print NR; exit }' ${defaultNixPath})
204− awk -v drvName="$drvName" -i inplace \
205− 'NR>drvName {sub(/${graalVersion}/, "${newVersion}")} 1' ${defaultNixPath}
210+ sed -i 's|${versionKey} = "${currentVersion}";|${versionKey} = "${newVersion}";|' \
211+ ${lib.strings.escapeShellArg ././default.nix}
206212 ''
207213 else ''echo "No new version found. Skip updating."'';
208214
209215in
210−writeScript "update-graal.sh" ''
211− #!${runtimeShell}
216+writeShellScript "update-graal.sh" ''
212217 set -o errexit
213218 set -o nounset
214219 set -o pipefail