mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 01:06:01 +02:00
Bug 531125 - Tupled gcc toolchains should not be the local default
- change ToolChainManager so that when creating the types map for the first time, make it a LinkedHashMap instead of HashMap so order of input is preserved (first in = first out) - fix GCCPathToolChainProvider so that it adds non-tupled gcc to the ToolChainManger before adding any tupled version Change-Id: I84602a98dd4949a2f9847d4e72c428cdedd60688
This commit is contained in:
parent
ca09189575
commit
3405063203
2 changed files with 21 additions and 5 deletions
|
@ -9,6 +9,8 @@ package org.eclipse.cdt.build.gcc.core.internal;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -29,7 +31,8 @@ public class GCCPathToolChainProvider implements IToolChainProvider {
|
|||
|
||||
public static final String ID = "org.eclipse.cdt.build.gcc.core.gccPathProvider"; //$NON-NLS-1$
|
||||
|
||||
private static final Pattern gccPattern = Pattern.compile("(.*-)?gcc(\\.exe)?"); //$NON-NLS-1$
|
||||
private static final Pattern gccPattern = Pattern.compile("gcc(\\.exe)?"); //$NON-NLS-1$
|
||||
private static final Pattern tupledGccPattern = Pattern.compile("(.*-)?gcc(\\.exe)?"); //$NON-NLS-1$
|
||||
private static final Pattern clangPattern = Pattern.compile("clang(\\.exe)?"); //$NON-NLS-1$
|
||||
|
||||
@Override
|
||||
|
@ -40,6 +43,7 @@ public class GCCPathToolChainProvider implements IToolChainProvider {
|
|||
@Override
|
||||
public void init(IToolChainManager manager) {
|
||||
String path = System.getenv("PATH"); //$NON-NLS-1$
|
||||
List<IToolChain> tupledList = new ArrayList<>();
|
||||
for (String dirStr : path.split(File.pathSeparator)) {
|
||||
File dir = new File(dirStr);
|
||||
if (dir.isDirectory()) {
|
||||
|
@ -48,7 +52,8 @@ public class GCCPathToolChainProvider implements IToolChainProvider {
|
|||
continue;
|
||||
}
|
||||
Matcher matcher = gccPattern.matcher(file.getName());
|
||||
if (matcher.matches()) {
|
||||
Matcher matcher2 = tupledGccPattern.matcher(file.getName());
|
||||
if (matcher.matches() || matcher2.matches()) {
|
||||
try {
|
||||
GCCInfo info = new GCCInfo(file.toString());
|
||||
if (info.target != null && info.version != null) {
|
||||
|
@ -71,7 +76,12 @@ public class GCCPathToolChainProvider implements IToolChainProvider {
|
|||
try {
|
||||
if (manager.getToolChain(gcc.getTypeId(), gcc.getId()) == null) {
|
||||
// Only add if another provider hasn't already added it
|
||||
manager.addToolChain(gcc);
|
||||
if (matcher.matches()) {
|
||||
manager.addToolChain(gcc);
|
||||
} else {
|
||||
// add to tupled list to register later
|
||||
tupledList.add(gcc);
|
||||
}
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e.getStatus());
|
||||
|
@ -80,7 +90,7 @@ public class GCCPathToolChainProvider implements IToolChainProvider {
|
|||
}
|
||||
} catch (IOException e) {
|
||||
Activator.log(e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
matcher = clangPattern.matcher(file.getName());
|
||||
if (matcher.matches()) {
|
||||
|
@ -93,6 +103,11 @@ public class GCCPathToolChainProvider implements IToolChainProvider {
|
|||
}
|
||||
}
|
||||
}
|
||||
// add tupled toolchains last so we won't find any local compiler as a tupled chain before the normal
|
||||
// defaults (e.g. don't want to find x86_64-redhat-linux-gcc before gcc if looking for a local toolchain)
|
||||
for (IToolChain t : tupledList) {
|
||||
manager.addToolChain(t);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import java.util.ArrayList;
|
|||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -133,7 +134,7 @@ public class ToolChainManager implements IToolChainManager {
|
|||
public void addToolChain(IToolChain toolChain) {
|
||||
Map<String, IToolChain> type = toolChains.get(toolChain.getTypeId());
|
||||
if (type == null) {
|
||||
type = new HashMap<>();
|
||||
type = new LinkedHashMap<>(); // use LinkedHashMap so input order is maintained
|
||||
toolChains.put(toolChain.getTypeId(), type);
|
||||
}
|
||||
type.put(toolChain.getId(), toolChain);
|
||||
|
|
Loading…
Add table
Reference in a new issue