|
1 | 1 | /*******************************************************************************
|
2 |
| - * Copyright (c) 2016, 2023 QNX Software Systems and others. |
| 2 | + * Copyright (c) 2016, 2024 QNX Software Systems and others. |
3 | 3 | *
|
4 | 4 | * This program and the accompanying materials
|
5 | 5 | * are made available under the terms of the Eclipse Public License 2.0
|
|
9 | 9 | * SPDX-License-Identifier: EPL-2.0
|
10 | 10 | * Contributors:
|
11 | 11 | * John Dallaway - Support multiple MSYS2 64-bit registry names (#237)
|
| 12 | + * John Dallaway - Detect UCRT64 toolchains (#887) |
12 | 13 | *******************************************************************************/
|
13 | 14 | package org.eclipse.cdt.build.gcc.core.internal;
|
14 | 15 |
|
15 | 16 | import java.io.File;
|
16 | 17 | import java.nio.file.Files;
|
17 | 18 | import java.nio.file.Path;
|
18 | 19 | import java.nio.file.Paths;
|
| 20 | +import java.util.List; |
19 | 21 | import java.util.Set;
|
20 | 22 |
|
| 23 | +import org.eclipse.cdt.build.gcc.core.ClangToolChain; |
21 | 24 | import org.eclipse.cdt.build.gcc.core.GCCToolChain;
|
22 | 25 | import org.eclipse.cdt.core.build.IToolChain;
|
23 | 26 | import org.eclipse.cdt.core.build.IToolChainManager;
|
@@ -78,59 +81,57 @@ public void init(IToolChainManager manager) {
|
78 | 81 | private boolean addToolChain64(IToolChainManager manager, WindowsRegistry registry, String key) {
|
79 | 82 | String installLocation = registry.getCurrentUserValue(key, "InstallLocation"); //$NON-NLS-1$
|
80 | 83 | Path msysPath = Paths.get(installLocation);
|
81 |
| - Path gccPath = msysPath.resolve("mingw64\\bin\\gcc.exe"); //$NON-NLS-1$ |
82 |
| - if (Files.exists(gccPath)) { |
83 |
| - StringBuilder pathVar = new StringBuilder(); |
84 |
| - pathVar.append(msysPath); |
85 |
| - pathVar.append("\\mingw64\\bin"); //$NON-NLS-1$ |
86 |
| - pathVar.append(File.pathSeparatorChar); |
87 |
| - pathVar.append(msysPath); |
88 |
| - pathVar.append("\\usr\\local\\bin"); //$NON-NLS-1$ |
89 |
| - pathVar.append(File.pathSeparatorChar); |
90 |
| - pathVar.append(msysPath); |
91 |
| - pathVar.append("\\usr\\bin"); //$NON-NLS-1$ |
92 |
| - pathVar.append(File.pathSeparatorChar); |
93 |
| - pathVar.append(msysPath); |
94 |
| - pathVar.append("\\bin"); //$NON-NLS-1$ |
95 |
| - IEnvironmentVariable[] vars = new IEnvironmentVariable[] { |
96 |
| - new EnvironmentVariable("PATH", pathVar.toString(), IEnvironmentVariable.ENVVAR_PREPEND, //$NON-NLS-1$ |
97 |
| - File.pathSeparator) }; |
98 |
| - GCCToolChain toolChain = new GCCToolChain(this, gccPath, Platform.ARCH_X86_64, vars); |
99 |
| - toolChain.setProperty(IToolChain.ATTR_PACKAGE, "msys2"); //$NON-NLS-1$ |
100 |
| - manager.addToolChain(toolChain); |
101 |
| - return true; |
102 |
| - } else { |
103 |
| - return addToolChain32(manager, registry, key); |
| 84 | + boolean found = false; |
| 85 | + for (String variant : List.of("mingw64", "ucrt64")) { //$NON-NLS-1$ //$NON-NLS-2$ |
| 86 | + Path gccPath = msysPath.resolve(variant + "\\bin\\gcc.exe"); //$NON-NLS-1$ |
| 87 | + if (Files.exists(gccPath)) { |
| 88 | + IEnvironmentVariable[] vars = createEnvironmentVariables(msysPath, gccPath.getParent()); |
| 89 | + IToolChain toolChain = new GCCToolChain(this, gccPath, Platform.ARCH_X86_64, vars); |
| 90 | + toolChain.setProperty(IToolChain.ATTR_PACKAGE, "msys2"); //$NON-NLS-1$ |
| 91 | + manager.addToolChain(toolChain); |
| 92 | + found = true; |
| 93 | + } |
| 94 | + Path clangPath = msysPath.resolve(variant + "\\bin\\clang.exe"); //$NON-NLS-1$ |
| 95 | + if (Files.exists(clangPath)) { |
| 96 | + IEnvironmentVariable[] vars = createEnvironmentVariables(msysPath, clangPath.getParent()); |
| 97 | + IToolChain toolChain = new ClangToolChain(this, clangPath, Platform.ARCH_X86_64, vars); |
| 98 | + toolChain.setProperty(IToolChain.ATTR_PACKAGE, "msys2"); //$NON-NLS-1$ |
| 99 | + manager.addToolChain(toolChain); |
| 100 | + found = true; |
| 101 | + } |
104 | 102 | }
|
| 103 | + return found || addToolChain32(manager, registry, key); |
105 | 104 | }
|
106 | 105 |
|
107 | 106 | private boolean addToolChain32(IToolChainManager manager, WindowsRegistry registry, String key) {
|
108 | 107 | String installLocation = registry.getCurrentUserValue(key, "InstallLocation"); //$NON-NLS-1$
|
109 | 108 | Path msysPath = Paths.get(installLocation);
|
110 | 109 | Path gccPath = msysPath.resolve("mingw32\\bin\\gcc.exe"); //$NON-NLS-1$
|
111 | 110 | if (Files.exists(gccPath)) {
|
112 |
| - StringBuilder pathVar = new StringBuilder(); |
113 |
| - pathVar.append(msysPath); |
114 |
| - pathVar.append("\\mingw32\\bin"); //$NON-NLS-1$ |
115 |
| - pathVar.append(File.pathSeparatorChar); |
116 |
| - pathVar.append(msysPath); |
117 |
| - pathVar.append("\\usr\\local\\bin"); //$NON-NLS-1$ |
118 |
| - pathVar.append(File.pathSeparatorChar); |
119 |
| - pathVar.append(msysPath); |
120 |
| - pathVar.append("\\usr\\bin"); //$NON-NLS-1$ |
121 |
| - pathVar.append(File.pathSeparatorChar); |
122 |
| - pathVar.append(msysPath); |
123 |
| - pathVar.append("\\bin"); //$NON-NLS-1$ |
124 |
| - IEnvironmentVariable[] vars = new IEnvironmentVariable[] { |
125 |
| - new EnvironmentVariable("PATH", pathVar.toString(), IEnvironmentVariable.ENVVAR_PREPEND, //$NON-NLS-1$ |
126 |
| - File.pathSeparator) }; |
127 |
| - GCCToolChain toolChain = new GCCToolChain(this, gccPath, Platform.ARCH_X86, vars); |
| 111 | + IEnvironmentVariable[] vars = createEnvironmentVariables(msysPath, gccPath.getParent()); |
| 112 | + IToolChain toolChain = new GCCToolChain(this, gccPath, Platform.ARCH_X86, vars); |
128 | 113 | toolChain.setProperty(IToolChain.ATTR_PACKAGE, "msys2"); //$NON-NLS-1$
|
129 | 114 | manager.addToolChain(toolChain);
|
130 | 115 | return true;
|
131 |
| - } else { |
132 |
| - return false; |
133 | 116 | }
|
| 117 | + return false; |
| 118 | + } |
| 119 | + |
| 120 | + private IEnvironmentVariable[] createEnvironmentVariables(Path msysPath, Path toolPath) { |
| 121 | + StringBuilder pathVar = new StringBuilder(); |
| 122 | + pathVar.append(toolPath); |
| 123 | + pathVar.append(File.pathSeparatorChar); |
| 124 | + pathVar.append(msysPath); |
| 125 | + pathVar.append("\\usr\\local\\bin"); //$NON-NLS-1$ |
| 126 | + pathVar.append(File.pathSeparatorChar); |
| 127 | + pathVar.append(msysPath); |
| 128 | + pathVar.append("\\usr\\bin"); //$NON-NLS-1$ |
| 129 | + pathVar.append(File.pathSeparatorChar); |
| 130 | + pathVar.append(msysPath); |
| 131 | + pathVar.append("\\bin"); //$NON-NLS-1$ |
| 132 | + EnvironmentVariable pathVariable = new EnvironmentVariable("PATH", pathVar.toString(), //$NON-NLS-1$ |
| 133 | + IEnvironmentVariable.ENVVAR_PREPEND, File.pathSeparator); |
| 134 | + return new IEnvironmentVariable[] { pathVariable }; |
134 | 135 | }
|
135 | 136 |
|
136 | 137 | }
|
0 commit comments