From f17c77bae63a085d48c87d8661e38ed4a7e3c415 Mon Sep 17 00:00:00 2001 From: Erwin Waterlander Date: Wed, 15 Feb 2023 12:23:17 +0000 Subject: [PATCH] New API to custom parse #define lines from GCC during scanning Option to override the matching of macro defines for the Core Build GCC toolchain. This may be needed for custom compilers. Also-by: Jonah Graham --- NewAndNoteworthy/CDT-11.1.md | 3 ++ .../META-INF/MANIFEST.MF | 2 +- .../cdt/build/gcc/core/GCCToolChain.java | 28 +++++++++++++++---- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/NewAndNoteworthy/CDT-11.1.md b/NewAndNoteworthy/CDT-11.1.md index 44ad19146a2..907bc16ebc5 100644 --- a/NewAndNoteworthy/CDT-11.1.md +++ b/NewAndNoteworthy/CDT-11.1.md @@ -12,6 +12,9 @@ This is the New & Noteworthy page for CDT 11.1 which is part of Eclipse 2023-03 Please see [CHANGELOG-API](CHANGELOG-API.md) for details on the breaking API changes in this release as well as future planned API changes. +## GCCToolchain allows custom parsing of `#define` lines + +See new method `matchDefines` introduced in `GCCToolChain`. # Noteworthy Issues and Pull Requests See [Noteworthy issues and PRs](https://github.com/eclipse-cdt/cdt/issues?q=is%3Aclosed+label%3Anoteworthy+milestone%3A11.1.0) for this release in the issue/PR tracker. diff --git a/build/org.eclipse.cdt.build.gcc.core/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.build.gcc.core/META-INF/MANIFEST.MF index c46ce153216..bbd122df157 100644 --- a/build/org.eclipse.cdt.build.gcc.core/META-INF/MANIFEST.MF +++ b/build/org.eclipse.cdt.build.gcc.core/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.cdt.build.gcc.core;singleton:=true -Bundle-Version: 2.0.100.qualifier +Bundle-Version: 2.1.0.qualifier Bundle-Activator: org.eclipse.cdt.build.gcc.core.internal.Activator Bundle-Vendor: %providerName Require-Bundle: org.eclipse.core.runtime, 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 3616ccd9385..0bdcbd7cf16 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 @@ -56,6 +56,8 @@ public class GCCToolChain extends PlatformObject implements IToolChain { public static final String TYPE_ID = "org.eclipse.cdt.build.gcc"; //$NON-NLS-1$ + private static Pattern definePattern = Pattern.compile("#define ([^\\s]*)\\s(.*)"); //$NON-NLS-1$ + private final IToolChainProvider provider; private final String id; private final Path path; @@ -471,7 +473,6 @@ private IExtendedScannerInfo getScannerInfo(IBuildConfiguration buildConfig, Lis // Scan for the scanner info Map symbols = new HashMap<>(); List includePath = new ArrayList<>(); - Pattern definePattern = Pattern.compile("#define ([^\\s]*)\\s(.*)"); //$NON-NLS-1$ // First the include path off the error stream Thread includePathReaderThread = new Thread("Include Path Reader") { @@ -509,11 +510,9 @@ public void run() { // Now the defines off the output stream try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) { for (String line = reader.readLine(); line != null; line = reader.readLine()) { - if (line.startsWith("#define ")) { //$NON-NLS-1$ - Matcher matcher = definePattern.matcher(line); - if (matcher.matches()) { - symbols.put(matcher.group(1), matcher.group(2)); - } + Map matchDefines = matchDefines(line); + if (matchDefines != null) { + symbols.putAll(matchDefines); } } } catch (IOException e) { @@ -535,6 +534,23 @@ public void run() { return new ExtendedScannerInfo(symbols, includePath.toArray(new String[includePath.size()])); } + /** + * Find any macro defines on the given input line and return a map of all such defines. + * + * @param line single line of output from the compiler + * @return map of macro defines + * @since 2.1 + */ + protected Map matchDefines(String line) { + if (line.startsWith("#define ")) { //$NON-NLS-1$ + Matcher matcher = definePattern.matcher(line); + if (matcher.matches()) { + return Map.of(matcher.group(1), matcher.group(2)); + } + } + return Map.of(); + } + @Override public String[] getErrorParserIds() { return new String[] { "org.eclipse.cdt.core.GCCErrorParser", //$NON-NLS-1$