mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
bug 404913: Built-In Settings Provider should recognize extra gcc
parameters from build settings
This commit is contained in:
parent
af57f95d75
commit
12c5f12990
5 changed files with 154 additions and 4 deletions
|
@ -9391,6 +9391,15 @@
|
|||
resourceFilter="all"
|
||||
valueType="string">
|
||||
</option>
|
||||
<option
|
||||
command="-bool-option"
|
||||
defaultValue="true"
|
||||
id="cdt.managedbuilder.lsp.tests.option.bool"
|
||||
isAbstract="false"
|
||||
resourceFilter="all"
|
||||
useByScannerDiscovery="true"
|
||||
valueType="boolean">
|
||||
</option>
|
||||
<option
|
||||
command="-str-option="
|
||||
id="cdt.managedbuilder.lsp.tests.option.string"
|
||||
|
@ -9400,6 +9409,50 @@
|
|||
value="str-value"
|
||||
valueType="string">
|
||||
</option>
|
||||
<option
|
||||
id="cdt.managedbuilder.lsp.tests.option.enum"
|
||||
isAbstract="false"
|
||||
resourceFilter="all"
|
||||
useByScannerDiscovery="true"
|
||||
valueType="enumerated">
|
||||
<enumeratedOptionValue
|
||||
command="-enum-option"
|
||||
id="cdt.managedbuilder.lsp.tests.enum.value"
|
||||
isDefault="true"
|
||||
name="cdt.managedbuilder.lsp.tests.enum.value">
|
||||
</enumeratedOptionValue>
|
||||
</option>
|
||||
<option
|
||||
command="-list-option"
|
||||
id="cdt.managedbuilder.lsp.tests.option.stringlist"
|
||||
isAbstract="false"
|
||||
resourceFilter="all"
|
||||
useByScannerDiscovery="true"
|
||||
valueType="stringList">
|
||||
<listOptionValue
|
||||
value="1">
|
||||
</listOptionValue>
|
||||
<listOptionValue
|
||||
value="2">
|
||||
</listOptionValue>
|
||||
</option>
|
||||
<option
|
||||
defaultValue="cdt.managedbuilder.lsp.tests.tree-option"
|
||||
id="cdt.managedbuilder.lsp.tests.option.tree"
|
||||
isAbstract="false"
|
||||
resourceFilter="all"
|
||||
useByScannerDiscovery="true"
|
||||
valueType="tree">
|
||||
<treeOptionRoot
|
||||
id="cdt.managedbuilder.lsp.tests.option.tree.root"
|
||||
name="cdt.managedbuilder.lsp.tests.option.tree.root">
|
||||
<treeOption
|
||||
command="-tree-option"
|
||||
id="cdt.managedbuilder.lsp.tests.tree-option"
|
||||
name="cdt.managedbuilder.lsp.tests.tree-option">
|
||||
</treeOption>
|
||||
</treeOptionRoot>
|
||||
</option>
|
||||
</tool>
|
||||
</toolChain>
|
||||
</extension>
|
||||
|
|
|
@ -84,6 +84,15 @@ public class GCCBuiltinSpecsDetectorTest extends BaseTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
class MockLspToolchainBuiltinSpecsDetectorCommandResolver extends MockGCCBuiltinSpecsDetectorCommandResolver {
|
||||
// ID must match the tool-chain definition in org.eclipse.cdt.managedbuilder.core.buildDefinitions extension point
|
||||
private static final String MOCK_TOOLCHAIN_ID = "cdt.managedbuilder.lsp.tests.toolchain";
|
||||
@Override
|
||||
public String getToolchainId() {
|
||||
return MOCK_TOOLCHAIN_ID;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
@ -163,6 +172,19 @@ public class GCCBuiltinSpecsDetectorTest extends BaseTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test expansion of relevant tool options in build command.
|
||||
*/
|
||||
public void testGCCBuiltinSpecsDetector_ResolvedCommand_Flags() throws Exception {
|
||||
// check ${FLAGS}
|
||||
MockLspToolchainBuiltinSpecsDetectorCommandResolver detector = new MockLspToolchainBuiltinSpecsDetectorCommandResolver();
|
||||
detector.setLanguageScope(new ArrayList<String>() {{add(LANGUAGE_ID_C);}});
|
||||
detector.setCommand("gcc ${FLAGS}");
|
||||
|
||||
String resolvedCommand = detector.resolveCommand(LANGUAGE_ID_C);
|
||||
assertEquals("gcc -bool-option -str-option=str-value -enum-option -list-option1 -list-option2 -tree-option", resolvedCommand);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test parsing of macro without value.
|
||||
*/
|
||||
|
|
|
@ -42,7 +42,7 @@ ManagedMakeBuilder.warning.unsupported.configuration=**** WARNING: The "{0}" Co
|
|||
ManagedMakeBuilder.error.prefix=Error:
|
||||
|
||||
# Option exception messages
|
||||
Option.error.bad_value_type=Bad value for type
|
||||
Option.error.bad_value_type=Type of option value is inconsistent with option type
|
||||
|
||||
# Managed build manager exception messages
|
||||
ManagedBuildManager.error.owner_not_null=addTarget: owner not null
|
||||
|
|
|
@ -93,6 +93,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
|
|||
public static final String JOB_FAMILY_BUILTIN_SPECS_DETECTOR = "org.eclipse.cdt.managedbuilder.AbstractBuiltinSpecsDetector"; //$NON-NLS-1$
|
||||
|
||||
protected static final String COMPILER_MACRO = "${COMMAND}"; //$NON-NLS-1$
|
||||
protected static final String FLAGS_MACRO = "${FLAGS}"; //$NON-NLS-1$
|
||||
protected static final String SPEC_FILE_MACRO = "${INPUTS}"; //$NON-NLS-1$
|
||||
protected static final String SPEC_EXT_MACRO = "${EXT}"; //$NON-NLS-1$
|
||||
protected static final String SPEC_FILE_BASE = "spec"; //$NON-NLS-1$
|
||||
|
@ -305,6 +306,11 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
|
|||
if (compiler != null)
|
||||
cmd = cmd.replace(COMPILER_MACRO, compiler);
|
||||
}
|
||||
if (cmd.contains(FLAGS_MACRO)) {
|
||||
String flags = getToolOptions(languageId);
|
||||
if (flags != null)
|
||||
cmd = cmd.replace(FLAGS_MACRO, flags);
|
||||
}
|
||||
if (cmd.contains(SPEC_FILE_MACRO)) {
|
||||
String specFileName = getSpecFile(languageId);
|
||||
if (specFileName != null)
|
||||
|
@ -814,6 +820,17 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
|
|||
return ext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine additional options to pass to scanner discovery command.
|
||||
* These options are intended to come from the tool-chain.
|
||||
*
|
||||
* @param languageId - language ID.
|
||||
* @return additional options to pass to scanner discovery command.
|
||||
*/
|
||||
protected String getToolOptions(String languageId) {
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public Element serializeAttributes(Element parentElement) {
|
||||
Element elementProvider = super.serializeAttributes(parentElement);
|
||||
|
|
|
@ -16,8 +16,10 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
|
||||
import org.eclipse.cdt.managedbuilder.core.BuildException;
|
||||
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
|
||||
import org.eclipse.cdt.managedbuilder.core.IInputType;
|
||||
import org.eclipse.cdt.managedbuilder.core.IOption;
|
||||
import org.eclipse.cdt.managedbuilder.core.ITool;
|
||||
import org.eclipse.cdt.managedbuilder.core.IToolChain;
|
||||
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
|
||||
|
@ -39,6 +41,7 @@ import org.eclipse.cdt.managedbuilder.internal.envvar.EnvironmentVariableManager
|
|||
* @since 8.1
|
||||
*/
|
||||
public abstract class ToolchainBuiltinSpecsDetector extends AbstractBuiltinSpecsDetector {
|
||||
private static final String EMPTY_QUOTED_STRING = "\"\""; //$NON-NLS-1$
|
||||
private Map<String, ITool> toolMap = new HashMap<String, ITool>();
|
||||
|
||||
/**
|
||||
|
@ -55,13 +58,16 @@ public abstract class ToolchainBuiltinSpecsDetector extends AbstractBuiltinSpecs
|
|||
* This returns the first tool found.
|
||||
*/
|
||||
private ITool getTool(String languageId) {
|
||||
ITool tool = toolMap.get(languageId);
|
||||
if (tool != null) {
|
||||
return tool;
|
||||
if (currentCfgDescription == null) {
|
||||
ITool tool = toolMap.get(languageId);
|
||||
if (tool != null) {
|
||||
return tool;
|
||||
}
|
||||
}
|
||||
|
||||
String toolchainId = null;
|
||||
IToolChain toolchain = null;
|
||||
ITool tool = null;
|
||||
if (currentCfgDescription != null) {
|
||||
IConfiguration cfg = ManagedBuildManager.getConfigurationForDescription(currentCfgDescription);
|
||||
toolchain = cfg != null ? cfg.getToolChain() : null;
|
||||
|
@ -130,6 +136,58 @@ public abstract class ToolchainBuiltinSpecsDetector extends AbstractBuiltinSpecs
|
|||
return ext;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getToolOptions(String languageId) {
|
||||
String flags = ""; //$NON-NLS-1$
|
||||
ITool tool = getTool(languageId);
|
||||
if (tool != null) {
|
||||
IOption[] options = tool.getOptions();
|
||||
for (IOption option : options) {
|
||||
if (option.isForScannerDiscovery()) {
|
||||
try {
|
||||
String optionValue = null;
|
||||
switch (option.getBasicValueType()) {
|
||||
case IOption.BOOLEAN:
|
||||
if (option.getBooleanValue()) {
|
||||
optionValue = option.getCommand();
|
||||
} else {
|
||||
optionValue = option.getCommandFalse();
|
||||
}
|
||||
break;
|
||||
case IOption.ENUMERATED:
|
||||
optionValue = option.getEnumCommand(option.getSelectedEnum());
|
||||
break;
|
||||
case IOption.STRING:
|
||||
optionValue = option.getCommand() + option.getStringValue();
|
||||
break;
|
||||
case IOption.STRING_LIST:
|
||||
String[] values = option.getBasicStringListValue();
|
||||
if(values != null) {
|
||||
optionValue = ""; //$NON-NLS-1$
|
||||
String cmd = option.getCommand();
|
||||
for (String value : values) {
|
||||
if(!value.isEmpty() && !value.equals(EMPTY_QUOTED_STRING))
|
||||
optionValue = optionValue + cmd + value + ' ';
|
||||
}
|
||||
}
|
||||
break;
|
||||
case IOption.TREE:
|
||||
optionValue = option.getCommand(option.getStringValue());
|
||||
break;
|
||||
default:
|
||||
}
|
||||
if (optionValue != null) {
|
||||
flags = flags + ' ' + optionValue.trim();
|
||||
}
|
||||
} catch (BuildException e) {
|
||||
ManagedBuilderCorePlugin.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return flags.trim();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<IEnvironmentVariable> getEnvironmentVariables() {
|
||||
if (envMngr == null && currentCfgDescription == null) {
|
||||
|
|
Loading…
Add table
Reference in a new issue