Skip to content

Commit de91c43

Browse files
authored
fix: properly updating toolchain list after tools installation (#842)
1 parent b152760 commit de91c43

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

bundles/com.espressif.idf.core/src/com/espressif/idf/core/toolchain/ESPToolChainManager.java

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,10 @@ public void initToolChain(IToolChainManager manager, IToolChainProvider toolchai
146146

147147
public File findDebugger(String target)
148148
{
149-
return toolchainElements
150-
.values()
151-
.stream()
152-
.filter(espToolChainElement -> espToolChainElement.name.equals(target))
153-
.map(espToolChainElement -> findToolChain(getAllPaths(), espToolChainElement.debuggerPattern))
154-
.findFirst()
155-
.orElse(null);
149+
return toolchainElements.values().stream()
150+
.filter(espToolChainElement -> espToolChainElement.name.equals(target))
151+
.map(espToolChainElement -> findToolChain(getAllPaths(), espToolChainElement.debuggerPattern))
152+
.findFirst().orElse(null);
156153
}
157154

158155
public File findToolChain(List<String> paths, String filePattern)
@@ -174,10 +171,7 @@ public File findToolChain(List<String> paths, String filePattern)
174171

175172
private Path[] getDirectories(String path)
176173
{
177-
return Arrays.stream(path.split(File.pathSeparator))
178-
.map(String::trim)
179-
.map(Paths::get)
180-
.toArray(Path[]::new);
174+
return Arrays.stream(path.split(File.pathSeparator)).map(String::trim).map(Paths::get).toArray(Path[]::new);
181175
}
182176

183177
private File findMatchingFile(Path dir, String filePattern)
@@ -204,7 +198,6 @@ private File findMatchingFile(Path dir, String filePattern)
204198
return null;
205199
}
206200

207-
208201
public void removePrevInstalledToolchains(IToolChainManager manager)
209202
{
210203
try
@@ -224,17 +217,36 @@ private void addToolChain(IToolChainManager manager, IToolChainProvider toolchai
224217
{
225218
try
226219
{
227-
if (!isToolChainExist(manager, toolChainElement))
220+
if (isToolChainExist(manager, toolChainElement))
228221
{
229-
manager.addToolChain(new ESPToolchain(toolchainProvider, compilerFile.toPath(), toolChainElement));
222+
removeMatchedToolChain(manager, toolChainElement);
230223
}
224+
225+
manager.addToolChain(new ESPToolchain(toolchainProvider, compilerFile.toPath(), toolChainElement));
231226
}
232227
catch (CoreException e)
233228
{
234229
CCorePlugin.log(e.getStatus());
235230
}
236231
}
237232

233+
private void removeMatchedToolChain(IToolChainManager manager, ESPToolChainElement toolChainElement)
234+
{
235+
Map<String, String> props = new HashMap<>();
236+
props.put(IToolChain.ATTR_OS, toolChainElement.name);
237+
props.put(IToolChain.ATTR_ARCH, toolChainElement.arch);
238+
props.put(TOOLCHAIN_ATTR_ID, toolChainElement.fileName);
239+
try
240+
{
241+
manager.getToolChainsMatching(props).forEach(toolchain -> manager.removeToolChain(toolchain));
242+
}
243+
catch (CoreException e)
244+
{
245+
Logger.log(e);
246+
}
247+
248+
}
249+
238250
private boolean isToolChainExist(IToolChainManager manager, ESPToolChainElement toolChainElement)
239251
throws CoreException
240252
{

0 commit comments

Comments
 (0)