Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GR-48515] Enforce .exports files gets safely created for a cmd-launcher. #7557

Merged
merged 2 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions sdk/mx.sdk/mx_sdk_vm_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,10 @@ def _add_link(_dest, _target, _component=None, _dest_base_name=None):
# add `LauncherConfig.destination` to the layout
launcher_project = GraalVmLauncher.launcher_project_name(_launcher_config, stage1)
_add(layout, _launcher_dest, 'dependency:' + launcher_project, _component)
if not GraalVmLauncher.is_launcher_native(_launcher_config, stage1) and mx.is_windows():
assert _launcher_dest.endswith('.cmd')
export_list_dest = _launcher_dest[:-len('cmd')] + 'export-list'
_add(layout, export_list_dest, f'dependency:{launcher_project}/*.export-list', _component)
if _debug_images() and GraalVmLauncher.is_launcher_native(_launcher_config, stage1) and _get_svm_support().generate_debug_info(_launcher_config):
if _get_svm_support().generate_separate_debug_info(_launcher_config):
_add(layout, dirname(_launcher_dest) + '/', 'dependency:' + launcher_project + '/*' + _get_svm_support().separate_debuginfo_ext(), _component)
Expand Down Expand Up @@ -1878,6 +1882,14 @@ def getBuildTask(self, args):
else:
return GraalVmBashLauncherBuildTask(self, args)

def getArchivableResults(self, use_relpath=True, single=False):
yield from super().getArchivableResults(use_relpath=use_relpath, single=single)
if not single and not self.is_native() and mx.is_windows():
assert self.native_image_name.endswith('.cmd')
export_list_arc_name = self.native_image_name[:-len('cmd')] + 'export-list'
export_list_file = join(self.build_directory(), export_list_arc_name)
yield export_list_file, export_list_arc_name

def is_native(self):
return GraalVmLauncher.is_launcher_native(self.native_image_config, self.stage1)

Expand Down Expand Up @@ -2239,14 +2251,12 @@ def _get_launcher_args():
return ''

def _get_add_exports():
res = ' '.join(self.subject.native_image_config.get_add_exports(_known_missing_jars))
if mx.is_windows():
res = ' '.join(('"{}"'.format(a) for a in res.split()))
return res
return ' '.join(self.subject.native_image_config.get_add_exports(_known_missing_jars))

_template_subst = mx_subst.SubstitutionEngine(mx_subst.string_substitutions)
_template_subst.register_no_arg('module_launcher', _is_module_launcher)
_template_subst.register_no_arg('add_exports', _get_add_exports)
if not mx.is_windows():
_template_subst.register_no_arg('add_exports', _get_add_exports)
_template_subst.register_no_arg('classpath', _get_classpath)
_template_subst.register_no_arg('jre_bin', _get_jre_bin)
_template_subst.register_no_arg('main_class', _get_main_class)
Expand All @@ -2256,6 +2266,11 @@ def _get_add_exports():
_template_subst.register_no_arg('option_vars', _get_option_vars)
_template_subst.register_no_arg('launcher_args', _get_launcher_args)

if mx.is_windows():
add_exports_argfile = output_file[:-len('cmd')] + 'export-list'
with open(add_exports_argfile, 'w') as argfile:
argfile.write('\n'.join(_get_add_exports().split()))

with open(self._template_file(), 'r') as template, mx.SafeFileCreation(output_file) as sfc, open(sfc.tmpPath, 'w') as launcher:
for line in template:
launcher.write(_template_subst.substitute(line))
Expand Down
7 changes: 1 addition & 6 deletions sdk/mx.sdk/vm/launcher_template.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,7 @@ set "module_launcher=<module_launcher>"
if "%module_launcher%"=="True" (
set "main_class=--module <main_module>/<main_class>"
set "app_path_arg=--module-path"
set exports_file="%location%.!basename!.exports"
if not exist "!exports_file!" (
for %%a in (<add_exports>) do (
echo %%a >> "!exports_file!"
)
)
set exports_file="%location%!basename!.export-list"
set "jvm_args=!jvm_args! @!exports_file!"
) else (
set "main_class=<main_class>"
Expand Down