1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-25 09:55:29 +02:00

Bug 559674: Migrating from a ILanguageSettingsProvider implementation to IIndexerInfoConsumer (5/6)

Adjust detection participant implementations & tests to new API.

This is piece five of change https://git.eclipse.org/r/c/159828 being split into pieces.
Splitting is done for code reviewing reasons.

Change-Id: Iab6917c45f9e749f2a8ff1f1c0b4c4991131cbd2
Signed-off-by: Martin Weber <fifteenknots505@gmail.com>
This commit is contained in:
Martin Weber 2020-05-07 21:34:43 +02:00 committed by Alexander Fedorov
parent 636691a404
commit e9d6747a74
17 changed files with 82 additions and 127 deletions

View file

@ -33,7 +33,7 @@ public class ArmClangToolDetectionParticipant extends DefaultToolDetectionPartic
new Arglets.MacroUndefine_C_POSIX() };
private ToolCommandlineParser() {
super(null, new ResponseFileArglets.At(), null, arglets);
super(new ResponseFileArglets.At(), null, arglets);
}
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 Martin Weber.
* Copyright (c) 2019-2020 Martin Weber.
*
* Content is provided to you under the terms and conditions of the Eclipse Public License Version 2.0 "EPL".
* A copy of the EPL is available at http://www.eclipse.org/legal/epl-2.0.
@ -43,16 +43,4 @@ class ArmccBuiltinDetectionBehavior implements IBuiltinsDetectionBehavior {
// enable built-in detection
return false;
}
@SuppressWarnings("nls")
@Override
public String getInputFileExtension(String languageId) {
if (languageId.equals("org.eclipse.cdt.core.gcc")) {
return "c";
}
if (languageId.equals("org.eclipse.cdt.core.g++")) {
return "cpp";
}
return null;
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 Martin Weber.
* Copyright (c) 2019-2020 Martin Weber.
*
* Content is provided to you under the terms and conditions of the Eclipse Public License Version 2.0 "EPL".
* A copy of the EPL is available at http://www.eclipse.org/legal/epl-2.0.
@ -32,7 +32,7 @@ public class ArmccToolDetectionParticipant extends DefaultToolDetectionParticipa
new Arglets.MacroUndefine_C_POSIX(), new Arglets.SystemIncludePath_armcc() };
private ToolCommandlineParser() {
super(null, null, new ArmccBuiltinDetectionBehavior(), arglets);
super(null, new ArmccBuiltinDetectionBehavior(), arglets);
}
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 Martin Weber.
* Copyright (c) 2019-2020 Martin Weber.
*
* Content is provided to you under the terms and conditions of the Eclipse Public License Version 2.0 "EPL".
* A copy of the EPL is available at http://www.eclipse.org/legal/epl-2.0.
@ -32,7 +32,7 @@ public class HpeC11ToolDetectionParticipant extends DefaultToolDetectionParticip
new Arglets.MacroUndefine_C_POSIX() };
private ToolCommandlineParser() {
super(null, new ResponseFileArglets.At(), null, arglets);
super(new ResponseFileArglets.At(), null, arglets);
}
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 Martin Weber.
* Copyright (c) 2019-2020 Martin Weber.
*
* Content is provided to you under the terms and conditions of the Eclipse Public License Version 2.0 "EPL".
* A copy of the EPL is available at http://www.eclipse.org/legal/epl-2.0.
@ -32,7 +32,7 @@ public class HpeC89ToolDetectionParticipant extends DefaultToolDetectionParticip
new Arglets.MacroUndefine_C_POSIX() };
private ToolCommandlineParser() {
super(null, new ResponseFileArglets.At(), null, arglets);
super(new ResponseFileArglets.At(), null, arglets);
}
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 Martin Weber.
* Copyright (c) 2019-2020 Martin Weber.
*
* Content is provided to you under the terms and conditions of the Eclipse Public License Version 2.0 "EPL".
* A copy of the EPL is available at http://www.eclipse.org/legal/epl-2.0.
@ -32,7 +32,7 @@ public class HpeC99ToolDetectionParticipant extends DefaultToolDetectionParticip
new Arglets.MacroUndefine_C_POSIX() };
private ToolCommandlineParser() {
super(null, new ResponseFileArglets.At(), null, arglets);
super(new ResponseFileArglets.At(), null, arglets);
}
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 Martin Weber.
* Copyright (c) 2019-2020 Martin Weber.
*
* Content is provided to you under the terms and conditions of the Eclipse Public License Version 2.0 "EPL".
* A copy of the EPL is available at http://www.eclipse.org/legal/epl-2.0.
@ -32,7 +32,7 @@ public class IclCandCppToolDetectionParticipant extends DefaultToolDetectionPart
new Arglets.MacroUndefine_C_POSIX() };
private CandCppToolCommandlineParser() {
super(null, new ResponseFileArglets.At(), null, arglets);
super(new ResponseFileArglets.At(), null, arglets);
}
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 Martin Weber.
* Copyright (c) 2019-2020 Martin Weber.
*
* Content is provided to you under the terms and conditions of the Eclipse Public License Version 2.0 "EPL".
* A copy of the EPL is available at http://www.eclipse.org/legal/epl-2.0.
@ -24,7 +24,7 @@ class IntelCToolCommandlineParser extends DefaultToolCommandlineParser {
static final IntelCToolCommandlineParser INSTANCE = new IntelCToolCommandlineParser();
private IntelCToolCommandlineParser() {
super("org.eclipse.cdt.core.gcc", new ResponseFileArglets.At(), null, new Arglets.IncludePath_C_POSIX(),
new Arglets.MacroDefine_C_POSIX(), new Arglets.MacroUndefine_C_POSIX());
super(new ResponseFileArglets.At(), null, new Arglets.IncludePath_C_POSIX(), new Arglets.MacroDefine_C_POSIX(),
new Arglets.MacroUndefine_C_POSIX());
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 Martin Weber.
* Copyright (c) 2019-2020 Martin Weber.
*
* Content is provided to you under the terms and conditions of the Eclipse Public License Version 2.0 "EPL".
* A copy of the EPL is available at http://www.eclipse.org/legal/epl-2.0.
@ -24,7 +24,7 @@ class IntelCppToolCommandlineParser extends DefaultToolCommandlineParser {
static final IntelCppToolCommandlineParser INSTANCE = new IntelCppToolCommandlineParser();
private IntelCppToolCommandlineParser() {
super("org.eclipse.cdt.core.g++", new ResponseFileArglets.At(), null, new Arglets.IncludePath_C_POSIX(),
new Arglets.MacroDefine_C_POSIX(), new Arglets.MacroUndefine_C_POSIX());
super(new ResponseFileArglets.At(), null, new Arglets.IncludePath_C_POSIX(), new Arglets.MacroDefine_C_POSIX(),
new Arglets.MacroUndefine_C_POSIX());
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 Martin Weber.
* Copyright (c) 2019-2020 Martin Weber.
*
* Content is provided to you under the terms and conditions of the Eclipse Public License Version 2.0 "EPL".
* A copy of the EPL is available at http://www.eclipse.org/legal/epl-2.0.
@ -31,15 +31,7 @@ class MsclToolCommandlineParser extends DefaultToolCommandlineParser {
new MacroUndefine_C_CL() };
public MsclToolCommandlineParser() {
super(null, new ResponseFileArglets.At(), null, arglets);
}
/**
* Overridden to get the language ID from the file name extension.
*/
@Override
public String getLanguageId(String sourceFileExtension) {
return super.determineLanguageId(sourceFileExtension).orElse(null);
super(new ResponseFileArglets.At(), null, arglets);
}
////////////////////////////////////////////////////////////////////
@ -71,8 +63,8 @@ class MsclToolCommandlineParser extends DefaultToolCommandlineParser {
* @see org.eclipse.cdt.cmake.is.IArglet#processArgs(java.lang.String)
*/
@Override
public int processArgument(IParseContext parseContext, IPath cwd, String argsLine) {
return processArgument(parseContext, cwd, argsLine, optionMatchers);
public int processArgument(IArgumentCollector resultCollector, IPath cwd, String argsLine) {
return processArgument(false, resultCollector, cwd, argsLine, optionMatchers);
}
}
@ -97,8 +89,8 @@ class MsclToolCommandlineParser extends DefaultToolCommandlineParser {
* @see org.eclipse.cdt.cmake.is.IArglet#processArgs(java.lang.String)
*/
@Override
public int processArgument(IParseContext parseContext, IPath cwd, String argsLine) {
return processArgument(parseContext, argsLine, optionMatchers);
public int processArgument(IArgumentCollector resultCollector, IPath cwd, String argsLine) {
return processArgument(resultCollector, argsLine, optionMatchers);
}
}
@ -115,8 +107,8 @@ class MsclToolCommandlineParser extends DefaultToolCommandlineParser {
* @see org.eclipse.cdt.cmake.is.IArglet#processArgument(java.util.List, java.lang.String)
*/
@Override
public int processArgument(IParseContext parseContext, IPath cwd, String argsLine) {
return processArgument(parseContext, argsLine, optionMatcher);
public int processArgument(IArgumentCollector resultCollector, IPath cwd, String argsLine) {
return processArgument(resultCollector, argsLine, optionMatcher);
}
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018 Martin Weber.
* Copyright (c) 2018-2020 Martin Weber.
*
* Content is provided to you under the terms and conditions of the Eclipse Public License Version 2.0 "EPL".
* A copy of the EPL is available at http://www.eclipse.org/legal/epl-2.0.
@ -12,8 +12,6 @@ import static org.junit.Assert.assertEquals;
import org.eclipse.cdt.cmake.is.core.DefaultToolCommandlineParser;
import org.eclipse.cdt.cmake.is.core.IToolCommandlineParser.IResult;
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.junit.Before;
@ -36,41 +34,32 @@ public class NvccSystemIncludePathTest {
@Test
public final void testProcessArgument() {
DefaultToolCommandlineParser tcp = new DefaultToolCommandlineParser("egal", null, null, testee);
DefaultToolCommandlineParser tcp = new DefaultToolCommandlineParser(null, null, testee);
final String more = " -g -MMD -MT CMakeFiles/execut1.dir/util1.c.o -MF \"CMakeFiles/execut1.dir/util1.c.o.d\""
+ " -o CMakeFiles/execut1.dir/util1.c.o -c /testprojects/C-subsrc/src/src-sub/main1.cu";
final IPath cwd = new Path("");
ICLanguageSettingEntry parsed;
// -isystem=/an/Include/Path
String name = "/an/Include/Path";
IResult result = tcp.processArgs(cwd, "-isystem" + "=" + name + more);
assertEquals("#entries", 1, result.getSettingEntries().size());
parsed = result.getSettingEntries().get(0);
assertEquals("kind", ICSettingEntry.INCLUDE_PATH, parsed.getKind());
assertEquals("name", name, parsed.getName());
assertEquals("#entries", 1, result.getSystemIncludePaths().size());
assertEquals("name", name, result.getSystemIncludePaths().get(0));
// -isystem='/an/Include/Path'
result = tcp.processArgs(cwd, "-isystem" + "=" + "'" + name + "'" + more);
assertEquals("#entries", 1, result.getSettingEntries().size());
parsed = result.getSettingEntries().get(0);
assertEquals("kind", ICSettingEntry.INCLUDE_PATH, parsed.getKind());
assertEquals("name", name, parsed.getName());
assertEquals("#entries", 1, result.getSystemIncludePaths().size());
assertEquals("name", name, result.getSystemIncludePaths().get(0));
// -isystem="/an/Include/Path"
result = tcp.processArgs(cwd, "-isystem" + "=" + "\"" + name + "\"" + more);
assertEquals("#entries", 1, result.getSettingEntries().size());
parsed = result.getSettingEntries().get(0);
assertEquals("kind", ICSettingEntry.INCLUDE_PATH, parsed.getKind());
assertEquals("name", name, parsed.getName());
assertEquals("#entries", 1, result.getSystemIncludePaths().size());
assertEquals("name", name, result.getSystemIncludePaths().get(0));
name = (new Path("A:an\\In CLU de/Pat h")).toOSString();
// -isystem="A:an\In CLU de/Pat h"
result = tcp.processArgs(cwd, "-isystem" + "=" + "\"" + name + "\"" + more);
assertEquals("#entries", 1, result.getSettingEntries().size());
parsed = result.getSettingEntries().get(0);
assertEquals("kind", ICSettingEntry.INCLUDE_PATH, parsed.getKind());
assertEquals("name", name, parsed.getName());
assertEquals("#entries", 1, result.getSystemIncludePaths().size());
assertEquals("name", name, result.getSystemIncludePaths().get(0));
// -isystem='A:an\In CLU de/Pat h'
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 Martin Weber.
* Copyright (c) 2019-2020 Martin Weber.
*
* Content is provided to you under the terms and conditions of the Eclipse Public License Version 2.0 "EPL".
* A copy of the EPL is available at http://www.eclipse.org/legal/epl-2.0.
@ -38,7 +38,7 @@ public class NvccBuiltins_DetectLangStdTest {
*/
@Test
public final void testProcessArgument_std() {
DefaultToolCommandlineParser tcp = new DefaultToolCommandlineParser("egal", null, null, testee);
DefaultToolCommandlineParser tcp = new DefaultToolCommandlineParser(null, null, testee);
final String more = " -g -MMD -MT CMakeFiles/execut1.dir/util1.c.o -MF \"CMakeFiles/execut1.dir/util1.c.o.d\""
+ " -o CMakeFiles/execut1.dir/util1.c.o -c /testprojects/C-subsrc/src/src-sub/main1.c";
@ -79,7 +79,7 @@ public class NvccBuiltins_DetectLangStdTest {
public final void testProcessArgument_std2() {
final String more = " -g -MMD -MT CMakeFiles/execut1.dir/util1.c.o -MF \"CMakeFiles/execut1.dir/util1.c.o.d\""
+ " -o CMakeFiles/execut1.dir/util1.c.o -c /testprojects/C-subsrc/src/src-sub/main1.c";
DefaultToolCommandlineParser tcp = new DefaultToolCommandlineParser("egal", null, null, testee);
DefaultToolCommandlineParser tcp = new DefaultToolCommandlineParser(null, null, testee);
String parsed;

View file

@ -15,13 +15,14 @@ import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.eclipse.cdt.cmake.is.core.IRawIndexerInfoCollector;
import org.eclipse.cdt.cmake.is.core.builtins.GccOutputProcessor;
import org.eclipse.cdt.cmake.is.core.builtins.IBuiltinsOutputProcessor;
import org.eclipse.cdt.cmake.is.core.builtins.OutputSniffer;
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
import org.junit.Before;
import org.junit.Test;
@ -44,7 +45,7 @@ public class NvccOutputProcessorTest {
@Test
public void testProcessFile() throws IOException {
// pass resource content line-wise to the testee...
ProcessingContextMock pc = new ProcessingContextMock();
RawIndexerInfoMock pc = new RawIndexerInfoMock();
try (InputStream is = getClass().getResourceAsStream("cbd-nvcc.output.txt");
OutputSniffer os = new OutputSniffer(testee, null, pc)) {
byte[] buffer = new byte[1024];
@ -54,38 +55,43 @@ public class NvccOutputProcessorTest {
}
}
// check __GNUC__
for (ICLanguageSettingEntry entry : pc.entries) {
if (entry.getKind() == ICLanguageSettingEntry.MACRO) {
if ("__CUDACC_VER_BUILD__".equals(entry.getName()))
assertEquals("value (" + entry.getName() + ")", "85", entry.getValue());
}
}
assertEquals("# include paths", 6, pc.includePaths.size());
assertEquals("# macros", 242, pc.defines.size());
int inc = 0;
int macro = 0;
for (ICLanguageSettingEntry entry : pc.entries) {
if (entry.getKind() == ICLanguageSettingEntry.INCLUDE_PATH) {
inc++;
assertTrue("path", !"".equals(entry.getName()));
} else if (entry.getKind() == ICLanguageSettingEntry.MACRO) {
macro++;
assertTrue("macro", !"".equals(entry.getName()));
assertTrue("value (" + entry.getName() + ")", entry.getValue() != null);
}
}
assertEquals("# include paths", 6, inc);
assertEquals("# macros", 242, macro);
// check __CUDACC_VER_BUILD__
assertTrue("__CUDACC_VER_BUILD__", pc.defines.containsKey("__GNUC__"));
assertEquals("value", "85", pc.defines.get("__CUDACC_VER_BUILD__"));
}
private static class ProcessingContextMock implements IBuiltinsOutputProcessor.IProcessingContext {
private final List<ICLanguageSettingEntry> entries = Collections
.synchronizedList(new ArrayList<ICLanguageSettingEntry>());
private static class RawIndexerInfoMock implements IRawIndexerInfoCollector {
private final Map<String, String> defines = new HashMap<>();
private final List<String> undefines = new ArrayList<>();
private final List<String> includePaths = new ArrayList<>();
private final List<String> systemIncludePaths = new ArrayList<>();
@Override
public void addSettingEntry(ICLanguageSettingEntry entry) {
entries.add(entry);
public void addDefine(String name, String value) {
Objects.requireNonNull(name);
value = Objects.toString(value, ""); //$NON-NLS-1$
defines.put(name, value);
}
@Override
public void addUndefine(String name) {
Objects.requireNonNull(name);
undefines.add(name);
}
@Override
public void addIncludePath(String path) {
Objects.requireNonNull(path);
includePaths.add(path);
}
@Override
public void addSystemIncludePath(String path) {
Objects.requireNonNull(path);
systemIncludePaths.add(path);
}
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 Martin Weber.
* Copyright (c) 2019-2020 Martin Weber.
*
* Content is provided to you under the terms and conditions of the Eclipse Public License Version 2.0 "EPL".
* A copy of the EPL is available at http://www.eclipse.org/legal/epl-2.0.
@ -42,18 +42,4 @@ class NvccBuiltinDetectionBehavior implements IBuiltinsDetectionBehavior {
// enable built-in detection
return false;
}
@Override
public String getInputFileExtension(String languageId) {
if (languageId.equals("org.eclipse.cdt.core.gcc")) {
return "c";
}
if (languageId.equals("org.eclipse.cdt.core.g++")) {
return "cpp";
}
if (languageId.equals("com.nvidia.cuda.toolchain.language.cuda.cu")) {
return "cu";
}
return null;
}
}

View file

@ -28,7 +28,7 @@ public class NvccLangStdArglet extends BuiltinDetctionArgsGeneric implements IAr
* @see org.eclipse.cdt.cmake.is.IArglet#processArgs(java.lang.String)
*/
@Override
public int processArgument(IParseContext parseContext, IPath cwd, String argsLine) {
return processArgument(parseContext, argsLine, optionMatchers);
public int processArgument(IArgumentCollector resultCollector, IPath cwd, String argsLine) {
return processArgument(resultCollector, argsLine, optionMatchers);
}
}

View file

@ -33,7 +33,7 @@ class NvccSystemIncludePathArglet extends IncludePathGeneric implements IArglet
* @see org.eclipse.cdt.cmake.is.IArglet#processArgs(java.lang.String)
*/
@Override
public int processArgument(IParseContext parseContext, IPath cwd, String argsLine) {
return processArgument(parseContext, cwd, argsLine, optionMatchers);
public int processArgument(IArgumentCollector resultCollector, IPath cwd, String argsLine) {
return processArgument(true, resultCollector, cwd, argsLine, optionMatchers);
}
}

View file

@ -37,13 +37,7 @@ public class NvccToolDetectionParticipant extends DefaultToolDetectionParticipan
new Arglets.SystemIncludePath_C(), new NvccLangStdArglet() };
private ToolCommandlineParser() {
super(COM_NVIDIA_CUDA_LANGUAGE_ID, new ResponseFileArglets.At(), new NvccBuiltinDetectionBehavior(),
arglets);
}
@Override
public Set<String> getCustomLanguageIds() {
return Collections.singleton(COM_NVIDIA_CUDA_LANGUAGE_ID);
super(new ResponseFileArglets.At(), new NvccBuiltinDetectionBehavior(), arglets);
}
}
}