1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-06 17:26: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:
Jeff Johnston 2018-02-13 16:33:10 -05:00
parent ca09189575
commit 3405063203
2 changed files with 21 additions and 5 deletions

View file

@ -9,6 +9,8 @@ package org.eclipse.cdt.build.gcc.core.internal;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; 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$ 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$ private static final Pattern clangPattern = Pattern.compile("clang(\\.exe)?"); //$NON-NLS-1$
@Override @Override
@ -40,6 +43,7 @@ public class GCCPathToolChainProvider implements IToolChainProvider {
@Override @Override
public void init(IToolChainManager manager) { public void init(IToolChainManager manager) {
String path = System.getenv("PATH"); //$NON-NLS-1$ String path = System.getenv("PATH"); //$NON-NLS-1$
List<IToolChain> tupledList = new ArrayList<>();
for (String dirStr : path.split(File.pathSeparator)) { for (String dirStr : path.split(File.pathSeparator)) {
File dir = new File(dirStr); File dir = new File(dirStr);
if (dir.isDirectory()) { if (dir.isDirectory()) {
@ -48,7 +52,8 @@ public class GCCPathToolChainProvider implements IToolChainProvider {
continue; continue;
} }
Matcher matcher = gccPattern.matcher(file.getName()); Matcher matcher = gccPattern.matcher(file.getName());
if (matcher.matches()) { Matcher matcher2 = tupledGccPattern.matcher(file.getName());
if (matcher.matches() || matcher2.matches()) {
try { try {
GCCInfo info = new GCCInfo(file.toString()); GCCInfo info = new GCCInfo(file.toString());
if (info.target != null && info.version != null) { if (info.target != null && info.version != null) {
@ -71,7 +76,12 @@ public class GCCPathToolChainProvider implements IToolChainProvider {
try { try {
if (manager.getToolChain(gcc.getTypeId(), gcc.getId()) == null) { if (manager.getToolChain(gcc.getTypeId(), gcc.getId()) == null) {
// Only add if another provider hasn't already added it // 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) { } catch (CoreException e) {
CCorePlugin.log(e.getStatus()); CCorePlugin.log(e.getStatus());
@ -80,7 +90,7 @@ public class GCCPathToolChainProvider implements IToolChainProvider {
} }
} catch (IOException e) { } catch (IOException e) {
Activator.log(e); Activator.log(e);
} }
} else { } else {
matcher = clangPattern.matcher(file.getName()); matcher = clangPattern.matcher(file.getName());
if (matcher.matches()) { 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);
}
} }
} }

View file

@ -11,6 +11,7 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -133,7 +134,7 @@ public class ToolChainManager implements IToolChainManager {
public void addToolChain(IToolChain toolChain) { public void addToolChain(IToolChain toolChain) {
Map<String, IToolChain> type = toolChains.get(toolChain.getTypeId()); Map<String, IToolChain> type = toolChains.get(toolChain.getTypeId());
if (type == null) { if (type == null) {
type = new HashMap<>(); type = new LinkedHashMap<>(); // use LinkedHashMap so input order is maintained
toolChains.put(toolChain.getTypeId(), type); toolChains.put(toolChain.getTypeId(), type);
} }
type.put(toolChain.getId(), toolChain); type.put(toolChain.getId(), toolChain);