Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit bdeb890

Browse files
Ekaterina VergizovaYuri Nesterenko
authored andcommitted
8248987: AOT's Linker.java seems to eagerly fail-fast on Windows.
Treat all problems in getVC141AndNewerLinker() as non-fatal. Print error messages with --verbose flag. Backport-of: e2353cc
1 parent da062ac commit bdeb890

File tree

1 file changed

+16
-10
lines changed
  • src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc

1 file changed

+16
-10
lines changed

src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/Linker.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private static String getString(InputStream stream) {
107107
objectFileName = name.substring(0, name.length() - ".dll".length());
108108
}
109109
objectFileName = objectFileName + ".obj";
110-
linkerPath = (options.linkerpath != null) ? options.linkerpath : getWindowsLinkPath();
110+
linkerPath = (options.linkerpath != null) ? options.linkerpath : getWindowsLinkPath(main);
111111
if (linkerPath == null) {
112112
throw new InternalError("Can't locate Microsoft Visual Studio amd64 link.exe");
113113
}
@@ -127,6 +127,8 @@ private static String getString(InputStream stream) {
127127
throw new InternalError(getString(p.getErrorStream()));
128128
}
129129
}
130+
131+
main.printer.printlnVerbose("Found linker: " + linkerPath);
130132
}
131133

132134
void link() throws Exception {
@@ -159,14 +161,17 @@ void link() throws Exception {
159161
/**
160162
* Search for Visual Studio link.exe Search Order is: VS2017+, VS2013, VS2015, VS2012.
161163
*/
162-
private static String getWindowsLinkPath() throws Exception {
164+
private static String getWindowsLinkPath(Main main) throws Exception {
163165
try {
164166
Path vc141NewerLinker = getVC141AndNewerLinker();
165167
if (vc141NewerLinker != null) {
166168
return vc141NewerLinker.toString();
167169
}
168170
} catch (Exception e) {
169-
e.printStackTrace();
171+
main.printer.printlnVerbose("Could not find VC14 or newer version of linker: " + e.getMessage());
172+
if (main.options.debug) {
173+
e.printStackTrace();
174+
}
170175
}
171176

172177
String link = "\\VC\\bin\\amd64\\link.exe";
@@ -202,11 +207,12 @@ private static String getWindowsLinkPath() throws Exception {
202207
private static Path getVC141AndNewerLinker() throws Exception {
203208
String programFilesX86 = System.getenv("ProgramFiles(x86)");
204209
if (programFilesX86 == null) {
205-
throw new InternalError("Could not read the ProgramFiles(x86) environment variable");
210+
throw new IllegalStateException("Could not read the ProgramFiles(x86) environment variable");
206211
}
207-
Path vswhere = Paths.get(programFilesX86 + "\\Microsoft Visual Studio\\Installer\\vswhere.exe");
212+
String vswherePath = programFilesX86 + "\\Microsoft Visual Studio\\Installer\\vswhere.exe";
213+
Path vswhere = Paths.get(vswherePath);
208214
if (!Files.exists(vswhere)) {
209-
return null;
215+
throw new IllegalStateException("Could not find " + vswherePath);
210216
}
211217

212218
ProcessBuilder processBuilder = new ProcessBuilder(vswhere.toString(), "-requires",
@@ -220,19 +226,19 @@ private static Path getVC141AndNewerLinker() throws Exception {
220226
if (errorMessage.isEmpty()) {
221227
errorMessage = getString(process.getInputStream());
222228
}
223-
throw new InternalError(errorMessage);
229+
throw new IllegalStateException("vswhere error: " + errorMessage);
224230
}
225231

226-
String installationPath = getLines(process.getInputStream()).findFirst().orElseThrow(() -> new InternalError("Unexpected empty output from vswhere"));
232+
String installationPath = getLines(process.getInputStream()).findFirst().orElseThrow(() -> new IllegalStateException("Unexpected empty output from vswhere"));
227233
Path vcToolsVersionFilePath = Paths.get(installationPath, "VC\\Auxiliary\\Build\\Microsoft.VCToolsVersion.default.txt");
228234
List<String> vcToolsVersionFileLines = Files.readAllLines(vcToolsVersionFilePath);
229235
if (vcToolsVersionFileLines.isEmpty()) {
230-
throw new InternalError(vcToolsVersionFilePath.toString() + " is empty");
236+
throw new IllegalStateException(vcToolsVersionFilePath.toString() + " is empty");
231237
}
232238
String vcToolsVersion = vcToolsVersionFileLines.get(0);
233239
Path linkPath = Paths.get(installationPath, "VC\\Tools\\MSVC", vcToolsVersion, "bin\\Hostx64\\x64\\link.exe");
234240
if (!Files.exists(linkPath)) {
235-
throw new InternalError("Linker at path " + linkPath.toString() + " does not exist");
241+
throw new IllegalStateException("Linker at path " + linkPath.toString() + " does not exist");
236242
}
237243

238244
return linkPath;

0 commit comments

Comments
 (0)