|
20 | 20 | # or visit www.oracle.com if you need additional information or have any
|
21 | 21 | # questions.
|
22 | 22 | #
|
23 |
| -from os.path import exists |
| 23 | +from os.path import exists, join |
| 24 | +from copy import deepcopy |
24 | 25 |
|
25 | 26 | import mx
|
26 | 27 | import mx_sdk_vm
|
27 |
| -import mx_sdk_vm_impl |
28 | 28 | import mx_gate
|
29 | 29 |
|
30 |
| -from mx_espresso import _espresso_stability, espresso_library_config, _espresso_command, _send_sigquit, _llvm_toolchain_wrappers |
| 30 | +from mx_espresso import _espresso_stability, _has_native_espresso_standalone, _send_sigquit, get_java_home_dep, _jdk_lib_dir, jvm_standalone_with_llvm |
| 31 | +from mx_sdk_vm_ng import _find_native_image_command, ThinLauncherProject # pylint: disable=unused-import |
| 32 | +from mx_sdk_vm_impl import get_final_graalvm_distribution, has_component |
31 | 33 |
|
32 | 34 | _suite = mx.suite('espresso-compiler-stub')
|
33 | 35 |
|
|
48 | 50 | standalone=False,
|
49 | 51 | ))
|
50 | 52 |
|
| 53 | +def create_ni_standalone(base_standalone_name, register_distribution): |
| 54 | + espresso_suite = mx.suite('espresso') |
| 55 | + base_standalone = espresso_suite.dependency(base_standalone_name, fatalIfMissing=False) |
| 56 | + assert base_standalone_name.startswith('ESPRESSO_') |
| 57 | + ni_pos = len('ESPRESSO_') |
| 58 | + ni_standalone_name = base_standalone_name[:ni_pos] + 'NI_' + base_standalone_name[ni_pos:] |
| 59 | + if base_standalone: |
| 60 | + layout = deepcopy(base_standalone.layout) |
| 61 | + if '_NATIVE_' in base_standalone_name: |
| 62 | + # avoid dependency on project, copy from base standalone |
| 63 | + idx = layout['<jdk_lib_dir>/truffle/'].index('dependency:espresso:com.oracle.truffle.espresso.mokapot/<lib:jvm>') |
| 64 | + layout['<jdk_lib_dir>/truffle/'][idx] = f'dependency:espresso:{base_standalone_name}/{_jdk_lib_dir()}/truffle/<lib:jvm>' |
| 65 | + assert len(layout['languages/java/lib/']) == 1 |
| 66 | + layout['languages/java/lib/'] = [ |
| 67 | + f'dependency:espresso:{base_standalone_name}/languages/java/lib/<lib:javavm>' |
| 68 | + ] |
| 69 | + else: |
| 70 | + idx = layout['languages/java/lib/'].index('dependency:espresso:com.oracle.truffle.espresso.mokapot/<lib:jvm>') |
| 71 | + layout['languages/java/lib/'][idx] = f'dependency:espresso:{base_standalone_name}/languages/java/lib/<lib:jvm>' |
| 72 | + idx = layout['bin/'].index('dependency:espresso:espresso') |
| 73 | + del layout['bin/'][idx] |
| 74 | + layout['bin/<exe:espresso>'] = f'dependency:espresso:{base_standalone}/bin/<exe:espresso>' |
| 75 | + layout['bin/<exe:java>'] = 'link:<exe:espresso>' |
| 76 | + layout['./'][0]['exclude'].append("bin/<exe:java>") |
| 77 | + if not jvm_standalone_with_llvm(): |
| 78 | + mx.warn(f"{ni_standalone_name} requires using nfi-llvm but it looks like ESPRESSO_LLVM_JAVA_HOME wasn't set.") |
| 79 | + layout['languages/java/lib/'].append("dependency:espresso-compiler-stub:ESPRESSO_GRAAL/*") |
| 80 | + layout['./'][0]['exclude'].remove('lib/static') |
| 81 | + espresso_java_home = get_java_home_dep() |
| 82 | + if _find_native_image_command(espresso_java_home.java_home): |
| 83 | + # ESPRESSO_JAVA_HOME has native-image, keep that |
| 84 | + pass |
| 85 | + elif has_component('ni') and espresso_java_home.java_home == mx_sdk_vm.base_jdk().home: |
| 86 | + # substratevm is available and ESPRESSO_JAVA_HOME is JAVA_HOME, use GraalVM |
| 87 | + layout['./'][0]['source_type'] = 'extracted-dependency' |
| 88 | + layout['./'][0]['dependency'] = get_final_graalvm_distribution().qualifiedName() |
| 89 | + layout['./'][0]['path'] = '*/*' |
| 90 | + layout['./'][0]['exclude'] += [ |
| 91 | + '*/languages/elau', |
| 92 | + '*/languages/java', |
| 93 | + '*/bin/espresso' |
| 94 | + ] |
| 95 | + else: |
| 96 | + layout = None |
| 97 | + if not mx.suite('substratevm', fatalIfMissing=False): |
| 98 | + second_issue = "the substratevm suite is not available" |
| 99 | + elif not has_component('ni'): |
| 100 | + second_issue = "the Native Image component is not available in the current GraalVM" |
| 101 | + else: |
| 102 | + second_issue = "ESPRESSO_JAVA_HOME != JAVA_HOME" |
| 103 | + mx.warn("ESPRESSO_JAVA_HOME doesn't contain native-image and " + second_issue + ". Cannot create " + ni_standalone_name) |
| 104 | + if layout: |
| 105 | + register_distribution(mx.LayoutDirDistribution(_suite, ni_standalone_name, [], layout, None, True, base_standalone.theLicense, pruning_mode=base_standalone.pruning_mode)) |
| 106 | + return True |
| 107 | + return False |
51 | 108 |
|
52 |
| -def _run_espresso_native_image_launcher(args, cwd=None, nonZeroIsFatal=True, out=None, err=None, timeout=None): |
| 109 | +def mx_register_dynamic_suite_constituents(register_project, register_distribution): |
| 110 | + native = create_ni_standalone('ESPRESSO_NATIVE_STANDALONE', register_distribution) |
| 111 | + jvm = create_ni_standalone('ESPRESSO_JVM_STANDALONE', register_distribution) |
| 112 | + if not (native or jvm): |
| 113 | + raise mx.abort("Couldn't create any Espresso native-image standalone") |
| 114 | + |
| 115 | +def _run_espresso_native_image_launcher(args, cwd=None, nonZeroIsFatal=True, out=None, err=None, timeout=None, mode=None): |
53 | 116 | extra_args = ['-J--vm.' + arg for arg in mx_gate.get_jacoco_agent_args() or []]
|
54 |
| - if mx_sdk_vm_impl._skip_libraries(espresso_library_config): |
55 |
| - # JVM mode |
56 |
| - espresso_launcher = _espresso_command('espresso', [])[0] |
57 |
| - if not exists(espresso_launcher): |
58 |
| - raise mx.abort("It looks like JVM mode but the espresso launcher does not exist") |
| 117 | + mode = mode or _detect_espresso_native_image_mode() |
| 118 | + if mode == 'native': |
| 119 | + standalone = 'ESPRESSO_NI_NATIVE_STANDALONE' |
| 120 | + else: |
| 121 | + assert mode == 'jvm' |
| 122 | + standalone = 'ESPRESSO_NI_JVM_STANDALONE' |
| 123 | + espresso_launcher = join(mx.distribution(standalone).get_output(), 'bin', mx.exe_suffix('espresso')) |
59 | 124 | extra_args += [
|
60 | 125 | '--vm.Dcom.oracle.svm.driver.java.executable.override=' + espresso_launcher,
|
61 | 126 | '-J--java.GuestFieldOffsetStrategy=graal',
|
62 | 127 | '-J--java.NativeBackend=nfi-llvm',
|
63 |
| - ] |
64 |
| - native_image_command = _espresso_command('native-image', extra_args + args) |
65 |
| - if not exists(native_image_command[0]): |
66 |
| - raise mx.abort("The native-image launcher does not exist") |
67 |
| - return mx.run(native_image_command, cwd=cwd, nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, timeout=timeout, on_timeout=_send_sigquit) |
| 128 | + '--vm.-java.NativeBackend=nfi-llvm' |
| 129 | + ] |
| 130 | + standalone_output = mx.distribution(standalone).get_output() |
| 131 | + if not exists(standalone_output): |
| 132 | + raise mx.abort(f"{standalone} doesn't seem to be built, please run `mx build --targets={standalone}`") |
| 133 | + native_image_command = _find_native_image_command(standalone_output) |
| 134 | + if not native_image_command: |
| 135 | + raise mx.abort(f"The native-image launcher does not exist in {standalone}") |
| 136 | + return mx.run([native_image_command] + extra_args + args, cwd=cwd, nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, timeout=timeout, on_timeout=_send_sigquit) |
68 | 137 |
|
| 138 | +def _detect_espresso_native_image_mode(): |
| 139 | + if _has_native_espresso_standalone() and exists(mx.distribution('ESPRESSO_NI_NATIVE_STANDALONE').get_output()): |
| 140 | + return 'native' |
| 141 | + else: |
| 142 | + return 'jvm' |
| 143 | + |
| 144 | +def _run_espresso_native_image_jvm_launcher(args, cwd=None, nonZeroIsFatal=True, out=None, err=None, timeout=None): |
| 145 | + return _run_espresso_native_image_launcher(args, cwd, nonZeroIsFatal, out, err, timeout, mode='jvm') |
| 146 | + |
| 147 | +def _run_espresso_native_image_native_launcher(args, cwd=None, nonZeroIsFatal=True, out=None, err=None, timeout=None): |
| 148 | + return _run_espresso_native_image_launcher(args, cwd, nonZeroIsFatal, out, err, timeout, mode='native') |
69 | 149 |
|
70 | 150 | mx.update_commands(_suite, {
|
71 | 151 | 'espresso-native-image': [_run_espresso_native_image_launcher, '[args]'],
|
| 152 | + 'espresso-native-image-jvm': [_run_espresso_native_image_jvm_launcher, '[args]'], |
| 153 | + 'espresso-native-image-native': [_run_espresso_native_image_native_launcher, '[args]'], |
72 | 154 | })
|
73 |
| - |
74 |
| -mx_sdk_vm.register_vm_config('espresso-ni-ce', ['java', 'ejvm', 'ejc', 'nfi-libffi', 'nfi', 'sdk', 'sdkni', 'sdkc', 'sdkl', 'tfl', 'tfla', 'tflc', 'cmp', 'svm', 'svmt', 'svmsl', 'tflm', 'bnative-image', 'ni', 'nil', 'tflsm', 'snative-image-agent', 'snative-image-diagnostics-agent', 'ecs'], _suite, env_file='espresso-ni') # pylint: disable=line-too-long |
75 |
| -mx_sdk_vm.register_vm_config('espresso-ni-jvm-ce', ['java', 'ejvm', 'elau', 'ellvm', 'nfi-libffi', 'nfi', 'sdk', 'sdkni', 'sdkc', 'sdkl', 'tfl', 'tfla', 'tflc', 'cmp', 'antlr4', 'llrc', 'llrlf', 'llrn', 'svm', 'svmt', 'svmsl', 'tflm', 'bnative-image', 'ni', 'nil', 'tflsm', 'snative-image-agent', 'snative-image-diagnostics-agent', 'lg', 'sjavavm', 'bespresso', 'ecs'] + _llvm_toolchain_wrappers, _suite, env_file='espresso-ni-jvm') # pylint: disable=line-too-long |
|
0 commit comments