def image_server_start(args, dumpArgs=False, timeout=None): """Run an SVM image build server on a defined port. If the port is not defined, the server is started on the default port 26681. In case a server is already running command will not start a new server. This is a convenience for downstream projects so they can always run `image_server_start` in their builds to obviate the need for developers to keep track of their servers. Options: -port=<port_number> port of the build server """ if dumpArgs: print(' '.join(['image_server_start'] + args)) port = extractPortNumber(args) running = image_server_running(port) if running: print("Native image build server is already running.") else: classpath = _classpath([svmDistribution]) extraVmArgs, extraNormalArgs = _parse_standard_arguments(False, args) vmArgs, normalArgs = mx.extract_VM_args(args, useDoubleDash=True, defaultAllVMArgs=False) noTruffleRuntimeVmArgs = [ arg for arg in vmArgs + extraVmArgs if not arg.startswith('-Dtruffle.TruffleRuntime=') ] run_java(['-Xss10m', '-Xms2G'] + GRAAL_COMPILER_FLAGS + ['-cp', classpath] + noTruffleRuntimeVmArgs + [ 'com.oracle.svm.hosted.server.NativeImageBuildServer', PORT_PREFIX + str(port) ] + normalArgs + extraNormalArgs, timeout=timeout)
def native_image_on_jvm(args, **kwargs): save_args = [] for arg in args: if arg == '--no-server' or arg.startswith('--server'): mx.warn('Ignoring server-mode native-image argument ' + arg) else: save_args.append(arg) driver_cp = [ join(suite_native_image_root(), 'lib', subdir, '*.jar') for subdir in ['boot', 'jvmci', 'graalvm'] ] driver_cp += [ join(suite_native_image_root(), 'lib', 'svm', tail) for tail in ['*.jar', join('builder', '*.jar')] ] driver_cp = list( itertools.chain.from_iterable(glob.glob(cp) for cp in driver_cp)) svm_version = suite.release_version(snapshotSuffix='SNAPSHOT') run_java([ '-Dorg.graalvm.version=' + svm_version, '-Dnative-image.root=' + suite_native_image_root(), '-cp', os.pathsep.join(driver_cp), mx.dependency('substratevm:SVM_DRIVER').mainClass ] + save_args, **kwargs)
def native_image_on_jvm(args, **kwargs): save_args = [] for arg in args: if arg == '--no-server' or arg.startswith('--server'): mx.warn('Ignoring server-mode native-image argument ' + arg) else: save_args.append(arg) driver_cp = [join(suite_native_image_root(), 'lib', subdir, '*.jar') for subdir in ['boot', 'jvmci', 'graalvm']] driver_cp += [join(suite_native_image_root(), 'lib', 'svm', tail) for tail in ['*.jar', join('builder', '*.jar')]] driver_cp = list(itertools.chain.from_iterable(glob.glob(cp) for cp in driver_cp)) run_java(['-Dnative-image.root=' + suite_native_image_root(), '-cp', ":".join(driver_cp), mx.dependency('substratevm:SVM_DRIVER').mainClass] + save_args, **kwargs)
def _image_server_client(port, command, arguments, out=sys.stdout, err=sys.stderr): client_classpath = _classpath([svmDistribution]) client_command = [ '-cp', client_classpath, 'com.oracle.svm.hosted.server.NativeImageBuildClient', PORT_PREFIX + str(port) ] run_java(client_command + ['-command=' + command] + arguments, out=out, err=err)
def native_image_on_jvm(args): driver_cp = [ join(suite_native_image_root(), 'lib', subdir, '*.jar') for subdir in ['boot', 'jvmci', 'graalvm'] ] driver_cp += [ join(suite_native_image_root(), 'lib', 'svm', tail) for tail in ['*.jar', join('builder', '*.jar')] ] driver_cp = list( itertools.chain.from_iterable(glob.glob(cp) for cp in driver_cp)) run_java([ '-Dnative-image.root=' + suite_native_image_root(), '-cp', ":".join(driver_cp), mx.dependency('substratevm:SVM_DRIVER').mainClass ] + args)
def run_executable(server, port, vmArgs, task, compilerClasspath, imageClasspath, imageGenArgs, timeout=None, **kwargs): if server: return build_in_server(task, port, vmArgs, imageClasspath, imageGenArgs) else: allArgs = ['-Xss10m', '-Xms2G'] + GRAAL_COMPILER_FLAGS + vmArgs + [ '-cp', compilerClasspath, task, '-imagecp', imageClasspath ] + imageGenArgs return run_java(allArgs, timeout=timeout, **kwargs)
def bootstrap_native_image(native_image_root, svmDistribution, graalDistribution, librarySupportDistribution): if not allow_native_image_build: mx.logv( 'Detected building with ejc + --warning-as-error -> suppress bootstrap_native_image' ) return bootstrap_command = list(GRAAL_COMPILER_FLAGS) bootstrap_command += locale_US_args() bootstrap_command += substratevm_version_args() bootstrap_command += ['-Dgraalvm.version=dev'] builder_classpath = classpath(svmDistribution) imagecp_classpath = classpath(svmDistribution + ['substratevm:SVM_DRIVER']) bootstrap_command += [ '-cp', builder_classpath, 'com.oracle.svm.hosted.NativeImageGeneratorRunner', '-imagecp', imagecp_classpath, '-H:CLibraryPath=' + clibrary_libpath() ] bootstrap_command += [ '-H:Path=' + dirname(native_image_path(native_image_root)), '-H:Class=com.oracle.svm.driver.NativeImage', '-H:Name=' + basename(native_image_path(native_image_root)), '-H:-TruffleFeature', '-H:-ParseRuntimeOptions', '-H:ReflectionConfigurationResources=com/oracle/svm/driver/ReflectionConfiguration.json' ] if mx._opts.strip_jars: bootstrap_command += ['-H:-VerifyNamingConventions'] run_java(bootstrap_command) mx.logv('Built ' + native_image_path(native_image_root)) def native_image_layout_dists(subdir, dists): native_image_dists = [mx.dependency(dist_name) for dist_name in dists] native_image_layout(native_image_dists, subdir, native_image_root) # Create native-image layout for sdk parts native_image_layout_dists(join('lib', 'boot'), ['sdk:GRAAL_SDK']) native_image_layout_dists(join('lib', 'graalvm'), ['sdk:LAUNCHER_COMMON']) # Create native-image layout for compiler & jvmci parts native_image_layout_dists(join('lib', 'jvmci'), graalDistribution) jdk_config = mx.get_jdk() jvmci_path = join(jdk_config.home, 'jre', 'lib', 'jvmci') for symlink_name in os.listdir(jvmci_path): relsymlink(join(jvmci_path, symlink_name), join(native_image_root, 'lib', 'jvmci', symlink_name)) # Create native-image layout for truffle parts native_image_layout_dists(join('lib', 'truffle'), ['truffle:TRUFFLE_API']) # Create native-image layout for tools parts native_image_layout_dists(join('tools', 'junit', 'builder'), ['mx:JUNIT_TOOL', 'JUNIT', 'HAMCREST']) native_image_option_properties('tools', 'junit', native_image_root) native_image_option_properties('tools', 'truffle', native_image_root) native_image_layout_dists(join('tools', 'nfi', 'builder'), ['truffle:TRUFFLE_NFI']) native_image_option_properties('tools', 'nfi', native_image_root) # Create native-image layout for svm parts svm_subdir = join('lib', 'svm') native_image_layout_dists(svm_subdir, librarySupportDistribution) native_image_layout_dists( join(svm_subdir, 'builder'), svmDistribution + ['substratevm:POINTSTO', 'substratevm:OBJECTFILE']) for clibrary_path in clibrary_paths(): copy_tree(clibrary_path, join(native_image_root, join(svm_subdir, 'clibraries'))) # Finally create symlink to native-image in svm_suite().dir native_image_symlink_path = join( svm_suite().dir, basename(native_image_path(native_image_root))) if islink(native_image_symlink_path): os.remove(native_image_symlink_path) relsymlink(native_image_path(native_image_root), native_image_symlink_path)
def bootstrap_native_image(native_image_root, svmDistribution, graalDistribution, librarySupportDistribution): if not allow_native_image_build: mx.logv( 'Detected building with ejc + --warning-as-error -> suppress bootstrap_native_image' ) return bootstrap_command = list(GRAAL_COMPILER_FLAGS) bootstrap_command += locale_US_args() bootstrap_command += substratevm_version_args() bootstrap_command += ['-Dgraalvm.version=dev'] builder_classpath = classpath(svmDistribution) imagecp_classpath = classpath(svmDistribution + ['substratevm:SVM_DRIVER']) bootstrap_command += [ '-cp', builder_classpath, 'com.oracle.svm.hosted.NativeImageGeneratorRunner', '-imagecp', imagecp_classpath, '-H:CLibraryPath=' + clibrary_libpath() ] bootstrap_command += [ '-H:Path=' + dirname(native_image_path(native_image_root)), '-H:Class=com.oracle.svm.driver.NativeImage', '-H:Name=' + basename(native_image_path(native_image_root)), '-H:-ParseRuntimeOptions' ] if mx._opts.strip_jars: bootstrap_command += ['-H:-VerifyNamingConventions'] run_java(bootstrap_command) mx.logv('Built ' + native_image_path(native_image_root)) def names_to_dists(dist_names): return [mx.dependency(dist_name) for dist_name in dist_names] def native_image_layout_dists(subdir, dist_names): native_image_layout(names_to_dists(dist_names), subdir, native_image_root) def native_image_extract_dists(subdir, dist_names): native_image_extract(names_to_dists(dist_names), subdir, native_image_root) # Create native-image layout for sdk parts native_image_layout_dists(join('lib', 'boot'), ['sdk:GRAAL_SDK']) native_image_layout_dists(join('lib', 'graalvm'), ['sdk:LAUNCHER_COMMON']) # Create native-image layout for compiler & jvmci parts native_image_layout_dists(join('lib', 'jvmci'), graalDistribution) jdk_config = mx.get_jdk() jvmci_path = join(jdk_config.home, 'jre', 'lib', 'jvmci') for symlink_name in os.listdir(jvmci_path): relsymlink(join(jvmci_path, symlink_name), join(native_image_root, 'lib', 'jvmci', symlink_name)) # Create native-image layout for truffle parts native_image_layout_dists(join('lib', 'truffle'), ['truffle:TRUFFLE_API']) # Create native-image layout for tools parts for tool_name in tools_map: tool_descriptor = tools_map[tool_name] native_image_layout_dists(join('tools', tool_name, 'builder'), tool_descriptor.builder_deps) native_image_layout_dists(join('tools', tool_name), tool_descriptor.image_deps) native_image_extract_dists(join('tools', tool_name), tool_descriptor.native_deps) native_image_option_properties('tools', tool_name, native_image_root) # Create native-image layout for svm parts svm_subdir = join('lib', 'svm') native_image_layout_dists(svm_subdir, librarySupportDistribution) native_image_layout_dists( join(svm_subdir, 'builder'), svmDistribution + ['substratevm:POINTSTO', 'substratevm:OBJECTFILE']) for clibrary_path in clibrary_paths(): copy_tree(clibrary_path, join(native_image_root, join(svm_subdir, 'clibraries'))) # Create platform-specific symlink to native-image in svm_suite().dir symlink_path = remove_existing_symlink( native_image_symlink_path(native_image_root)) relsymlink(native_image_path(native_image_root), symlink_path) # Finally create default symlink to native-image in svm_suite().dir symlink_path = remove_existing_symlink( native_image_symlink_path(native_image_root, platform_specific=False)) relsymlink(native_image_path(native_image_root), symlink_path)