From f40f957c6c7f2e4b627ff5af43c3d671cbd59f2d Mon Sep 17 00:00:00 2001 From: Erwin Waterlander Date: Fri, 21 Apr 2023 09:07:45 +0100 Subject: [PATCH] Improved GCCToolChain.stripCommand() GCCToolChain.stripCommand() assumed that all resources are at the end of the command, like in the old version of GCCToolChain.getResourcesFromCommand() which was fixed in PR #311 (see commit a89ce59df23). Now stripCommand() is in line with getResourcesFromCommand(). --- .../cdt/build/gcc/core/GCCToolChain.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/GCCToolChain.java b/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/GCCToolChain.java index 4c7bec4b39c..150964638c8 100644 --- a/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/GCCToolChain.java +++ b/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/GCCToolChain.java @@ -721,17 +721,24 @@ public class GCCToolChain extends PlatformObject implements IToolChain { public List stripCommand(List command, IResource[] resources) { List newCommand = new ArrayList<>(); - for (int i = 0; i < command.size() - resources.length; ++i) { + for (int i = 0; i < command.size(); ++i) { String arg = command.get(i); - if (arg.startsWith("-o")) { //$NON-NLS-1$ - if (arg.equals("-o")) { //$NON-NLS-1$ - i++; - } + if (arg.equals("-o")) { //$NON-NLS-1$ + // this is an output file, skip. + i++; continue; } - newCommand.add(arg); + if (arg.startsWith("-")) { //$NON-NLS-1$ + // ran into an option, add. + newCommand.add(arg); + continue; + } + String ext = getFileExtension(arg); + if (!resourcesFileExtensions.contains(ext)) { + // not a resource, add. + newCommand.add(arg); + } } - return newCommand; }