Skip to content
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
7 changes: 3 additions & 4 deletions substratevm/mx.substratevm/mx_substratevm.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import tempfile
from glob import glob
from contextlib import contextmanager
from distutils.dir_util import mkpath # pylint: disable=no-name-in-module
from os.path import join, exists, dirname
import pipes
from argparse import ArgumentParser
Expand Down Expand Up @@ -494,9 +493,9 @@ def native_unittests_task(extra_build_args=None):
resources_from_dir = join(cp_entry_name, 'resourcesFromDir')
simple_dir = join(cp_entry_name, 'simpleDir')

mkpath(cp_entry_name)
mkpath(resources_from_dir)
mkpath(simple_dir)
os.makedirs(cp_entry_name)
os.makedirs(resources_from_dir)
os.makedirs(simple_dir)

for i in range(4):
with open(join(cp_entry_name, "resourcesFromDir", f'cond-resource{i}.txt'), 'w') as out:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Optional;
Expand All @@ -50,6 +49,7 @@
import com.oracle.svm.core.option.SubstrateOptionsParser;
import com.oracle.svm.core.util.InterruptImageBuilding;
import com.oracle.svm.core.util.UserError;
import com.oracle.svm.core.util.VMError;
import com.oracle.svm.hosted.c.libc.HostedLibCBase;
import com.oracle.svm.hosted.c.util.FileUtils;
import com.oracle.svm.util.ClassUtil;
Expand Down Expand Up @@ -139,47 +139,52 @@ protected InputStream getCompilerErrorStream(Process compilingProcess) {

@Override
protected List<String> getVersionInfoOptions() {
return Collections.emptyList();
Path detectVersionInfoFile = tempDirectory.resolve("detect-cl-version-info.c").toAbsolutePath();
try {
Files.write(detectVersionInfoFile, List.of("M_X64=_M_X64", "M_ARM64EC=_M_ARM64EC", "MSC_FULL_VER=_MSC_FULL_VER"));
} catch (IOException ioe) {
throw VMError.shouldNotReachHere("Unable to create file to detect cl version info", ioe);
}
return List.of("/EP", detectVersionInfoFile.toString());
}

@Override
protected CompilerInfo createCompilerInfo(Path compilerPath, Scanner outerScanner) {
try (Scanner scanner = new Scanner(outerScanner.nextLine())) {
String targetArch = null;
/* For cl.exe the first line holds all necessary information */
if (scanner.hasNext("\u7528\u4E8E")) {
/* Simplified-Chinese has targetArch first */
scanner.next();
targetArch = scanner.next();
protected CompilerInfo createCompilerInfo(Path compilerPath, Scanner scanner) {
try {
if (scanner.findInLine("Microsoft.*\\(R\\)") == null) {
return null; // not a Microsoft compiler
}
/*
* Some cl.exe print "... Microsoft (R) C/C++ ... ##.##.#####" while others print
* "...C/C++ ... Microsoft (R) ... ##.##.#####".
*/
if (scanner.findInLine("Microsoft.*\\(R\\) C/C\\+\\+") == null &&
scanner.findInLine("C/C\\+\\+.*Microsoft.*\\(R\\)") == null) {
scanner.nextLine(); // skip rest of first line
scanner.nextLine(); // skip copyright line
scanner.nextLine(); // skip blank separator line
skipLineIfHasNext(scanner, "detect-cl-version-info.c");
scanner.nextLine(); // skip blank separator line
skipLineIfHasNext(scanner, "M_X64=100"); // _M_X64 is defined
skipLineIfHasNext(scanner, "M_ARM64EC=_M_ARM64EC"); // _M_ARM64EC is not defined
if (scanner.findInLine("MSC_FULL_VER=") == null) {
return null;
}
scanner.useDelimiter("\\D");
while (!scanner.hasNextInt()) {
scanner.next();
}
int major = scanner.nextInt();
int minor0 = scanner.nextInt();
int minor1 = scanner.nextInt();
if (targetArch == null) {
scanner.reset();
while (scanner.hasNext()) {
/* targetArch is last token in line */
targetArch = scanner.next();
}
String mscFullVerValue = scanner.nextLine();
if (mscFullVerValue.length() < 5) {
return null;
}
return new CompilerInfo(compilerPath, "microsoft", "C/C++ Optimizing Compiler", "cl", major, minor0, minor1, targetArch);
} catch (NoSuchElementException e) {
int major = Integer.parseInt(mscFullVerValue.substring(0, 2));
int minor0 = Integer.parseInt(mscFullVerValue.substring(2, 4));
int minor1 = Integer.parseInt(mscFullVerValue.substring(4));
return new CompilerInfo(compilerPath, "microsoft", "C/C++ Optimizing Compiler", "cl", major, minor0, minor1, "x64");
} catch (NoSuchElementException | NumberFormatException e) {
return null;
}
}

private void skipLineIfHasNext(Scanner scanner, String expectedToken) {
if (scanner.hasNext(expectedToken)) {
scanner.nextLine();
} else {
throw new NoSuchElementException(expectedToken);
}
}

@Override
protected void verify() {
// See details on _MSC_VER at
Expand All @@ -190,11 +195,6 @@ protected void verify() {
UserError.abort("On Windows, GraalVM Native Image for JDK %s requires %s or later (C/C++ Optimizing Compiler Version %s.%s or later).%nCompiler info detected: %s",
JavaVersionUtil.JAVA_SPEC, VISUAL_STUDIO_MINIMUM_REQUIRED_VERSION, minimumMajorVersion, minimumMinorVersion, compilerInfo.getShortDescription());
}
if (guessArchitecture(compilerInfo.targetArch) != AMD64.class) {
String targetPrefix = compilerInfo.targetArch.matches("(.*x|i\\d)86$") ? "32-bit architecture " : "";
UserError.abort("Native-image building on Windows currently only supports target architecture: %s (%s%s unsupported)",
AMD64.class.getSimpleName(), targetPrefix, compilerInfo.targetArch);
}
}

@Override
Expand Down Expand Up @@ -416,7 +416,7 @@ private CompilerInfo getCCompilerInfo() {
}

protected List<String> getVersionInfoOptions() {
return Arrays.asList("-v");
return List.of("-v");
}

protected abstract CompilerInfo createCompilerInfo(Path compilerPath, Scanner scanner);
Expand Down