diff --git a/build/org.eclipse.cdt.cmake.core/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.cmake.core/META-INF/MANIFEST.MF index cc83607a7c8..28011f0ea86 100644 --- a/build/org.eclipse.cdt.cmake.core/META-INF/MANIFEST.MF +++ b/build/org.eclipse.cdt.cmake.core/META-INF/MANIFEST.MF @@ -11,7 +11,8 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.launchbar.core;bundle-version="2.0.0", org.eclipse.cdt.core;bundle-version="5.12.0", org.eclipse.tools.templates.freemarker;bundle-version="1.0.0";visibility:=reexport, - com.google.gson + com.google.gson, + org.eclipse.cdt.cmake.is.core Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-ActivationPolicy: lazy Export-Package: org.eclipse.cdt.cmake.core, diff --git a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfiguration.java b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfiguration.java index 5e89c87c2f5..1686b778fbd 100644 --- a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfiguration.java +++ b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfiguration.java @@ -11,7 +11,6 @@ package org.eclipse.cdt.cmake.core.internal; import java.io.File; -import java.io.FileReader; import java.io.IOException; import java.nio.file.FileVisitResult; import java.nio.file.Files; @@ -23,9 +22,15 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; +import java.util.function.Consumer; import org.eclipse.cdt.cmake.core.ICMakeToolChainFile; import org.eclipse.cdt.cmake.core.ICMakeToolChainManager; +import org.eclipse.cdt.cmake.is.core.CompileCommandsJsonParser; +import org.eclipse.cdt.cmake.is.core.IIndexerInfoConsumer; +import org.eclipse.cdt.cmake.is.core.ParseRequest; +import org.eclipse.cdt.core.CommandLauncherManager; import org.eclipse.cdt.core.ConsoleOutputStream; import org.eclipse.cdt.core.ErrorParserManager; import org.eclipse.cdt.core.IConsoleParser; @@ -34,17 +39,20 @@ import org.eclipse.cdt.core.build.IToolChain; import org.eclipse.cdt.core.envvar.EnvironmentVariable; import org.eclipse.cdt.core.envvar.IEnvironmentVariable; import org.eclipse.cdt.core.model.ICModelMarker; +import org.eclipse.cdt.core.parser.ExtendedScannerInfo; +import org.eclipse.cdt.core.parser.IScannerInfo; import org.eclipse.cdt.core.resources.IConsole; import org.eclipse.core.resources.IBuildConfiguration; +import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.jobs.Job; -import com.google.gson.Gson; - public class CMakeBuildConfiguration extends CBuildConfiguration { public static final String CMAKE_GENERATOR = "cmake.generator"; //$NON-NLS-1$ @@ -54,6 +62,7 @@ public class CMakeBuildConfiguration extends CBuildConfiguration { public static final String CLEAN_COMMAND = "cmake.command.clean"; //$NON-NLS-1$ private ICMakeToolChainFile toolChainFile; + private Map infoPerResource; public CMakeBuildConfiguration(IBuildConfiguration config, String name) throws CoreException { super(config, name); @@ -95,6 +104,7 @@ public class CMakeBuildConfiguration extends CBuildConfiguration { } project.deleteMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE); + infoPerResource = new HashMap<>(); ConsoleOutputStream outStream = console.getOutputStream(); @@ -222,8 +232,10 @@ public class CMakeBuildConfiguration extends CBuildConfiguration { project.refreshLocal(IResource.DEPTH_INFINITE, monitor); - // Load compile_commands.json file - processCompileCommandsFile(monitor); + // parse compile_commands.json file + // built-ins detection output goes to the build console, if the user requested + // output + processCompileCommandsFile(console, monitor); outStream.write(String.format(Messages.CMakeBuildConfiguration_BuildingComplete, epm.getErrorCount(), epm.getWarningCount(), buildDir.toString())); @@ -290,38 +302,22 @@ public class CMakeBuildConfiguration extends CBuildConfiguration { } } - private void processCompileCommandsFile(IProgressMonitor monitor) throws CoreException { - IProject project = getProject(); - Path commandsFile = getBuildDirectory().resolve("compile_commands.json"); //$NON-NLS-1$ - if (Files.exists(commandsFile)) { - List jobsList = new ArrayList<>(); - monitor.setTaskName(Messages.CMakeBuildConfiguration_ProcCompJson); - try (FileReader reader = new FileReader(commandsFile.toFile())) { - Gson gson = new Gson(); - CompileCommand[] commands = gson.fromJson(reader, CompileCommand[].class); - Map dedupedCmds = new HashMap<>(); - for (CompileCommand command : commands) { - dedupedCmds.put(command.getFile(), command); - } - for (CompileCommand command : dedupedCmds.values()) { - processLine(command.getCommand(), jobsList); - } - for (Job j : jobsList) { - try { - j.join(); - } catch (InterruptedException e) { - // ignore - } - } - shutdown(); - } catch (IOException e) { - throw new CoreException(Activator.errorStatus( - String.format(Messages.CMakeBuildConfiguration_ProcCompCmds, project.getName()), e)); - } - } + /** + * @param console the console to print the compiler output during built-ins + * detection to or null if no separate console is to + * be allocated. Ignored if workspace preferences indicate that + * no console output is wanted. + * @param monitor the job's progress monitor + */ + private void processCompileCommandsFile(IConsole console, IProgressMonitor monitor) throws CoreException { + CompileCommandsJsonParser parser = new CompileCommandsJsonParser( + new ParseRequest(this, new CMakeIndexerInfoConsumer(this::setScannerInformation), + CommandLauncherManager.getInstance().getCommandLauncher(this), console)); + parser.parse(monitor); } - /** Recursively removes any files and directories found in the specified Path. + /** + * Recursively removes any files and directories found below the specified Path. */ private static void cleanDirectory(Path dir) throws IOException { SimpleFileVisitor deltor = new SimpleFileVisitor() { @@ -351,4 +347,111 @@ public class CMakeBuildConfiguration extends CBuildConfiguration { cleanDirectory(buildDir); // TODO: not a directory should we do something? } + + /** + * Overridden since the ScannerInfoCache mechanism does not satisfy our needs. + */ + // interface IScannerInfoProvider + @Override + public IScannerInfo getScannerInformation(IResource resource) { + if (infoPerResource == null) { + // no build was run yet, nothing detected + infoPerResource = new HashMap<>(); + try { + processCompileCommandsFile(null, new NullProgressMonitor()); + } catch (CoreException e) { + Activator.log(e); + } + } + return infoPerResource.get(resource); + } + + private void setScannerInformation(Map infoPerResource) { + this.infoPerResource = infoPerResource; + } + + private static class CMakeIndexerInfoConsumer implements IIndexerInfoConsumer { + /** + * gathered IScannerInfo objects or null if no new IScannerInfo was + * received + */ + private Map infoPerResource = new HashMap<>(); + private boolean haveUpdates; + private final Consumer> resultSetter; + + /** + * @param resultSetter receives the all scanner information when processing is + * finished + */ + public CMakeIndexerInfoConsumer(Consumer> resultSetter) { + this.resultSetter = Objects.requireNonNull(resultSetter); + } + + @Override + public void acceptSourceFileInfo(String sourceFileName, List systemIncludePaths, + Map definedSymbols, List includePaths) { + IFile file = getFileForCMakePath(sourceFileName); + if (file != null) { + ExtendedScannerInfo info = new ExtendedScannerInfo(definedSymbols, + systemIncludePaths.stream().toArray(String[]::new), null, null, + includePaths.stream().toArray(String[]::new)); + infoPerResource.put(file, info); + haveUpdates = true; + } + } + + /** + * Gets an IFile object that corresponds to the source file name given in CMake + * notation. + * + * @param sourceFileName the name of the source file, in CMake notation. Note + * that on windows, CMake writes filenames with forward + * slashes (/) such as {@code H://path//to//source.c}. + * @return a IFile object or null + */ + private IFile getFileForCMakePath(String sourceFileName) { + org.eclipse.core.runtime.Path path = new org.eclipse.core.runtime.Path(sourceFileName); + IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path); + // TODO maybe we need to introduce a strategy here to get the workbench resource + // Possible build scenarios: + // 1) linux native: should be OK as is + // 2) linux host, building in container: should be OK as is + // 3) windows native: Path.fromOSString()? + // 4) windows host, building in linux container: ??? needs testing on windows + return file; + } + + @Override + public void shutdown() { + if (haveUpdates) { + // we received updates + resultSetter.accept(infoPerResource); + infoPerResource = null; + haveUpdates = false; + } + } + } + + /** Overwritten since we do not parse console output to get scanner information. + */ + // interface IConsoleParser2 + @Override + public boolean processLine(String line) { + return true; + } + + /** Overwritten since we do not parse console output to get scanner information. + */ + // interface IConsoleParser2 + @Override + public boolean processLine(String line, List jobsArray) { + return true; + } + + /** Overwritten since we do not parse console output to get scanner information. + */ + // interface IConsoleParser2 + @Override + public void shutdown() { + } } diff --git a/cmake/aggregator/CDT devel.launch b/cmake/aggregator/CDT devel.launch new file mode 100644 index 00000000000..5b79ebfcc69 --- /dev/null +++ b/cmake/aggregator/CDT devel.launch @@ -0,0 +1,671 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cmake/org.eclipse.cdt.cmake.is.core/plugin.xml b/cmake/org.eclipse.cdt.cmake.is.core/plugin.xml index 5ef8cc69b04..c3fd96ef998 100644 --- a/cmake/org.eclipse.cdt.cmake.is.core/plugin.xml +++ b/cmake/org.eclipse.cdt.cmake.is.core/plugin.xml @@ -3,13 +3,6 @@ "org.eclipse.cdt.cmake.is.core.internal.ui.CompileCommandsJsonParserOptionPage"> - - - - null if a separate console is to - * be allocated. + * specified configuration, if time-stamps differ. * @param monitor the job's progress monitor * * @return {@code true} if the json file did change since the last invocation of @@ -158,10 +141,11 @@ public class CompileCommandsJsonParser { * {@code false} * @throws CoreException */ - private boolean processJsonFile(ICommandLauncher launcher, IConsole console, IProgressMonitor monitor) - throws CoreException { - final IProject project = cBuildConfiguration.getBuildConfiguration().getProject(); - java.nio.file.Path buildRoot = cBuildConfiguration.getBuildDirectory(); + private boolean processJsonFile(IProgressMonitor monitor) throws CoreException { + final CBuildConfiguration configuration = parseRequest.getBuildConfiguration(); + final IProject project = configuration.getBuildConfiguration().getProject(); + java.nio.file.Path buildRoot = Paths.get(configuration.getBuildDirectoryURI()); + final java.nio.file.Path jsonFile = buildRoot.resolve("compile_commands.json"); //$NON-NLS-1$ if (!Files.exists(jsonFile)) { // no json file was produced in the build @@ -178,7 +162,7 @@ public class CompileCommandsJsonParser { // tread as 'file does nor exist' return false; } - IContainer buildContainer = cBuildConfiguration.getBuildContainer(); + IContainer buildContainer = configuration.getBuildContainer(); final IFile jsonFileRc = buildContainer.getFile(new Path("compile_commands.json")); //$NON-NLS-1$ Long sessionLastModified = (Long) buildContainer.getSessionProperty(TIMESTAMP_COMPILE_COMMANDS_PROPERTY); @@ -207,7 +191,7 @@ public class CompileCommandsJsonParser { return false; } - detectBuiltins(launcher, console, monitor); + detectBuiltins(monitor); // store time-stamp buildContainer.setSessionProperty(TIMESTAMP_COMPILE_COMMANDS_PROPERTY, tsJsonModified); return true; @@ -274,31 +258,25 @@ public class CompileCommandsJsonParser { } /** - * @param launcher the launcher to run the compiler for built-in detection. - * Should be capable to run in docker container, if build in - * container is configured for the project. - * @param console the console to print the compiler output during built-in - * detection to or null if a separate console is to - * be allocated. * @param monitor * @throws CoreException */ - private void detectBuiltins(ICommandLauncher launcher, IConsole console, IProgressMonitor monitor) - throws CoreException { - if (builtinDetectorsToRun == null || builtinDetectorsToRun.isEmpty()) + private void detectBuiltins(IProgressMonitor monitor) throws CoreException { + if (builtinDetectorsToRun.isEmpty()) return; monitor.setTaskName(Messages.CompileCommandsJsonParser_msg_detecting_builtins); - java.nio.file.Path buildDir = cBuildConfiguration.getBuildDirectory(); + java.nio.file.Path buildDir = parseRequest.getBuildConfiguration().getBuildDirectory(); // run each built-in detector and collect the results.. Map builtinDetectorsResults = new HashMap<>(); for (Entry entry : builtinDetectorsToRun.entrySet()) { - IRawIndexerInfo result = entry.getValue().detectBuiltins(cBuildConfiguration.getBuildConfiguration(), - buildDir, launcher, console, monitor); + IRawIndexerInfo result = entry.getValue().detectBuiltins( + parseRequest.getBuildConfiguration().getBuildConfiguration(), buildDir, parseRequest.getLauncher(), + parseRequest.getConsole(), monitor); // store detector key with result builtinDetectorsResults.put(entry.getKey(), result); } - // all built-in detectors have been run at this point + // all built-in detectors have been run at this point, reduce memory footprint builtinDetectorsToRun.clear(); // most of the time we get different String objects for different source files @@ -361,7 +339,8 @@ public class CompileCommandsJsonParser { .map(stringPooler).collect(Collectors.toList()); // feed the paths and defines with the file name to the indexer.. - indexerInfoConsumer.acceptSourceFileInfo(sourceFileName, systemIncludePaths, effectiveDefines, includePaths); + parseRequest.getIndexerInfoConsumer().acceptSourceFileInfo(sourceFileName, systemIncludePaths, effectiveDefines, + includePaths); } private static void createMarker(IResource rc, String message) throws CoreException { @@ -431,14 +410,9 @@ public class CompileCommandsJsonParser { /** * Parses the {@code compile_commands.json} file in the build directory of the - * project if necessary and generates indexer information. - * - * @param launcher the launcher to run the compiler for built-in detection. - * Should be capable to run in docker container, if build in - * container is configured for the project. - * @param console the console to print the compiler output during built-in - * detection to or null if a separate console is to - * be allocated. + * build configuration if necessary and generates indexer information. If the JSON file did not change since the last invocation + * of this method on the same build configuration, parsing of the file will be skipped; that is: + * Method {@link IIndexerInfoConsumer#accept()} is not invoked. * @param monitor the job's progress monitor * * @return {@code true} if the {@code compile_commands.json} file did change @@ -447,20 +421,25 @@ public class CompileCommandsJsonParser { * indexer should be notified. * @throws CoreException */ - public boolean parse(ICommandLauncher launcher, IConsole console, IProgressMonitor monitor) throws CoreException { + public boolean parse(IProgressMonitor monitor) throws CoreException { long start = 0; + fileResults = new HashMap<>(); + builtinDetectorsToRun = new HashMap<>(); + fileToBuiltinDetectorLinks = new HashMap<>(); + try { if (DEBUG_TIME) { System.out.printf("Project %s parsing compile_commands.json ...%n", //$NON-NLS-1$ - cBuildConfiguration.getProject().getName()); + parseRequest.getBuildConfiguration().getProject().getName()); start = System.currentTimeMillis(); } - return processJsonFile(launcher, console, monitor); + return processJsonFile(monitor); } finally { + parseRequest.getIndexerInfoConsumer().shutdown(); if (DEBUG_TIME) { long end = System.currentTimeMillis(); System.out.printf("Project %s parsed compile_commands.json file in %dms%n", //$NON-NLS-1$ - cBuildConfiguration.getProject().getName(), end - start); + parseRequest.getBuildConfiguration().getProject().getName(), end - start); } // clean up builtinDetectorsToRun = null; @@ -474,9 +453,14 @@ public class CompileCommandsJsonParser { * run. * * @param compilerCommand the command name of the compiler - * @param builtinDetectionArgs compiler arguments that affect built-ins - * detection + * @param builtinDetectionArgs the compiler arguments from the command-line that + * affect built-in detection. For the GNU compilers, + * these are options like {@code --sysroot} and + * options that specify the language's standard + * ({@code -std=c++17}. * @param sourceFileExtension the extension of the source file name + * @return a Map-key suitable to minimize the set of CompilerBuiltinsDetector to + * run */ @SuppressWarnings("nls") private static String makeBuiltinsDetectorKey(String compilerCommand, List builtinDetectionArgs, @@ -504,27 +488,20 @@ public class CompileCommandsJsonParser { * @param result */ private void rememberFileResult(String sourceFileName, IRawIndexerInfo result) { - if (fileResults == null) - fileResults = new HashMap<>(); fileResults.put(sourceFileName, result); } /** * @param sourceFileName the name of the source file + * @param compilerCommand the command name of the compiler * @param builtinDetectionArgs the compiler arguments from the command-line that * affect built-in detection. For the GNU compilers, * these are options like {@code --sysroot} and * options that specify the language's standard * ({@code -std=c++17}. - * @return a Map-key suitable to minimize the set of CompilerBuiltinsDetector to - * run */ - private String rememberBuiltinsDetection(String sourceFileName, - IBuiltinsDetectionBehavior builtinsDetectionBehavior, String compilerCommand, - List builtinDetectionArgs) { - if (builtinDetectorsToRun == null) - builtinDetectorsToRun = new HashMap<>(3, 1.0f); - + private void rememberBuiltinsDetection(String sourceFileName, IBuiltinsDetectionBehavior builtinsDetectionBehavior, + String compilerCommand, List builtinDetectionArgs) { String extension = FilenameUtils.getExtension(sourceFileName); String key = makeBuiltinsDetectorKey(compilerCommand, builtinDetectionArgs, extension); if (!builtinDetectorsToRun.containsKey(key)) { @@ -533,11 +510,7 @@ public class CompileCommandsJsonParser { builtinDetectorsToRun.put(key, detector); } // remember the built-ins detector for the source file - if (fileToBuiltinDetectorLinks == null) - fileToBuiltinDetectorLinks = new HashMap<>(); - fileToBuiltinDetectorLinks.put(sourceFileName, key); - return key; } } diff --git a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/IIndexerInfoConsumer.java b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/IIndexerInfoConsumer.java index 2d3e7c27175..a921dd1e4c5 100644 --- a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/IIndexerInfoConsumer.java +++ b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/IIndexerInfoConsumer.java @@ -15,20 +15,39 @@ import java.util.List; import java.util.Map; /** - * Receives the indexer relevant information for each source file. + * Receives the indexer relevant information for each source file while a {@link + * CompileCommandsJsonParser#parse() compile_commands.json file is parsed}. + * + * @see CompileCommandsJsonParser * * @author weber */ public interface IIndexerInfoConsumer { - // TODO Docs - // Yes. Docs are currently intentionally missing here, since ATM it is not clear how to properly handle the sourceFileName argument. - // // Cmake writes filenames with forward slashes (/) even if it runs on windows. // OTOH, IScannerInfoProvider requests info for IResourceS. - // Somewhere in the calling sequence, the filenames have to be converted/mapped to IResource.Conversion*could* + // Somewhere in the calling sequence, the filenames have to be converted/mapped to IResource. Conversion *could* // be done in CompileCommandsJsonParser, but when I think of builds running // in a Linux-Docker-Container under windows, it might be better to do the conversion - //on the IIndexerInfoConsumer side which has more information on the build setup. + // on the IIndexerInfoConsumer side which has more information on the build setup. + + /** Adds indexer relevant information for a single source file. + * + * @param sourceFileName + * the name of the source file, in CMake notation. Note that on windows, CMake writes filenames with forward + * slashes (/) such as {@code H://path//to//source.c}. + * @param systemIncludePaths + * the system include paths ({@code #include <...>}) used to compile the given source file + * @param definedSymbols + * the preprocessor macros used to compile the given source file + * @param includePaths + * the local include paths ({@code #include "..."}) used to compile the given source file + */ void acceptSourceFileInfo(String sourceFileName, List systemIncludePaths, Map definedSymbols, List includePaths); + + /** + * Notifies this consumer that no further calls to {link {@link #acceptSourceFileInfo(String, List, Map, List)} will + * happen during the current parse operation. + */ + void shutdown(); } diff --git a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/ParseRequest.java b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/ParseRequest.java new file mode 100644 index 00000000000..913e042056e --- /dev/null +++ b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/ParseRequest.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2020 Martin Weber. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ + +package org.eclipse.cdt.cmake.is.core; + +import java.util.Objects; + +import org.eclipse.cdt.core.ICommandLauncher; +import org.eclipse.cdt.core.build.CBuildConfiguration; +import org.eclipse.cdt.core.resources.IConsole; + +/** Holds the arguments used to create a {@link CompileCommandsJsonParser}. + * + * @author weber + */ +public final class ParseRequest { + private final CBuildConfiguration buildConfiguration; + private final IIndexerInfoConsumer indexerInfoConsumer; + private final ICommandLauncher launcher; + private final IConsole console; + + /** Creates a new ParseRequest object. + * + * @param buildConfiguration the build configuration of the project + * @param indexerInfoConsumer the object that receives the indexer relevant + * information for each source file + * @param launcher the launcher to run the compiler for built-ins detection. + * Should be capable to run in docker container, if build in + * container is configured for the project. + * @param console the console to print the compiler output during built-ins + * detection to or null if no console output is requested. + * Ignored if workspace preferences indicate that no console output is wanted. + */ + public ParseRequest(CBuildConfiguration buildConfiguration, IIndexerInfoConsumer indexerInfoConsumer, + ICommandLauncher launcher, IConsole console) { + this.buildConfiguration = Objects.requireNonNull(buildConfiguration, "buildConfiguration"); //$NON-NLS-1$ + this.indexerInfoConsumer = Objects.requireNonNull(indexerInfoConsumer, "indexerInfoConsumer"); //$NON-NLS-1$ + this.launcher = Objects.requireNonNull(launcher, "launcher"); //$NON-NLS-1$ + this.console = console; + } + + /** Gets the build configuration of the project. + */ + public CBuildConfiguration getBuildConfiguration() { + return buildConfiguration; + } + + /** Gets the object that receives the indexer relevant + * information for each source file + */ + public IIndexerInfoConsumer getIndexerInfoConsumer() { + return indexerInfoConsumer; + } + + /** Gets the launcher to run the compiler for built-ins detection. + */ + public ICommandLauncher getLauncher() { + return launcher; + } + + /** Gets the console to print the compiler output during built-ins detection to. + * + * @return the console or null if no console output is requested. + */ + public IConsole getConsole() { + return console; + } +} diff --git a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/internal/builtins/CompilerBuiltinsDetector.java b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/internal/builtins/CompilerBuiltinsDetector.java index f8331b29706..dc72cf15f58 100644 --- a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/internal/builtins/CompilerBuiltinsDetector.java +++ b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/internal/builtins/CompilerBuiltinsDetector.java @@ -51,11 +51,6 @@ import org.osgi.framework.FrameworkUtil; * @author Martin Weber */ public class CompilerBuiltinsDetector { - /** - * console ID for extension point org.eclipse.cdt.core.CBuildConsole (see - * plugin.xml) - */ - private static final String CONSOLE_ID = Plugin.PLUGIN_ID + ".detectorConsole"; //$NON-NLS-1$ /** error marker ID */ private static final String MARKER_ID = Plugin.PLUGIN_ID + ".CompilerBuiltinsDetectorMarker"; //$NON-NLS-1$ @@ -94,8 +89,7 @@ public class CompilerBuiltinsDetector { * @param launcher the launcher that can run in docker container, if * any * @param console the console to print the compiler output to or - * null if a separate console is to be - * allocated. + * null if no console output is requested. * @throws CoreException */ public IRawIndexerInfo detectBuiltins(IBuildConfiguration buildConfiguration, java.nio.file.Path theBuildDirectory, @@ -240,16 +234,8 @@ public class CompilerBuiltinsDetector { IParserPreferences prefs = EclipseContextFactory .getServiceContext(FrameworkUtil.getBundle(getClass()).getBundleContext()) .get(IParserPreferencesAccess.class).getWorkspacePreferences(); - if (!prefs.getAllocateConsole()) { - return null; // no console to allocate - } else { + if (console != null && prefs.getAllocateConsole()) { IProject project = buildConfiguration.getProject(); - if (console == null) { - // need to allocate console, but none is given - String consoleId = CONSOLE_ID + "." + project.getName(); //$NON-NLS-1$ - console = CCorePlugin.getDefault().getConsole(CONSOLE_ID, consoleId, null, null); - } - console.start(project); try { final ConsoleOutputStream cis = console.getInfoStream(); @@ -262,8 +248,9 @@ public class CompilerBuiltinsDetector { cis.write("\n".getBytes()); //$NON-NLS-1$ } catch (IOException ignore) { } + return console; } - return console; + return null; // no console to allocate } } diff --git a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/internal/messages.properties b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/internal/messages.properties index e19e075194c..2055f216fd3 100644 --- a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/internal/messages.properties +++ b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/internal/messages.properties @@ -12,7 +12,7 @@ # Martin Weber - initial API and implementation ############################################################################### ParserPreferencesAccess_e_get_preferences=Unable to get preferences for node: {0}.{1} -ParserPreferencesMetadata_label_console=&Show output of compiler built-in detection in a console in the Console View +ParserPreferencesMetadata_label_console=&Show output of compiler built-in detection in the build console ParserPreferencesMetadata_label_suffix=&Suffix pattern: ParserPreferencesMetadata_label_try_suffix=&Also try with version suffix ParserPreferencesMetadata_ttip_suffix=Specify a Java regular expression pattern here