Skip to content

Commit 3d56567

Browse files
committed
[GR-19840] LibGraal adds an entry to the jlink.copyfiles file.
PullRequest: graal/12718
2 parents a3943ee + 3f2c079 commit 3d56567

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

sdk/mx.sdk/mx_sdk_vm.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def __prepare__(mcs, name, this_bases):
9898

9999

100100
class AbstractNativeImageConfig(_with_metaclass(ABCMeta, object)):
101-
def __init__(self, destination, jar_distributions, build_args, use_modules=None, links=None, is_polyglot=False, dir_jars=False, home_finder=False, build_time=1, build_args_enterprise=None): # pylint: disable=super-init-not-called
101+
def __init__(self, destination, jar_distributions, build_args, use_modules=None, links=None, is_polyglot=False, dir_jars=False, home_finder=False, jlink_copyfiles=False, build_time=1, build_args_enterprise=None): # pylint: disable=super-init-not-called
102102
"""
103103
:type destination: str
104104
:type jar_distributions: list[str]
@@ -108,6 +108,7 @@ def __init__(self, destination, jar_distributions, build_args, use_modules=None,
108108
:type is_polyglot: bool
109109
:param bool dir_jars: If true, all jars in the component directory are added to the classpath.
110110
:type home_finder: bool
111+
:type jlink_copyfiles: bool
111112
:type build_time: int
112113
:type build_args_enterprise: list[str] | None
113114
"""
@@ -119,6 +120,7 @@ def __init__(self, destination, jar_distributions, build_args, use_modules=None,
119120
self.is_polyglot = is_polyglot
120121
self.dir_jars = dir_jars
121122
self.home_finder = home_finder
123+
self.jlink_copyfiles = jlink_copyfiles
122124
self.build_time = build_time
123125
self.build_args_enterprise = build_args_enterprise or []
124126
self.relative_home_paths = {}
@@ -200,11 +202,11 @@ def __init__(self, destination, jar_distributions, main_class, build_args, langu
200202

201203

202204
class LibraryConfig(AbstractNativeImageConfig):
203-
def __init__(self, destination, jar_distributions, build_args, jvm_library=False, use_modules=None, home_finder=False, **kwargs):
205+
def __init__(self, destination, jar_distributions, build_args, jvm_library=False, use_modules=None, home_finder=False, jlink_copyfiles=False, **kwargs):
204206
"""
205207
:param bool jvm_library
206208
"""
207-
super(LibraryConfig, self).__init__(destination, jar_distributions, build_args, use_modules=use_modules, home_finder=home_finder, **kwargs)
209+
super(LibraryConfig, self).__init__(destination, jar_distributions, build_args, use_modules=use_modules, home_finder=home_finder, jlink_copyfiles=jlink_copyfiles, **kwargs)
208210
self.jvm_library = jvm_library
209211

210212

sdk/mx.sdk/mx_sdk_vm_impl.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import json
5151
import os
5252
from os.path import relpath, join, dirname, basename, exists, isfile, normpath, abspath, isdir, islink, isabs
53+
import pipes
5354
import pprint
5455
import re
5556
import shlex
@@ -330,6 +331,8 @@ def _get_main_component(components):
330331
""":type: dict[str, (str, str)]"""
331332
_parent_info_cache = {}
332333

334+
_jlink_copy_plugin = None
335+
333336
def _graalvm_maven_attributes(tag='graalvm'):
334337
"""
335338
:type tag: str
@@ -609,7 +612,7 @@ def _find_escaping_links(root_dir):
609612
_libpolyglot_component = mx_sdk_vm.graalvm_component_by_name('libpoly', fatalIfMissing=False)
610613
assert _libpolyglot_component is None or len(_libpolyglot_component.library_configs) == 1
611614
_libpolyglot_macro_dir = (_macros_dir + '/' + GraalVmNativeProperties.macro_name(_libpolyglot_component.library_configs[0]) + '/') if _macros_dir is not None and _libpolyglot_component is not None else None
612-
615+
_jlink_copyfiles = set()
613616
for _component in sorted(self.components, key=lambda c: c.name):
614617
mx.logv('Adding {} ({}) to the {} {}'.format(_component.name, _component.__class__.__name__, name, self.__class__.__name__))
615618
_component_type_base = _get_component_type_base(_component)
@@ -724,7 +727,11 @@ def _find_escaping_links(root_dir):
724727
_svm_library_home = _component_base
725728
_svm_library_dest = _svm_library_home + _library_config.destination
726729
if not stage1 and _get_svm_support().is_supported():
727-
_source_type = 'skip' if _skip_libraries(_library_config) else 'dependency'
730+
if _skip_libraries(_library_config):
731+
_source_type = 'skip'
732+
else:
733+
_source_type = 'dependency'
734+
_jlink_copyfiles.add(_svm_library_dest[len('<jre_base>/'):])
728735
_library_project_name = GraalVmNativeImage.project_name(_library_config)
729736
# add `LibraryConfig.destination` and the generated header files to the layout
730737
_add(layout, _svm_library_dest, _source_type + ':' + _library_project_name, _component)
@@ -794,6 +801,9 @@ def _find_escaping_links(root_dir):
794801
_metadata = self._get_metadata(_suites)
795802
_add(layout, _base + 'release', "string:{}".format(_metadata))
796803

804+
if is_graalvm and add_jdk_base and _has_jlink_copy_plugin() and _jlink_copyfiles:
805+
_add(layout, '<jdk_base>/conf/jlink.copyfiles', 'string:{}'.format('\n'.join(sorted(_jlink_copyfiles))))
806+
797807
if has_graal_compiler:
798808
_add(layout, '<jre_base>/lib/jvmci/compiler-name', 'string:graal')
799809

@@ -3748,6 +3758,18 @@ def _base_jdk_info():
37483758
return base_jdk_info.split(':')
37493759

37503760

3761+
def _has_jlink_copy_plugin():
3762+
global _jlink_copy_plugin
3763+
if _jlink_copy_plugin is None:
3764+
out = mx.LinesOutputCapture()
3765+
args = [_src_jdk.exe_path('jlink'), '--list-plugins']
3766+
exit_status = mx.run(args, out=out, err=out, nonZeroIsFatal=False)
3767+
if exit_status:
3768+
raise mx.abort('Failed to run \"{}\". Output:\n{}'.format(' '.join([pipes.quote(str(arg)) for arg in args]), '\n'.join(out.lines)))
3769+
_jlink_copy_plugin = any('--copy-files' in line for line in out.lines)
3770+
return _jlink_copy_plugin
3771+
3772+
37513773
def mx_post_parse_cmd_line(args):
37523774
if _src_jdk_version >= 9:
37533775
for component in registered_graalvm_components():

substratevm/mx.substratevm/mx_substratevm.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,7 @@ def _native_image_launcher_extra_jvm_args():
11921192
mx_sdk_vm.LibraryConfig(
11931193
destination="<lib:jvmcicompiler>",
11941194
jvm_library=True,
1195+
jlink_copyfiles=True,
11951196
jar_distributions=libgraal_jar_distributions,
11961197
build_args=libgraal_build_args + ['--features=com.oracle.svm.graal.hotspot.libgraal.LibGraalFeature'],
11971198
),

0 commit comments

Comments
 (0)