@@ -561,10 +561,12 @@ public List<String> getBuilderJavaArgs() {
561
561
*/
562
562
public List <Path > getBuilderModulePath () {
563
563
List <Path > result = new ArrayList <>();
564
- // Non-jlinked JDKs need truffle and graal-sdk on the module path since they
565
- // don't have those modules as part of the JDK.
564
+ // Non-jlinked JDKs need truffle and word, collections, nativeimage on the
565
+ // module path since they don't have those modules as part of the JDK. Note
566
+ // that graal-sdk is now obsolete after the split in GR-43819 (#7171)
566
567
if (libJvmciDir != null ) {
567
- result .addAll (getJars (libJvmciDir , "graal-sdk" , "enterprise-graal" ));
568
+ result .addAll (getJars (libJvmciDir , "enterprise-graal" ));
569
+ result .addAll (getJars (libJvmciDir , "word" , "collections" , "nativeimage" ));
568
570
}
569
571
if (modulePathBuild ) {
570
572
result .addAll (createTruffleBuilderModulePath ());
@@ -574,19 +576,36 @@ public List<Path> getBuilderModulePath() {
574
576
}
575
577
576
578
private List <Path > createTruffleBuilderModulePath () {
577
- List <Path > jars = getJars (rootDir .resolve (Paths .get ("lib" , "truffle" )), "truffle-api" , "truffle-runtime" , "truffle-enterprise" );
579
+ Path libTruffleDir = rootDir .resolve (Paths .get ("lib" , "truffle" ));
580
+ List <Path > jars = getJars (libTruffleDir , "truffle-api" , "truffle-runtime" , "truffle-enterprise" );
578
581
if (!jars .isEmpty ()) {
579
582
/*
580
583
* If Truffle is installed as part of the JDK we always add the builder modules of
581
584
* Truffle to the builder module path. This is legacy support and should in the
582
585
* future no longer be needed.
583
586
*/
584
- jars .addAll (getJars (rootDir . resolve ( Paths . get ( "lib" , "truffle" )) , "truffle-compiler" ));
587
+ jars .addAll (getJars (libTruffleDir , "truffle-compiler" ));
585
588
Path builderPath = rootDir .resolve (Paths .get ("lib" , "truffle" , "builder" ));
586
589
if (Files .exists (builderPath )) {
587
590
jars .addAll (getJars (builderPath , "truffle-runtime-svm" , "truffle-enterprise-svm" ));
591
+ if (libJvmciDir != null ) {
592
+ // truffle-runtime-svm depends on polyglot, which is not part of non-jlinked
593
+ // JDKs
594
+ jars .addAll (getJars (libJvmciDir , "polyglot" ));
595
+ }
596
+ }
597
+ if (libJvmciDir != null ) {
598
+ // truffle-runtime depends on polyglot, which is not part of non-jlinked JDKs
599
+ jars .addAll (getJars (libTruffleDir , "jniutils" ));
588
600
}
589
601
}
602
+ /*
603
+ * Non-Jlinked JDKs don't have truffle-compiler as part of the JDK, however the native
604
+ * image builder still needs it
605
+ */
606
+ if (libJvmciDir != null ) {
607
+ jars .addAll (getJars (libTruffleDir , "truffle-compiler" ));
608
+ }
590
609
591
610
return jars ;
592
611
}
@@ -1544,7 +1563,8 @@ protected int buildImage(List<String> javaArgs, LinkedHashSet<Path> cp, LinkedHa
1544
1563
Function <Path , Path > substituteModulePath = useBundle () ? bundleSupport ::substituteModulePath : Function .identity ();
1545
1564
List <Path > substitutedImageModulePath = imagemp .stream ().map (substituteModulePath ).toList ();
1546
1565
1547
- Map <String , Path > modules = listModulesFromPath (javaExecutable , Stream .concat (mp .stream (), imagemp .stream ()).distinct ().toList ());
1566
+ List <String > mainClassArg = config .getGeneratorMainClass ();
1567
+ Map <String , Path > modules = listModulesFromPath (javaExecutable , javaArgs , mainClassArg , mp .stream ().distinct ().toList (), imagemp .stream ().distinct ().toList ());
1548
1568
if (!addModules .isEmpty ()) {
1549
1569
1550
1570
arguments .add ("-D" + ModuleSupport .PROPERTY_IMAGE_EXPLICITLY_ADDED_MODULES + "=" +
@@ -1564,7 +1584,7 @@ protected int buildImage(List<String> javaArgs, LinkedHashSet<Path> cp, LinkedHa
1564
1584
}
1565
1585
}
1566
1586
1567
- arguments .addAll (config . getGeneratorMainClass () );
1587
+ arguments .addAll (mainClassArg );
1568
1588
1569
1589
if (IS_AOT && OS .getCurrent ().hasProcFS ) {
1570
1590
/*
@@ -1715,33 +1735,41 @@ protected int buildImage(List<String> javaArgs, LinkedHashSet<Path> cp, LinkedHa
1715
1735
/**
1716
1736
* Resolves and lists all modules given a module path.
1717
1737
*
1718
- * @see #callListModules(String, List)
1738
+ * @see #callListModules(String, List, List, List, List )
1719
1739
*/
1720
- private Map <String , Path > listModulesFromPath (String javaExecutable , Collection < Path > modulePath ) {
1740
+ private Map <String , Path > listModulesFromPath (String javaExecutable , List < String > javaArgs , List < String > mainClassArg , List < Path > modulePath , List < Path > imagemp ) {
1721
1741
if (modulePath .isEmpty () || !config .modulePathBuild ) {
1722
1742
return Map .of ();
1723
1743
}
1724
1744
String modulePathEntries = modulePath .stream ()
1725
1745
.map (Path ::toString )
1726
1746
.collect (Collectors .joining (File .pathSeparator ));
1727
- return callListModules (javaExecutable , List .of ("-p" , modulePathEntries ));
1747
+ String imagePathEntries = imagemp .stream ()
1748
+ .map (Path ::toString )
1749
+ .collect (Collectors .joining (File .pathSeparator ));
1750
+ List <String > imagempArgs = List .of ("-imagemp" , imagePathEntries );
1751
+ List <String > modulePathArgs = List .of ("--module-path" , modulePathEntries );
1752
+ return callListModules (javaExecutable , javaArgs , mainClassArg , imagempArgs , modulePathArgs );
1728
1753
}
1729
1754
1730
1755
/**
1731
- * Calls <code>java $arguments --list-modules</code> to list all modules and parse the output.
1732
- * The output consists of a map with module name as key and {@link Path} to jar file if the
1733
- * module is not installed as part of the JDK. If the module is installed as part of the
1756
+ * Calls the image generator's <code>--list-modules</code> to list all modules and parses the
1757
+ * output. The output consists of a map with module name as key and {@link Path} to jar file if
1758
+ * the module is not installed as part of the JDK. If the module is installed as part of the
1734
1759
* jdk/boot-layer then a <code>null</code> path will be returned.
1735
1760
* <p>
1736
1761
* This is a much more robust solution then trying to parse the JDK file structure manually.
1737
1762
*/
1738
- private static Map <String , Path > callListModules (String javaExecutable , List <String > arguments ) {
1763
+ private static Map <String , Path > callListModules (String javaExecutable , List <String > javaArgs , List < String > mainClassArg , List < String > imagempArgs , List < String > modulePathArgs ) {
1739
1764
Process listModulesProcess = null ;
1740
1765
Map <String , Path > result = new LinkedHashMap <>();
1741
1766
try {
1742
1767
var pb = new ProcessBuilder (javaExecutable );
1743
- pb .command ().addAll (arguments );
1744
- pb .command ().add ("--list-modules" );
1768
+ pb .command ().addAll (javaArgs );
1769
+ pb .command ().addAll (modulePathArgs );
1770
+ pb .command ().addAll (mainClassArg );
1771
+ pb .command ().addAll (imagempArgs );
1772
+ pb .command ().add ("-H:+ListModules" );
1745
1773
pb .environment ().clear ();
1746
1774
listModulesProcess = pb .start ();
1747
1775
@@ -1758,8 +1786,10 @@ private static Map<String, Path> callListModules(String javaExecutable, List<Str
1758
1786
String [] splitModuleNameAndVersion = StringUtil .split (splitString [0 ], "@" , 2 );
1759
1787
Path externalPath = null ;
1760
1788
if (splitString .length > 1 ) {
1761
- String pathURI = splitString [1 ]; // url: file://path/to/file
1762
- externalPath = Path .of (URI .create (pathURI )).toAbsolutePath ();
1789
+ String pathURI = splitString [1 ].trim (); // url: file://path/to/file
1790
+ if (pathURI .startsWith ("file://" )) {
1791
+ externalPath = Path .of (URI .create (pathURI )).toAbsolutePath ();
1792
+ }
1763
1793
}
1764
1794
result .put (splitModuleNameAndVersion [0 ], externalPath );
1765
1795
}
0 commit comments