Skip to content

Commit 9ffedd3

Browse files
committed
Cleanup
1 parent ebe1218 commit 9ffedd3

File tree

5 files changed

+33
-31
lines changed

5 files changed

+33
-31
lines changed

src/jdk.jlink/share/classes/jdk/tools/jlink/internal/JRTArchive.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ public class JRTArchive implements Archive {
8989
* install aborts the link.
9090
* @param perModDiff The lib/modules (a.k.a jimage) diff for this module,
9191
* possibly an empty list if there are no differences.
92-
* @param altHashSums A map of per-module hash sums to allow for binaries
93-
* and dynamic libraries.
92+
* @param altHashSums A map of alternative hash sums for files in
93+
* a module, possibly empty.
9494
* @param taskHelper The task helper reference.
9595
*/
9696
JRTArchive(String module,
@@ -225,7 +225,14 @@ private void addNonClassResources() {
225225

226226
// Read from the base JDK image.
227227
Path path = BASE.resolve(m.resPath);
228-
// FIXME: Do this only for binaries/shared libs?
228+
// Allow for additional hash sums so as to support
229+
// file modifications done after jlink has run at build
230+
// time. For example for Windows builds done with
231+
// --with-external-symbols-in-bundles=public or
232+
// distribution builds, where some post-processing happens
233+
// on produced binaries and libraries invalidating the
234+
// hash sum included in the jdk.jlink module for those
235+
// files at jlink-time
229236
Set<String> shaSums = new HashSet<>();
230237
shaSums.add(m.hashOrTarget);
231238
Set<String> extra = altHashSums.get(m.resPath);

src/jdk.jlink/share/classes/jdk/tools/jlink/internal/JlinkTask.java

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
import java.io.BufferedInputStream;
3030
import java.io.File;
31-
import java.io.FileNotFoundException;
3231
import java.io.IOException;
3332
import java.io.InputStream;
3433
import java.io.PrintWriter;
@@ -60,7 +59,6 @@
6059
import java.util.Objects;
6160
import java.util.Optional;
6261
import java.util.Set;
63-
import java.util.TreeSet;
6462
import java.util.stream.Collectors;
6563
import java.util.stream.Stream;
6664

@@ -202,16 +200,22 @@ public class JlinkTask {
202200
throw taskHelper.newBadArgs("err.sha.overrides.multiple");
203201
}
204202
Path file = Paths.get(arg.substring(1));
205-
try {
206-
Files.readAllLines(file).stream()
207-
.forEach(task.options.shaOverrides::add);
208-
} catch (FileNotFoundException e) {
209-
throw taskHelper.newBadArgs("err.sha.overrides.fnf", file.toString());
210-
} catch (IOException e) {
211-
throw taskHelper.newBadArgs("err.sha.overrides.freaderr", file.toString());
203+
// Ignore non-existing sha overrides file.
204+
//
205+
// This is to allow for custom builds needing to optionally
206+
// support run-time image links on (possibly) modified
207+
// binaries/debuginfo files done after the JDK build
208+
if (Files.exists(file)) {
209+
try {
210+
Files.readAllLines(file).stream()
211+
.forEach(task.options.shaOverrides::add);
212+
} catch (IOException e) {
213+
throw taskHelper.newBadArgs("err.sha.overrides.freaderr", file.toString());
214+
}
212215
}
213216
} else {
214-
// Comma separated values on CLI. Possible multiples.
217+
// Allow multiple values, separated by comma in addition to
218+
// multiple times the same option.
215219
Arrays.asList(arg.split(",")).stream()
216220
.forEach(task.options.shaOverrides::add);
217221
}
@@ -486,7 +490,7 @@ private JlinkConfiguration initJlinkConfig() throws BadArgs {
486490

487491
LinkableRuntimeImage.Config linkableRuntimeConfig = new LinkableRuntimeImage.Config(
488492
options.ignoreModifiedRuntime,
489-
isLinkFromRuntime ? buildShaSumMap(finder, taskHelper, options.shaOverrides) : Map.of());
493+
isLinkFromRuntime ? buildShaSumMap(taskHelper, options.shaOverrides) : null);
490494
return new JlinkConfiguration(options.output,
491495
roots,
492496
finder,
@@ -495,15 +499,9 @@ private JlinkConfiguration initJlinkConfig() throws BadArgs {
495499
options.generateLinkableRuntime);
496500
}
497501

498-
private Map<String, Map<String, Set<String>>> buildShaSumMap(ModuleFinder finder,
499-
TaskHelper taskHelper,
502+
private Map<String, Map<String, Set<String>>> buildShaSumMap(TaskHelper taskHelper,
500503
Set<String> shaOverrides) throws BadArgs {
501-
Set<String> modules = finder.findAll().stream()
502-
.map(ModuleReference::descriptor)
503-
.map(ModuleDescriptor::name)
504-
.collect(Collectors.toSet());
505504
Map<String, Map<String, Set<String>>> moduleToFiles = new HashMap<>();
506-
modules.forEach(m -> { moduleToFiles.put(m, new HashMap<>());});
507505
for (String t: shaOverrides) {
508506
String trimmed = t.trim();
509507
if (trimmed.startsWith("#")) {
@@ -518,12 +516,8 @@ private Map<String, Map<String, Set<String>>> buildShaSumMap(ModuleFinder finder
518516
// <module-name>
519517
// <file-path>
520518
// <SHA-512-sum>
521-
Map<String, Set<String>> perModuleMap = moduleToFiles.get(tokens[0]);
522-
if (perModuleMap == null) {
523-
throw taskHelper.newBadArgs("err.sha.overrides.bad.module", tokens[0]);
524-
}
525-
// TreeSet to disallow null values
526-
Set<String> shaSumsPerFile = perModuleMap.computeIfAbsent(tokens[1], k -> new TreeSet<>());
519+
Map<String, Set<String>> perModuleMap = moduleToFiles.computeIfAbsent(tokens[0], k -> new HashMap<>());
520+
Set<String> shaSumsPerFile = perModuleMap.computeIfAbsent(tokens[1], k -> new HashSet<>());
527521
shaSumsPerFile.add(tokens[2]);
528522
}
529523
return moduleToFiles;

src/jdk.jlink/share/classes/jdk/tools/jlink/internal/LinkableRuntimeImage.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ public static Archive newArchive(String module,
8787
path,
8888
!config.ignoreModifiedRuntime,
8989
perModuleDiff,
90-
config.altHashSums.get(module),
90+
// Empty map if no alternative sha sums
91+
config.altHashSums.computeIfAbsent(module, k -> Map.of()),
9192
taskHelper);
9293
}
9394

src/jdk.jlink/share/classes/jdk/tools/jlink/resources/jlink.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,12 @@ err.runtime.link.packaged.mods=This JDK has no packaged modules.\
127127
err.runtime.link.modified.file={0} has been modified
128128
err.runtime.link.patched.module=jlink does not support linking from the run-time image\
129129
\ when running on a patched runtime with --patch-module
130+
130131
# Linking from the run-time image, SHA sum handling
131132
err.sha.overrides.multiple=option --sha-overrides does not allow @file and non-file combinations
132-
err.sha.overrides.fnf=File ''{0}'' not found that got passed with option --sha-overrides
133133
err.sha.overrides.freaderr=Error reading file ''{0}'' passed with option --sha-overrides
134134
err.sha.overrides.bad.format=Bad format in --sha-overrides. Token was {0}. Expected <module-name>|<file-path>|<sha-sum>
135-
err.sha.overrides.bad.module=Module {0} specified in --sha-overrides is not in the set of output modules
135+
136136
err.no.module.path=--module-path option must be specified with --add-modules ALL-MODULE-PATH
137137
err.empty.module.path=No module found in module path ''{0}'' with --add-modules ALL-MODULE-PATH
138138
err.limit.modules=--limit-modules not allowed with --add-modules ALL-MODULE-PATH

test/jdk/tools/jlink/IntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ private static void test() throws Exception {
159159
mods,
160160
JlinkTask.limitFinder(JlinkTask.newModuleFinder(modulePaths), limits, mods),
161161
linkFromRuntime,
162-
false /* ignore modified runtime */,
162+
null /* run-time image link config */,
163163
false /* generate run-time image */);
164164

165165
List<Plugin> lst = new ArrayList<>();

0 commit comments

Comments
 (0)