-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
mx_sdk_vm_impl.py
4798 lines (4097 loc) 路 231 KB
/
mx_sdk_vm_impl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#
# Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# The Universal Permissive License (UPL), Version 1.0
#
# Subject to the condition set forth below, permission is hereby granted to any
# person obtaining a copy of this software, associated documentation and/or
# data (collectively the "Software"), free of charge and under any and all
# copyright rights in the Software, and any and all patent rights owned or
# freely licensable by each licensor hereunder covering either (i) the
# unmodified Software as contributed to or provided by such licensor, or (ii)
# the Larger Works (as defined below), to deal in both
#
# (a) the Software, and
#
# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
# one is included with the Software each a "Larger Work" to which the Software
# is contributed by such licensors),
#
# without restriction, including without limitation the rights to copy, create
# derivative works of, display, perform, and distribute the Software and make,
# use, sell, offer for sale, import, export, have made, and have sold the
# Software and the Larger Work(s), and to sublicense the foregoing rights on
# either these or other terms.
#
# This license is subject to the following condition:
#
# The above copyright notice and either this complete permission notice or at a
# minimum a reference to the UPL must be included in all copies or substantial
# portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
from __future__ import print_function
from abc import ABCMeta
from argparse import ArgumentParser, RawTextHelpFormatter
from collections import OrderedDict
from zipfile import ZipFile
import hashlib
import io
import inspect
import json
import os
from os.path import relpath, join, dirname, basename, exists, isfile, normpath, abspath, isdir
import pprint
import re
import shlex
import shutil
import subprocess
import sys
import textwrap
import zipfile
try:
# Use more secure defusedxml library, if available
from defusedxml.ElementTree import parse as etreeParse
except ImportError:
from xml.etree.ElementTree import parse as etreeParse
import mx
import mx_gate
import mx_javamodules
import mx_jardistribution
import mx_native
import mx_subst
import mx_sdk
import mx_sdk_vm
import mx_util
if sys.version_info[0] < 3:
_unicode = unicode # pylint: disable=undefined-variable
def _decode(x):
return x
def _encode(x):
return x
else:
_unicode = str
def _decode(x):
return x.decode()
def _encode(x):
return x.encode()
def unicode_utf8(string):
if sys.version_info[0] < 3:
if isinstance(string, str):
return unicode(string, 'utf-8') # pylint: disable=undefined-variable
elif isinstance(string, bytes):
return str(string)
return string
_suite = mx.suite('sdk')
""":type: mx.SourceSuite | mx.Suite"""
_exe_suffix = mx.exe_suffix('')
_cmd_suffix = mx.cmd_suffix('')
""":type: str"""
_lib_suffix = mx.add_lib_suffix("")
_lib_prefix = mx.add_lib_prefix("")
_graalvm_base_name = 'GraalVM'
_registered_graalvm_components = {}
_project_name = 'graal'
_base_jdk_version_info = None
default_components = []
USE_LEGACY_GU = mx.str_to_bool(mx.get_env('LEGACY_GU', 'false'))
mx.add_argument('--base-dist-name', help='Sets the name of the GraalVM base image ( for complete, ruby ... images), default to "base"', default='base')
def svm_experimental_options(experimental_options):
return ['-H:+UnlockExperimentalVMOptions'] + experimental_options + ['-H:-UnlockExperimentalVMOptions']
mx_sdk_vm.register_graalvm_component(mx_sdk_vm.GraalVmJreComponent(
suite=_suite,
name='Polyglot Launcher',
short_name='poly',
license_files=[],
third_party_license_files=[],
dir_name='polyglot',
launcher_configs=[mx_sdk_vm.LauncherConfig(
destination='bin/<exe:polyglot>',
jar_distributions=['sdk:LAUNCHER_COMMON'],
main_class='org.graalvm.launcher.PolyglotLauncher',
build_args=[
'--features=org.graalvm.launcher.PolyglotLauncherFeature',
'--tool:all',
] + svm_experimental_options(['-H:-ParseRuntimeOptions']),
is_main_launcher=True,
default_symlinks=True,
is_sdk_launcher=True,
is_polyglot=True,
)],
))
def gate_body(args, tasks):
with mx_gate.Task('Sdk: GraalVM dist names', tasks, tags=['names']) as t:
if t:
mx_sdk_vm.verify_graalvm_configs()
mx_gate.add_gate_runner(_suite, gate_body)
def registered_graalvm_components(stage1=False):
"""
:type stage1: bool
:rtype: list[mx_sdk_vm.GraalVmComponent]
"""
if stage1 not in _registered_graalvm_components:
components_include_list = _components_include_list()
if components_include_list is None:
components_include_list = mx_sdk.graalvm_components()
excluded = _excluded_components()
components_to_build = []
libpoly_build_dependencies = []
libpoly_has_entrypoints = []
def is_excluded(component):
return component.name in excluded or component.short_name in excluded
def add_dependencies(dependencies, excludes=True):
components = dependencies[:]
while components:
component = components.pop(0)
if component not in components_to_build and not (excludes and is_excluded(component)):
components_to_build.append(component)
components.extend(component.direct_dependencies())
libpoly_build_dependencies.extend(component.polyglot_lib_build_dependencies)
if component.has_polyglot_lib_entrypoints:
libpoly_has_entrypoints.append(component.name)
# Expand dependencies
add_dependencies([mx_sdk.graalvm_component_by_name(name) for name in default_components], excludes=True)
add_dependencies(components_include_list, excludes=True)
# The polyglot library must be the last component that we register, since it depends on the other ones.
# To avoid registering it twice (once when `stage1 == False` and once when `stage1 == True`), we check that
# `libpoly` is not part of `registered_short_names`.
# Even when the polyglot library is already registered, we still need to add its dependencies to the current
# GraalVM (see call to `add_dependencies()`.
registered_short_names = [c.short_name for c in mx_sdk_vm.graalvm_components()]
if _with_polyglot_lib_project() and libpoly_has_entrypoints:
if 'libpoly' in registered_short_names:
libpolyglot_component = mx_sdk_vm.graalvm_component_by_name('libpoly')
else:
libpolyglot_component = mx_sdk_vm.GraalVmJreComponent(
suite=_suite,
name='Polyglot Library',
short_name='libpoly',
license_files=[],
third_party_license_files=[],
dir_name='polyglot',
library_configs=[mx_sdk_vm.LibraryConfig(
destination='<lib:polyglot>',
# We can ignore `component.polyglot_lib_jar_dependencies` because, when building a native image,
# the `GraalVmNativeImage` project has a build-time dependency to Stage1
jar_distributions=[],
build_args=[
'-J-Xms20G',
'-Dgraalvm.libpolyglot=true',
'-Dorg.graalvm.polyglot.install_name_id=@rpath/<jre_home>/lib/polyglot/<lib:polyglot>',
'--tool:all',
],
is_polyglot=True,
build_time=25,
)],
)
mx_sdk_vm.register_graalvm_component(libpolyglot_component)
add_dependencies([libpolyglot_component])
if libpoly_build_dependencies:
mx.warn("Ignoring build dependency '{}' of '{}'. It should be already part of stage 1.".format(libpoly_build_dependencies, libpolyglot_component.name))
ni_component = mx_sdk_vm.graalvm_component_by_name('ni', fatalIfMissing=False)
niee_component = mx_sdk_vm.graalvm_component_by_name('niee', fatalIfMissing=False)
if stage1:
if mx.suite('truffle', fatalIfMissing=False):
import mx_truffle
if has_component(mx_truffle.truffle_nfi_component.name, stage1=False):
svmnfi_component = mx_sdk_vm.graalvm_component_by_name('svmnfi', fatalIfMissing=False)
if svmnfi_component is not None:
# SVM support for Truffle NFI must be added to the stage1 distribution if the Truffle NFI
# component is part of the final distribution
add_dependencies([svmnfi_component], excludes=False)
# To build native launchers or libraries we need Native Image and its dependencies in stage1, even when
# these components are not included in the final distribution
if niee_component is not None:
add_dependencies([niee_component], excludes=False)
elif ni_component is not None:
add_dependencies([ni_component], excludes=False)
if ni_component is None:
# Remove GraalVMSvmMacro if the 'svm' component is not found, most likely because the `/substratevm` suite
# is not loaded
mx.logv("Cannot find 'ni' component; removing macros: {}".format([component.name for component in components_to_build if isinstance(component, mx_sdk.GraalVMSvmMacro)]))
components_to_build = [component for component in components_to_build if not isinstance(component, mx_sdk.GraalVMSvmMacro)]
mx.logv('Components: {}'.format([c.name for c in components_to_build]))
_registered_graalvm_components[stage1] = components_to_build
return _registered_graalvm_components[stage1]
def _get_component_type_base(c, graalvm_dist_for_substitutions=None):
if isinstance(c, mx_sdk.GraalVmLanguage):
result = '<jre_base>/languages/'
elif isinstance(c, mx_sdk.GraalVmTool):
result = '<jre_base>/tools/'
elif isinstance(c, mx_sdk.GraalVmJdkComponent):
result = '<jdk_base>/lib/'
elif isinstance(c, mx_sdk.GraalVmJreComponent):
result = '<jre_base>/lib/'
elif isinstance(c, mx_sdk.GraalVMSvmMacro):
# Get the 'svm' component, even if it's not part of the GraalVM image
svm_component = mx_sdk_vm.graalvm_component_by_name('svm', fatalIfMissing=True)
result = _get_component_type_base(svm_component, graalvm_dist_for_substitutions=graalvm_dist_for_substitutions) + svm_component.dir_name + '/macros/'
elif isinstance(c, mx_sdk.GraalVmComponent):
result = '<jdk_base>/'
else:
raise mx.abort("Unknown component type for {}: {}".format(c.name, type(c).__name__))
if graalvm_dist_for_substitutions is not None:
result = graalvm_dist_for_substitutions.path_substitutions.substitute(result)
return result
def _get_jdk_base(jdk):
jdk_dir = jdk.home
if jdk_dir.endswith(os.path.sep):
jdk_dir = jdk_dir[:-len(os.path.sep)]
if jdk_dir.endswith('/Contents/Home'):
jdk_base = 'Contents/Home'
jdk_dir = jdk_dir[:-len('/Contents/Home')]
else:
jdk_base = '.'
return jdk_dir, jdk_base
def _get_macros_dir():
svm_component = get_component('svm', stage1=True)
if not svm_component:
return None
return _get_component_type_base(svm_component) + svm_component.dir_name + '/macros'
def _get_main_component(components):
"""
:type components: list[mx_sdk_vm.GraalVmComponent]
:rtype: mx_sdk_vm.GraalVmComponent
"""
assert len(components)
main_component = min(components, key=lambda c: (c.priority, not has_svm_launcher(c))) # we prefer components with low priority and native launchers (note that this is a `min` function)
if any([comp for comp in components if comp != main_component and comp.priority == main_component.priority and has_svm_launcher(comp)]):
raise mx.abort("""\
Cannot determine the main component between:
- {}
More than one component has priority {} and native launchers.\
""".format('\n - '.join(['{} (has native launchers: {})'.format(c.name, has_svm_launcher(c)) for c in components]), main_component.priority))
return main_component
_src_jdk = mx_sdk_vm.base_jdk()
_src_jdk_version = mx_sdk_vm.base_jdk_version()
# Example:
# macOS:
# _src_jdk_dir = /Library/Java/JavaVirtualMachines/oraclejdk1.8.0_221-jvmci-19.2-b02
# _src_jdk_base = Contents/Home
# Others:
# _src_jdk_dir = $JAVA_HOME (e.g. /usr/lib/jvm/oraclejdk1.8.0_212-jvmci-19.2-b01)
# _src_jdk_base = .
_src_jdk_dir, _src_jdk_base = _get_jdk_base(_src_jdk)
""":type: dict[str, (str, str)]"""
_parent_info_cache = {}
def _graalvm_maven_attributes(tag='graalvm'):
"""
:type tag: str
:rtype: dict[str, str]
"""
return {'groupId': 'org.graalvm', 'tag': tag}
mx.add_argument('--no-jlinking', action='store_true', help='Do not jlink graal libraries in the generated JDK. Warning: The resulting VM will be HotSpot, not GraalVM.')
def _jlink_libraries():
return not (mx.get_opts().no_jlinking or mx.env_var_to_bool('NO_JLINKING'))
def get_graalvm_edition():
return 'ee' if mx_sdk_vm.graalvm_component_by_name('cmpee', fatalIfMissing=False) else 'ce'
class BaseGraalVmLayoutDistribution(mx.LayoutDistribution, metaclass=ABCMeta):
def __init__(self, suite, name, deps, components, is_graalvm, exclLibs, platformDependent, theLicense, testDistribution,
add_jdk_base=False,
base_dir=None,
path=None,
stage1=False,
include_native_image_resources_filelists=False,
**kw_args): # pylint: disable=super-init-not-called
self.components = components or registered_graalvm_components(stage1)
self.stage1 = stage1
self.skip_archive = stage1 or graalvm_skip_archive() # *.tar archives for stage1 distributions are never built
layout = {}
src_jdk_base = _src_jdk_base if add_jdk_base else '.'
assert src_jdk_base
base_dir = base_dir or '.'
if base_dir != '.':
self.jdk_base = '/'.join([base_dir, src_jdk_base]) if src_jdk_base != '.' else base_dir
else:
self.jdk_base = src_jdk_base
self.jre_base = self.jdk_base
path_substitutions = mx_subst.SubstitutionEngine(mx_subst.path_substitutions)
path_substitutions.register_no_arg('jdk_base', lambda: self.jdk_base)
path_substitutions.register_no_arg('jre_base', lambda: self.jre_base)
path_substitutions.register_no_arg('jre_home', lambda: relpath(self.jre_base, self.jdk_base))
string_substitutions = mx_subst.SubstitutionEngine(path_substitutions)
string_substitutions.register_no_arg('version', _suite.release_version)
string_substitutions.register_no_arg('graalvm_os', get_graalvm_os())
string_substitutions.register_with_arg('esc', lambda s: '<' + s + '>')
_layout_provenance = {}
self._post_build_warnings = []
self.jimage_jars = set()
self.jimage_ignore_jars = set()
if is_graalvm:
for component in self.components:
if component.jlink:
self.jimage_jars.update(component.boot_jars + component.jvmci_parent_jars)
if isinstance(component, mx_sdk.GraalVmJvmciComponent):
self.jimage_jars.update(component.jvmci_jars)
for component in mx_sdk_vm.graalvm_components():
if not component.jlink:
self.jimage_ignore_jars.update(component.jar_distributions)
self.jimage_ignore_jars.update(component.builder_jar_distributions)
for config in component.launcher_configs + component.library_configs:
if config.jar_distributions:
self.jimage_ignore_jars.update(config.jar_distributions)
if isinstance(component, mx_sdk_vm.GraalVmTruffleLibrary):
# In order to transition to Truffle Unchained we need to
# exclude Truffle libraries from the mechanism that produces
# dummy modules for qualified exports when boot modules are installed in
# the GraalVM JDK to be able to later load it from the module-path.
self.jimage_ignore_jars.update(component.boot_jars)
self.jimage_ignore_jars.update(component.jar_distributions)
self.jimage_ignore_jars.update(component.jvmci_parent_jars)
self.jimage_ignore_jars.update(component.builder_jar_distributions)
def _add(_layout, dest, src, component=None, with_sources=False):
"""
:type _layout: dict[str, list[str] | str]
:type dest: str
:type src: list[str | dict] | str | dict
"""
assert dest.startswith('<jdk_base>') or dest.startswith('<jre_base>') or base_dir == '.' or dest.startswith(base_dir), dest
src = src if isinstance(src, list) else [src]
if not src:
return
if not dest.endswith('/') and dest in _layout:
if dest not in _layout_provenance or _layout_provenance[dest] is None:
mx.abort(
"Can not override '{dest}' which is part of the base GraalVM layout. ({component} tried to set {dest}<-{src})".format(
dest=dest, src=src, component=component.name if component else None))
previous_component = _layout_provenance[dest]
if not component:
mx.abort(
"Suspicious override in GraalVM layout: tried to set {}<-{} without a component while it already existed ({} set it to {})".format(
dest, src, previous_component.name, _layout[dest]))
if component.priority <= previous_component.priority:
mx.logv("'Skipping '{}<-{}' from {c}' ({c}.priority={cp} <= {pc}.priority={pcp})".format(dest, src, c=component.name, pc=previous_component.name, cp=component.priority, pcp=previous_component.priority))
return
else:
_layout[dest] = []
mx.logvv("'Adding '{}: {}' to the layout'".format(dest, src))
_layout_provenance[dest] = component
for _src in list(src):
src_dict = mx.LayoutDistribution._as_source_dict(_src, name, dest)
if src_dict['source_type'] == 'dependency' and src_dict['path'] is None:
if with_sources and _include_sources(src_dict['dependency']) and (src_dict['dependency'] not in self.jimage_jars or not _jlink_libraries()):
src_src_dict = {
'source_type': 'dependency',
'dependency': src_dict['dependency'],
'path': '*.src.zip',
'optional': True,
'if_stripped': 'exclude',
}
src.append(src_src_dict)
_layout.setdefault(dest, []).extend(src)
def _patch_darwin_jdk():
"""
Since the jimage is added to `Contents/Home`, `incl_list` must contain `Contents/MacOS` and `Contents/Info.plist`, with a different CFBundleName
:rtype: list[(str, source_dict)]
"""
_incl_list = []
orig_info_plist = join(_src_jdk_dir, 'Contents', 'Info.plist')
if exists(orig_info_plist):
root = etreeParse(orig_info_plist)
found_el = False
for el in root.iter():
if el.tag == 'key' and el.text == 'CFBundleName':
found_el = True
elif found_el:
assert el.tag == 'string'
el.text = graalvm_vendor_version()
bio = io.BytesIO()
root.write(bio) # When porting to Python 3, we can use root.write(StringIO(), encoding="unicode")
plist_src = {
'source_type': 'string',
'value': _decode(bio.getvalue()),
'ignore_value_subst': True
}
_incl_list.append((base_dir + '/Contents/Info.plist', plist_src))
break
_incl_list.append((base_dir + '/Contents/MacOS', {
'source_type': 'file',
'path': join(_src_jdk_dir, 'Contents', 'MacOS')
}))
return _incl_list
svm_component = get_component('svm', stage1=True)
def _add_native_image_macro(image_config, component, stage1):
# Add the macros if SubstrateVM is included, as images could be created later with an installable Native Image
if svm_component and (component is None or has_component(component.short_name, stage1=False)):
# create macro to build this launcher
_macro_dir = _get_macros_dir() + '/' + GraalVmNativeProperties.macro_name(image_config) + '/'
_project_name = GraalVmNativeProperties.project_name(image_config, stage1)
_add(layout, _macro_dir, 'dependency:{}'.format(_project_name), component) # native-image.properties is the main output
# Add profiles
for profile in _image_profiles(GraalVmNativeProperties.canonical_image_name(image_config)):
_add(layout, _macro_dir, 'file:{}'.format(abspath(profile)))
def _add_link(_dest, _target, _component=None, _dest_base_name=None):
assert _dest.endswith('/')
_linkname = relpath(path_substitutions.substitute(_target), start=path_substitutions.substitute(_dest[:-1]))
dest_base_name = _dest_base_name or basename(_target)
if _linkname != dest_base_name:
if mx.is_windows():
if _target.endswith('.exe') or _target.endswith('.cmd'):
link_template_name = join(_suite.mxDir, 'vm', 'exe_link_template.cmd')
with open(link_template_name, 'r') as template:
_template_subst = mx_subst.SubstitutionEngine(mx_subst.string_substitutions)
_template_subst.register_no_arg('target', normpath(_linkname))
contents = _template_subst.substitute(template.read())
full_dest = _dest + dest_base_name[:-len('.exe')] + '.cmd'
_add(layout, full_dest, 'string:{}'.format(contents), _component)
return full_dest
else:
mx.abort("Cannot create link on windows for {}->{}".format(_dest, _target))
else:
_add(layout, _dest + dest_base_name, 'link:{}'.format(_linkname), _component)
return _dest + dest_base_name
if is_graalvm:
if stage1:
# 1. we do not want a GraalVM to be used as base-JDK
# 2. we don't need to check if the base JDK is JVMCI-enabled, since JVMCIVersionCheck takes care of that when the GraalVM compiler is a registered component
check_versions(_src_jdk, expect_graalvm=False, check_jvmci=False)
# Add base JDK
if mx.get_os() == 'darwin':
# Since on Darwin the jimage is added to `Contents/Home`, `incl_list` must contain `Contents/MacOS` and `Contents/Info.plist`
incl_list = _patch_darwin_jdk()
for d, s in incl_list:
_add(layout, d, s)
jimage_exclusion_list = ['lib/jvm.cfg']
if not stage1:
for lc, c in [(lc, c) for c in self.components for lc in c.library_configs if lc.add_to_module]:
assert isinstance(c, (mx_sdk.GraalVmJreComponent, mx_sdk.GraalVmJdkComponent)), "'{}' is not a GraalVmJreComponent nor a GraalVmJdkComponent but defines a library config ('{}') with 'add_to_module' attribute".format(c.name, lc.destination)
assert not lc.add_to_module.endswith('.jmod'), "Library config '{}' of component '{}' has an invalid 'add_to_module' attribute: '{}' cannot end with '.jmod'".format(lc.destination, c.name, lc.add_to_module)
assert all(c not in lc.add_to_module for c in ('/', '\\')), "Library config '{}' of component '{}' has an invalid 'add_to_module' attribute: '{}' cannot contain '/' or '\\'".format(lc.destination, c.name, lc.add_to_module)
jmod_file = lc.add_to_module + '.jmod'
jimage_exclusion_list.append('jmods/' + jmod_file)
_add(layout, '<jre_base>/jmods/' + jmod_file, 'dependency:' + JmodModifier.project_name(jmod_file))
mx.logv("jimage_exclusion_list of {}: {}".format(name, jimage_exclusion_list))
_add(layout, self.jdk_base + '/', {
'source_type': 'dependency',
'dependency': 'graalvm-stage1-jimage' if stage1 and _needs_stage1_jimage(self, get_final_graalvm_distribution()) else 'graalvm-jimage',
'path': '*',
'exclude': jimage_exclusion_list,
})
# Add the rest of the GraalVM
component_suites = {}
installable_component_lists = {}
_macros_dir = _get_macros_dir()
_libpolyglot_component = mx_sdk_vm.graalvm_component_by_name('libpoly', fatalIfMissing=False)
assert _libpolyglot_component is None or len(_libpolyglot_component.library_configs) == 1
_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
graalvm_dists = set() # the jar distributions mentioned by launchers and libraries
component_dists = set() # the jar distributions directly mentioned by components
_lang_homes_with_ni_resources = []
jvm_configs = {}
for _component in sorted(self.components, key=lambda c: c.name):
mx.logv('Adding {} ({}) to the {} {}'.format(_component.name, _component.__class__.__name__, name, self.__class__.__name__))
_component_type_base = _get_component_type_base(_component)
if isinstance(_component, (mx_sdk.GraalVmJreComponent, mx_sdk.GraalVmJdkComponent)):
if mx.get_os() == 'windows':
_component_jvmlib_base = _component_type_base[:-len('lib/')] + 'bin/'
else:
_component_jvmlib_base = _component_type_base
elif mx.get_os() == 'windows':
_component_jvmlib_base = '<jre_base>/bin/'
else:
_component_jvmlib_base = '<jre_base>/lib/'
_jvm_library_dest = _component_jvmlib_base
if _component.dir_name:
_component_base = _component_type_base + _component.dir_name + '/'
else:
_component_base = _component_type_base
if not _jlink_libraries():
_add(layout, '<jre_base>/lib/jvmci/', ['dependency:' + d for d in _component.boot_jars], _component, with_sources=True)
_add(layout, _component_base, ['dependency:' + d for d in _component.jar_distributions + _component.jvmci_parent_jars], _component, with_sources=True)
_add(layout, _component_base + 'builder/', ['dependency:' + d for d in _component.builder_jar_distributions], _component, with_sources=True)
_add(layout, _component_base, [{
'source_type': 'extracted-dependency',
'dependency': d,
'exclude': _component.license_files if _no_licenses() else [],
'path': None,
} for d in _component.support_distributions], _component)
if include_native_image_resources_filelists and isinstance(_component, mx_sdk.GraalVmLanguage) and _component.support_distributions:
# A support distribution of a GraalVmLanguage component might have the `fileListPurpose` attribute with value 'native-image-resources' specifying that all the files from the distribution should
# be used as native image resources. Any value of the attribute other than 'native-image-resources' or None for a support distribution of a GraalVmLanguage is invalid. If the attribute is specified,
# there is a '<distribution archive file path>.filename' file containing a file list of all the files from the distribution. The support distributions specifying the attribute together specify
# a subset of files from this component's home directory. The file lists will be merged by the NativeImageResourcesFileList project into a single file `native-image-resources.filelist` that will be
# written into this component's home directory. As a part of a native image build that includes this component, the files in the merged file list will be copied as resources to a directory named
# `resources` next to the produced image. This impacts only the native images built by GraalVM that are not a part of the GraalVM itself.
if not _component_base in _lang_homes_with_ni_resources:
_add(layout, _component_base, 'dependency:{}/native-image-resources.filelist'.format(NativeImageResourcesFileList.project_name(_component.dir_name)), _component)
_lang_homes_with_ni_resources.append(_component_base)
_add(layout, '<jdk_base>/include/', [{
'source_type': 'extracted-dependency',
'dependency': d,
'exclude': [],
'path': None,
} for d in _component.support_headers_distributions], _component)
_add(layout, _jvm_library_dest, [{
'source_type': 'extracted-dependency',
'dependency': d,
'exclude': [],
'path': None,
} for d in _component.support_libraries_distributions], _component)
if isinstance(_component, mx_sdk.GraalVmJvmciComponent) and (not _jlink_libraries()):
_add(layout, '<jre_base>/lib/jvmci/', ['dependency:' + d for d in _component.jvmci_jars], _component, with_sources=True)
if isinstance(_component, mx_sdk.GraalVmJdkComponent):
_jdk_jre_bin = '<jdk_base>/bin/'
else:
_jdk_jre_bin = '<jre_base>/bin/'
_licenses = _component.third_party_license_files
if not _no_licenses():
_licenses = _licenses + _component.license_files
for _license in _licenses:
if mx.is_windows() or isinstance(self, mx.AbstractJARDistribution):
if _component_base == '<jdk_base>/':
pass # already in place from the support dist
elif len(_component.support_distributions) == 1:
_support = _component.support_distributions[0]
_add(layout, '<jdk_base>/', 'extracted-dependency:{}/{}'.format(_support, _license), _component)
elif any(_license.startswith(sd + '/') for sd in _component.support_distributions):
_add(layout, '<jdk_base>/', 'extracted-dependency:{}'.format(_license), _component)
else:
mx.warn("Can not add license: " + _license)
else:
for sd in _component.support_distributions:
if _license.startswith(sd + '/'):
_add_link('<jdk_base>/', _component_base + _license[len(sd) + 1:], _component)
break
else:
_add_link('<jdk_base>/', _component_base + _license, _component)
_jre_bin_names = []
for _launcher_config in sorted(_get_launcher_configs(_component), key=lambda c: c.destination):
graalvm_dists.update(_launcher_config.jar_distributions)
self.jimage_ignore_jars.update(_launcher_config.jar_distributions)
_launcher_dest = _component_base + GraalVmLauncher.get_launcher_destination(_launcher_config, stage1)
# 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)
if _include_sources(launcher_project):
_add(layout, dirname(_launcher_dest) + '/', 'dependency:' + launcher_project + '/sources', _component)
# add links from jre/bin to launcher
if _launcher_config.default_symlinks:
_link_path = _add_link(_jdk_jre_bin, _launcher_dest, _component)
_jre_bin_names.append(basename(_link_path))
for _component_link in _launcher_config.links:
_link_dest = _component_base + _component_link
# add links `LauncherConfig.links` -> `LauncherConfig.destination`
_link_dest_dir, _link_dest_base_name = os.path.split(_link_dest)
_add_link(_link_dest_dir + '/', _launcher_dest, _component, _dest_base_name=_link_dest_base_name)
# add links from jre/bin to component link
if _launcher_config.default_symlinks:
_link_path = _add_link(_jdk_jre_bin, _link_dest, _component)
_jre_bin_names.append(basename(_link_path))
if stage1 or _rebuildable_image(_launcher_config):
_add_native_image_macro(_launcher_config, _component, stage1)
if isinstance(_launcher_config, mx_sdk.LanguageLauncherConfig):
_add(layout, _component_base, 'dependency:{}/polyglot.config'.format(launcher_project), _component)
for _library_config in sorted(_get_library_configs(_component), key=lambda c: c.destination):
if stage1 or _rebuildable_image(_library_config) or isinstance(_library_config, mx_sdk_vm.LanguageLibraryConfig):
# language libraries can run in `--jvm` mode
graalvm_dists.update(_library_config.jar_distributions)
self.jimage_ignore_jars.update(_library_config.jar_distributions)
if _library_config.jvm_library:
assert isinstance(_component, (mx_sdk.GraalVmJdkComponent, mx_sdk.GraalVmJreComponent))
_svm_library_home = _jvm_library_dest
else:
_svm_library_home = _component_base
_svm_library_dest = _svm_library_home + _library_config.destination
if not stage1 and _get_svm_support().is_supported():
_source_type = 'skip' if _skip_libraries(_library_config) else 'dependency'
_library_project_name = GraalVmNativeImage.project_name(_library_config)
# add `LibraryConfig.destination` and the generated header files to the layout
_add(layout, _svm_library_dest, _source_type + ':' + _library_project_name, _component)
if _library_config.headers:
_add(layout, _svm_library_home, _source_type + ':' + _library_project_name + '/*.h', _component)
if _debug_images() and not _skip_libraries(_library_config) and _get_svm_support().generate_debug_info(_library_config):
if _get_svm_support().generate_separate_debug_info(_library_config):
_add(layout, dirname(_svm_library_dest) + '/', 'dependency:' + _library_project_name + '/*' + _get_svm_support().separate_debuginfo_ext(), _component)
if _include_sources(_library_config):
_add(layout, dirname(_svm_library_dest) + '/', 'dependency:' + _library_project_name + '/sources', _component)
if not stage1 and isinstance(_library_config, mx_sdk.LanguageLibraryConfig) and _library_config.launchers:
_add(layout, _component_base, 'dependency:{}/polyglot.config'.format(PolyglotConfig.project_name(_library_config)), _component)
# add native launchers for language libraries
for _executable in _library_config.launchers:
_add(layout, join(_component_base, _executable), 'dependency:{}'.format(NativeLibraryLauncherProject.library_launcher_project_name(_library_config)), _component)
_link_path = _add_link(_jdk_jre_bin, _component_base + _executable)
_jre_bin_names.append(basename(_link_path))
if stage1 or _rebuildable_image(_library_config):
_add_native_image_macro(_library_config, _component, stage1)
graalvm_dists.update(_component.polyglot_lib_jar_dependencies)
if _libpolyglot_macro_dir is not None and GraalVmLibPolyglotNativeProperties.needs_lib_polyglot_native_properties(_component):
_add(layout, _libpolyglot_macro_dir, 'dependency:' + _libpolyglot_macro_dist_name(_component))
if not _jlink_libraries():
component_dists.update(_component.boot_jars)
component_dists.update(_component.jar_distributions)
component_dists.update(_component.jvmci_parent_jars)
component_dists.update(_component.builder_jar_distributions)
for _provided_executable in _component.provided_executables:
if isinstance(_provided_executable, tuple):
# copied executable
_src_dist, _executable = _provided_executable
_executable = mx_subst.results_substitutions.substitute(_executable)
_add(layout, _jdk_jre_bin, 'extracted-dependency:{}/{}'.format(_src_dist, _executable), _component)
else:
# linked executable
_link_dest = _component_base + mx_subst.results_substitutions.substitute(_provided_executable)
_link_path = _add_link(_jdk_jre_bin, _link_dest, _component)
_jre_bin_names.append(basename(_link_path))
if isinstance(_component, mx_sdk.GraalVmLanguage) and not is_graalvm:
# add language-specific release file
component_suites.setdefault(_component_base, []).append(_component.suite)
if _component.installable:
installable_component_lists.setdefault(_component.installable_id, []).append(_component)
if not stage1:
for jvm_config in _component.jvm_configs:
supported_keys = ('configs', 'priority')
if any(key not in supported_keys for key in jvm_config.keys()):
raise mx.abort("Component '{}' defines a jvm_config with an unsupported property: '{}'. Supported properties are: {}".format(_component.name, jvm_config, supported_keys))
for supported_key in supported_keys:
if supported_key not in jvm_config:
raise mx.abort("Component '{}' defines a jvm_config that misses the '{}' property: '{}'".format(_component.name, supported_key, jvm_config))
if not isinstance(jvm_config['configs'], list):
raise mx.abort("The type of the 'configs' property of a jvm_config defined by component '{}' must be 'list': '{}'".format(_component.name, jvm_config))
priority = jvm_config['priority']
if callable(priority):
priority = priority()
if not isinstance(priority, int):
raise mx.abort("The type of the 'priority' property of a jvm_config defined by component '{}' must be 'int' or a callable that returns an int: '{}'".format(_component.name, jvm_config))
if priority == 0:
raise mx.abort("Component '{}' registers a jvm_config with default priority (0): '{}'\nSet a priority less than 0 to prepend to the default list of JVMs and more than 0 to append.".format(_component.name, jvm_config))
if priority in jvm_configs:
raise mx.abort("Two components define jvm_configs with the same priority:\n1. '{}': {}\n2. '{}': {}".format(jvm_configs[priority]['source'], jvm_configs[priority]['configs'], _component.name, jvm_config['configs']))
jvm_configs[priority] = {
'configs': jvm_config['configs'],
'source': _component.name,
}
if is_graalvm:
_add(layout, "<jre_base>/lib/jvm.cfg", "string:" + _get_jvm_cfg_contents(jvm_configs))
graalvm_dists.difference_update(component_dists)
_add(layout, '<jre_base>/lib/graalvm/', ['dependency:' + d for d in sorted(graalvm_dists)], with_sources=True)
for _base, _suites in component_suites.items():
_metadata = self._get_metadata(_suites)
_add(layout, _base + 'release', "string:{}".format(_metadata))
if "archive_factory" not in kw_args and self.skip_archive:
kw_args["archive_factory"] = mx.NullArchiver
super(BaseGraalVmLayoutDistribution, self).__init__(suite, name, deps, layout, path, platformDependent,
theLicense, exclLibs, path_substitutions=path_substitutions,
string_substitutions=string_substitutions,
testDistribution=testDistribution, **kw_args)
self.reset_user_group = True
mx.logvv("'{}' has layout:\n{}".format(self.name, pprint.pformat(self.layout)))
def getBuildTask(self, args):
return BaseGraalVmLayoutDistributionTask(args, self)
def needsUpdate(self, newestInput):
if self.skip_archive:
# When the distribution is not archived we cannot rely only on the archive file.
# Therefore, we must compare the contents of the output directory.
output = self.get_output()
if exists(output):
ts = mx.TimeStampFile(output)
if newestInput and ts.isOlderThan(newestInput):
return "{} is older than {}".format(ts, newestInput)
else:
return None
else:
return "{} does not exist".format(output)
else:
return super(BaseGraalVmLayoutDistribution, self).needsUpdate(newestInput)
@staticmethod
def _get_metadata(suites, parent_release_file=None):
"""
:type suites: list[mx.Suite]
:type parent_release_file: str | None
:rtype: str
"""
_commit_info = {}
for _s in suites:
if _s.vc:
if _s.vc_dir not in _parent_info_cache:
_parent_info_cache.setdefault(_s.vc_dir, (_s.vc.parent_info(_s.vc_dir), _s.vc.parent(_s.vc_dir)))
_info, _parent_rev = _parent_info_cache[_s.vc_dir]
_commit_info[_s.name] = {
"commit.rev": _parent_rev,
"commit.committer": _info['committer'] if _s.vc.kind != 'binary' else 'unknown',
"commit.committer-ts": _info['committer-ts'],
}
if parent_release_file:
_metadata_dict = mx_sdk_vm.parse_release_file(parent_release_file)
else:
_metadata_dict = OrderedDict()
_metadata_dict.setdefault('JAVA_VERSION', _src_jdk.version)
_metadata_dict.setdefault('OS_NAME', get_graalvm_os())
_metadata_dict.setdefault('OS_ARCH', mx.get_arch())
if mx.get_os_variant():
_metadata_dict.setdefault('OS_VARIANT', mx.get_os_variant())
_metadata_dict['GRAALVM_VERSION'] = _suite.release_version()
_source = _metadata_dict.get('SOURCE') or ''
if _source:
_source += ' '
_source += ' '.join(['{}:{}'.format(_s.name, _s.version()) for _s in suites])
_metadata_dict['SOURCE'] = _source
_metadata_dict['COMMIT_INFO'] = json.dumps(_commit_info, sort_keys=True)
# COMMIT_INFO is unquoted to simplify JSON parsing
return mx_sdk_vm.format_release_file(_metadata_dict, {'COMMIT_INFO'})
def get_artifact_metadata(self):
return {'edition': get_graalvm_edition(), 'type': mx.get_opts().base_dist_name, 'project': _project_name}
class BaseGraalVmLayoutDistributionTask(mx.LayoutArchiveTask):
def build(self):
assert isinstance(self.subject, BaseGraalVmLayoutDistribution)
super(BaseGraalVmLayoutDistributionTask, self).build()
for warning in self.subject._post_build_warnings:
mx.warn(warning, context=self)
if mx.is_windows():
LayoutSuper = mx.LayoutZIPDistribution
else:
LayoutSuper = mx.LayoutTARDistribution
class AbstractGraalVmLayoutDistribution(BaseGraalVmLayoutDistribution):
def __init__(self, base_name, theLicense=None, stage1=False, components=None, include_native_image_resources_filelists=None, add_component_dependencies=True, is_graalvm=True, add_jdk_base=True, allow_incomplete_launchers=False, **kw_args):
self.base_name = base_name
_include_native_image_resources_filelists = not stage1 if include_native_image_resources_filelists is None else include_native_image_resources_filelists
if components is None:
components_with_dependencies = []
elif add_component_dependencies:
components_with_dependencies = AbstractGraalVmLayoutDistribution._add_dependencies(components)
else:
components_with_dependencies = components
if not allow_incomplete_launchers and components_with_dependencies is not None:
for c in components_with_dependencies:
if c.launcher_configs or c.library_configs:
mx.abort('Cannot define a GraalVM layout distribution with a forced list of components that includes launcher or library configs. '
'The corresponding projects refer to the global stage1 and final GraalVM distributions.')
if is_graalvm:
name, base_dir, self.vm_config_name = _get_graalvm_configuration(base_name, components=components_with_dependencies, stage1=stage1)
else:
name = base_name
base_dir = base_name.lower().replace('_', '-')
self.vm_config_name = None
super(AbstractGraalVmLayoutDistribution, self).__init__(
suite=_suite,
name=name,
deps=[],
components=components_with_dependencies,
is_graalvm=is_graalvm,
exclLibs=[],
platformDependent=True,
theLicense=theLicense,
testDistribution=False,
add_jdk_base=add_jdk_base,
base_dir=base_dir,
path=None,
stage1=stage1,
include_native_image_resources_filelists=_include_native_image_resources_filelists,
**kw_args)
@staticmethod
def _add_dependencies(components, excluded_components=None):
components_with_repetitions = components[:]
components_with_dependencies = []
excluded_components = excluded_components or []
while components_with_repetitions:
component = components_with_repetitions.pop(0)
if component not in components_with_dependencies and component not in excluded_components:
components_with_dependencies.append(component)
components_with_repetitions.extend(component.direct_dependencies())
return components_with_dependencies
def extra_suite_revisions_data(self):
base_jdk_info = _base_jdk_info()
if self == get_final_graalvm_distribution() and base_jdk_info:
assert len(base_jdk_info) == 2
yield "basejdk", {
"name": base_jdk_info[0],
"version": base_jdk_info[1]
}
def remoteName(self, platform=None):
remote_name = super(AbstractGraalVmLayoutDistribution, self).remoteName(platform=platform)
# maven artifactId cannot contain '+'
# Example: 'graalvm-community-openjdk-17.0.7+4.1-linux-amd64' -> 'graalvm-community-openjdk-17.0.7-4.1-linux-amd64'
return remote_name.replace('+', '-')
class GraalVmLayoutDistribution(AbstractGraalVmLayoutDistribution, LayoutSuper): # pylint: disable=R0901
def __init__(self, base_name, **kw_args):
super(GraalVmLayoutDistribution, self).__init__(base_name, **kw_args)
def getBuildTask(self, args):
return GraalVmLayoutDistributionTask(args, self, 'latest_graalvm', 'latest_graalvm_home')
class GraalVmLayoutCompressedTARDistribution(AbstractGraalVmLayoutDistribution, mx.LayoutTARDistribution): # pylint: disable=R0901
def __init__(self, base_name, **kw_args):
super(GraalVmLayoutCompressedTARDistribution, self).__init__(base_name, compress=True, **kw_args)
def compress_locally(self):
return True
def compress_remotely(self):
return True
def getBuildTask(self, args):
return GraalVmLayoutDistributionTask(args, self)
def _components_set(components=None, stage1=False):
components = components or registered_graalvm_components(stage1)
components_set = set([c.short_name for c in components])
if stage1:
components_set.add('stage1')
elif mx_sdk_vm.graalvm_component_by_name('ni', fatalIfMissing=False) is not None:
# forced bash launchers and skipped libraries only make a difference if Native Image is involved in the build
for component in components:
for launcher_config in _get_launcher_configs(component):
simple_name = remove_exe_suffix(basename(launcher_config.destination))
if _force_bash_launchers(launcher_config):
components_set.add('b' + simple_name)
if not _rebuildable_image(launcher_config):
components_set.add('nr_lau_' + simple_name)
for library_config in _get_library_configs(component):
simple_name = remove_lib_prefix_suffix(basename(library_config.destination))
if _skip_libraries(library_config):
components_set.add('s' + simple_name)
if not _rebuildable_image(library_config):
components_set.add('nr_lib_' + simple_name)
if _no_licenses():
components_set.add('nolic')
return components_set
_graal_vm_configs_cache = {}
def _get_graalvm_configuration(base_name, components=None, stage1=False):
key = base_name, stage1
if key not in _graal_vm_configs_cache:
components_set = _components_set(components, stage1)
# Use custom distribution name and base dir for registered vm configurations
vm_dist_name = None
vm_config_name = None
for dist_name, config_name, config_components, _, _ in mx_sdk_vm._vm_configs:
config_components_set = set(config_components)
if components_set == config_components_set:
vm_dist_name = dist_name.replace('-', '_')
vm_config_name = config_name.replace('-', '_')