From aa7ee788d7861b59095ae0f1d26b1f037ddfc769 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20W=C3=B6gerer?= Date: Mon, 25 May 2020 11:23:29 +0200 Subject: [PATCH 1/3] Support cl.exe detection for Simplified-Chinese and other languages --- .../hosted/c/codegen/CCompilerInvoker.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/c/codegen/CCompilerInvoker.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/c/codegen/CCompilerInvoker.java index a81746028076..43c6032e169e 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/c/codegen/CCompilerInvoker.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/c/codegen/CCompilerInvoker.java @@ -124,15 +124,28 @@ protected List getVersionInfoOptions() { @Override protected CompilerInfo createCompilerInfo(Path compilerPath, Scanner scanner) { try { + String targetArch = null; /* For cl.exe the first line holds all necessary information */ - scanner.findInLine("Microsoft.?\\(R\\) C/C\\+\\+ Optimizing Compiler Version "); + if (scanner.hasNext("用于")) { + /* Simplified-Chinese has targetArch first */ + scanner.next(); + targetArch = scanner.next(); + } + if (scanner.findInLine("Microsoft.*\\(R\\) C/C\\+\\+") == null) { + return null; + } scanner.useDelimiter("[. ]"); + while (!scanner.hasNextInt()) { + scanner.next(); + } int major = scanner.nextInt(); int minor0 = scanner.nextInt(); int minor1 = scanner.nextInt(); - scanner.reset(); /* back to default delimiters */ - scanner.findInLine("for "); - String targetArch = scanner.next(); + if (targetArch == null) { + scanner.reset(); /* back to default delimiters */ + scanner.next(); + targetArch = scanner.next(); + } return new CompilerInfo(compilerPath, "microsoft", "C/C++ Optimizing Compiler", "cl", major, minor0, minor1, targetArch); } catch (NoSuchElementException e) { return null; From a52d69d62812cc3a3e5cb596ac6d82a15af952cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20W=C3=B6gerer?= Date: Mon, 25 May 2020 11:59:02 +0200 Subject: [PATCH 2/3] Checkstyle fix --- .../com/oracle/svm/hosted/c/codegen/CCompilerInvoker.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/c/codegen/CCompilerInvoker.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/c/codegen/CCompilerInvoker.java index 43c6032e169e..f859c728a0da 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/c/codegen/CCompilerInvoker.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/c/codegen/CCompilerInvoker.java @@ -126,7 +126,10 @@ protected CompilerInfo createCompilerInfo(Path compilerPath, Scanner scanner) { try { String targetArch = null; /* For cl.exe the first line holds all necessary information */ - if (scanner.hasNext("用于")) { + // Checkstyle: stop + String forToken = "用于"; + // Checkstyle: resume + if (scanner.hasNext(forToken)) { /* Simplified-Chinese has targetArch first */ scanner.next(); targetArch = scanner.next(); From f5992cc615f943d4a7f5f62263efbcf7db26fa96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20W=C3=B6gerer?= Date: Mon, 25 May 2020 12:57:01 +0200 Subject: [PATCH 3/3] cl.exe detection: targetArch is last token in line --- .../svm/hosted/c/codegen/CCompilerInvoker.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/c/codegen/CCompilerInvoker.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/c/codegen/CCompilerInvoker.java index f859c728a0da..9ab5e8c0b9d5 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/c/codegen/CCompilerInvoker.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/c/codegen/CCompilerInvoker.java @@ -122,14 +122,11 @@ protected List getVersionInfoOptions() { } @Override - protected CompilerInfo createCompilerInfo(Path compilerPath, Scanner scanner) { - try { + 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 */ - // Checkstyle: stop - String forToken = "用于"; - // Checkstyle: resume - if (scanner.hasNext(forToken)) { + if (scanner.hasNext("\u7528\u4E8E")) { /* Simplified-Chinese has targetArch first */ scanner.next(); targetArch = scanner.next(); @@ -145,9 +142,11 @@ protected CompilerInfo createCompilerInfo(Path compilerPath, Scanner scanner) { int minor0 = scanner.nextInt(); int minor1 = scanner.nextInt(); if (targetArch == null) { - scanner.reset(); /* back to default delimiters */ - scanner.next(); - targetArch = scanner.next(); + scanner.reset(); + while (scanner.hasNext()) { + /* targetArch is last token in line */ + targetArch = scanner.next(); + } } return new CompilerInfo(compilerPath, "microsoft", "C/C++ Optimizing Compiler", "cl", major, minor0, minor1, targetArch); } catch (NoSuchElementException e) {