mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-31 12:55:40 +02:00
Bug 531106 - Modify MBS option serialize to handle empty string lists
Store a flag to indicate if an empty or null list. Existing projects without flag will be considered as non-empty when loaded to maintain existing behaviour for them. Change-Id: I745c887eb2888910c6e76d5bc057d592a3d8fb3a Signed-off-by: William Riley <william.riley@renesas.com>
This commit is contained in:
parent
d03213fae4
commit
9a4853aa2d
3 changed files with 235 additions and 11 deletions
|
@ -9456,5 +9456,118 @@
|
|||
</tool>
|
||||
</toolChain>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.cdt.managedbuilder.core.buildDefinitions">
|
||||
<tool
|
||||
id="bug531106.tests.tool"
|
||||
isAbstract="false"
|
||||
isSystem="true">
|
||||
<option
|
||||
id="bug531106.tests.option.stringList"
|
||||
isAbstract="false"
|
||||
resourceFilter="all"
|
||||
valueType="stringList">
|
||||
<listOptionValue
|
||||
value="TC_VALUE">
|
||||
</listOptionValue>
|
||||
</option>
|
||||
<option
|
||||
id="bug531106.tests.option.incPath"
|
||||
isAbstract="false"
|
||||
resourceFilter="all"
|
||||
valueType="includePath">
|
||||
<listOptionValue
|
||||
value="TC_VALUE">
|
||||
</listOptionValue>
|
||||
</option>
|
||||
<option
|
||||
id="bug531106.tests.option.symbols"
|
||||
isAbstract="false"
|
||||
resourceFilter="all"
|
||||
valueType="definedSymbols">
|
||||
<listOptionValue
|
||||
value="TC_VALUE">
|
||||
</listOptionValue>
|
||||
</option>
|
||||
<option
|
||||
id="bug531106.tests.option.libs"
|
||||
isAbstract="false"
|
||||
resourceFilter="all"
|
||||
valueType="libs">
|
||||
<listOptionValue
|
||||
value="TC_VALUE">
|
||||
</listOptionValue>
|
||||
</option>
|
||||
<option
|
||||
id="bug531106.tests.option.userObjs"
|
||||
isAbstract="false"
|
||||
resourceFilter="all"
|
||||
valueType="userObjs">
|
||||
<listOptionValue
|
||||
value="TC_VALUE">
|
||||
</listOptionValue>
|
||||
</option>
|
||||
<option
|
||||
id="bug531106.tests.option.symFiles"
|
||||
isAbstract="false"
|
||||
resourceFilter="all"
|
||||
valueType="symbolFiles">
|
||||
<listOptionValue
|
||||
value="TC_VALUE">
|
||||
</listOptionValue>
|
||||
</option>
|
||||
<option
|
||||
id="bug531106.tests.option.incFiles"
|
||||
isAbstract="false"
|
||||
resourceFilter="all"
|
||||
valueType="includeFiles">
|
||||
<listOptionValue
|
||||
value="TC_VALUE">
|
||||
</listOptionValue>
|
||||
</option>
|
||||
<option
|
||||
id="bug531106.tests.option.libPaths"
|
||||
isAbstract="false"
|
||||
resourceFilter="all"
|
||||
valueType="libPaths">
|
||||
<listOptionValue
|
||||
value="TC_VALUE">
|
||||
</listOptionValue>
|
||||
</option>
|
||||
<option
|
||||
id="bug531106.tests.option.libFiles"
|
||||
isAbstract="false"
|
||||
resourceFilter="all"
|
||||
valueType="libFiles">
|
||||
<listOptionValue
|
||||
value="TC_VALUE">
|
||||
</listOptionValue>
|
||||
</option>
|
||||
</tool>
|
||||
<projectType
|
||||
id="bug531106.tests.ptype"
|
||||
isAbstract="false"
|
||||
isTest="true">
|
||||
<configuration
|
||||
id="bug531106.tests.cfg1"
|
||||
name="cfg1">
|
||||
<toolChain
|
||||
id="bug531106.tests.cfg1.tc"
|
||||
isAbstract="false"
|
||||
isSystem="true">
|
||||
<tool
|
||||
id="bug531106.tests.cfg1.tc.tool"
|
||||
isAbstract="false"
|
||||
superClass="bug531106.tests.tool">
|
||||
</tool>
|
||||
<builder
|
||||
id="bug531106.tests.cfg1.tc.builder"
|
||||
isAbstract="false"
|
||||
isVariableCaseSensitive="false">
|
||||
</builder>
|
||||
</toolChain>
|
||||
</configuration>
|
||||
</projectType>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
|||
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||
import org.eclipse.cdt.core.testplugin.ResourceHelper;
|
||||
import org.eclipse.cdt.managedbuilder.core.BuildException;
|
||||
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
|
||||
import org.eclipse.cdt.managedbuilder.core.IFolderInfo;
|
||||
import org.eclipse.cdt.managedbuilder.core.IOption;
|
||||
|
@ -281,4 +282,83 @@ public class OptionStringListValueTests extends TestCase {
|
|||
checkOptionValues(option);
|
||||
}
|
||||
|
||||
public void testSetToEmptyList_bug531106() throws Exception {
|
||||
String projName = PROJ_NAME_PREFIX + "_bug531106";
|
||||
IProject project = BuildSystemTestHelper.createProject(projName, null, "bug531106.tests.ptype");
|
||||
ResourceHelper.addResourceCreated(project);
|
||||
CoreModel model = CoreModel.getDefault();
|
||||
ICProjectDescriptionManager mngr = model.getProjectDescriptionManager();
|
||||
|
||||
ICProjectDescription des = mngr.getProjectDescription(project);
|
||||
ICConfigurationDescription cfgDes = des.getConfigurations()[0];
|
||||
IConfiguration cfg = ManagedBuildManager.getConfigurationForDescription(cfgDes);
|
||||
|
||||
ICFolderDescription fDes = cfgDes.getRootFolderDescription();
|
||||
IFolderInfo fInfo = cfg.getRootFolderInfo();
|
||||
|
||||
ITool tool = fInfo.getToolsBySuperClassId("bug531106.tests.tool")[0];
|
||||
testSetToEmptyList_VerifyValueCount(fInfo, tool, 1);
|
||||
|
||||
//Test clearing
|
||||
IOption slOption = tool.getOptionBySuperClassId("bug531106.tests.option.stringList");
|
||||
ManagedBuildManager.setOption(fInfo, tool, slOption, new OptionStringValue[0]);
|
||||
IOption incPathOption = tool.getOptionBySuperClassId("bug531106.tests.option.incPath");
|
||||
ManagedBuildManager.setOption(fInfo, tool, incPathOption, new OptionStringValue[0]);
|
||||
IOption symbolsOption = tool.getOptionBySuperClassId("bug531106.tests.option.symbols");
|
||||
ManagedBuildManager.setOption(fInfo, tool, symbolsOption, new OptionStringValue[0]);
|
||||
IOption libsOption = tool.getOptionBySuperClassId("bug531106.tests.option.libs");
|
||||
ManagedBuildManager.setOption(fInfo, tool, libsOption, new OptionStringValue[0]);
|
||||
IOption userObjsOption = tool.getOptionBySuperClassId("bug531106.tests.option.userObjs");
|
||||
ManagedBuildManager.setOption(fInfo, tool, userObjsOption, new OptionStringValue[0]);
|
||||
IOption symFilesOption = tool.getOptionBySuperClassId("bug531106.tests.option.symFiles");
|
||||
ManagedBuildManager.setOption(fInfo, tool, symFilesOption, new OptionStringValue[0]);
|
||||
IOption incFilesOption = tool.getOptionBySuperClassId("bug531106.tests.option.incFiles");
|
||||
ManagedBuildManager.setOption(fInfo, tool, incFilesOption, new OptionStringValue[0]);
|
||||
IOption libPathsOption = tool.getOptionBySuperClassId("bug531106.tests.option.libPaths");
|
||||
ManagedBuildManager.setOption(fInfo, tool, libPathsOption, new OptionStringValue[0]);
|
||||
IOption libFilesOption = tool.getOptionBySuperClassId("bug531106.tests.option.libFiles");
|
||||
ManagedBuildManager.setOption(fInfo, tool, libFilesOption, new OptionStringValue[0]);
|
||||
|
||||
testSetToEmptyList_VerifyValueCount(fInfo, tool, 0);
|
||||
|
||||
mngr.setProjectDescription(project, des);
|
||||
ManagedBuildManager.saveBuildInfo(project, true);
|
||||
|
||||
//Close & re-open project
|
||||
project.close(new NullProgressMonitor());
|
||||
project.open(new NullProgressMonitor());
|
||||
|
||||
//Reload config
|
||||
des = mngr.getProjectDescription(project);
|
||||
cfgDes = des.getConfigurations()[0];
|
||||
cfg = ManagedBuildManager.getConfigurationForDescription(cfgDes);
|
||||
|
||||
fDes = cfgDes.getRootFolderDescription();
|
||||
fInfo = cfg.getRootFolderInfo();
|
||||
|
||||
tool = fInfo.getToolsBySuperClassId("bug531106.tests.tool")[0];
|
||||
testSetToEmptyList_VerifyValueCount(fInfo, tool, 0);
|
||||
}
|
||||
|
||||
private void testSetToEmptyList_VerifyValueCount(IFolderInfo fInfo, ITool tool, int count) throws BuildException {
|
||||
IOption slOption = tool.getOptionBySuperClassId("bug531106.tests.option.stringList");
|
||||
assertEquals(count, slOption.getBasicStringListValueElements().length);
|
||||
IOption incPathOption = tool.getOptionBySuperClassId("bug531106.tests.option.incPath");
|
||||
assertEquals(count, incPathOption.getBasicStringListValueElements().length);
|
||||
IOption symbolsOption = tool.getOptionBySuperClassId("bug531106.tests.option.symbols");
|
||||
assertEquals(count, symbolsOption.getBasicStringListValueElements().length);
|
||||
IOption libsOption = tool.getOptionBySuperClassId("bug531106.tests.option.libs");
|
||||
assertEquals(count, libsOption.getBasicStringListValueElements().length);
|
||||
IOption userObjsOption = tool.getOptionBySuperClassId("bug531106.tests.option.userObjs");
|
||||
assertEquals(count, userObjsOption.getBasicStringListValueElements().length);
|
||||
IOption symFilesOption = tool.getOptionBySuperClassId("bug531106.tests.option.symFiles");
|
||||
assertEquals(count, symFilesOption.getBasicStringListValueElements().length);
|
||||
IOption incFilesOption = tool.getOptionBySuperClassId("bug531106.tests.option.incFiles");
|
||||
assertEquals(count, incFilesOption.getBasicStringListValueElements().length);
|
||||
IOption libPathsOption = tool.getOptionBySuperClassId("bug531106.tests.option.libPaths");
|
||||
assertEquals(count, libPathsOption.getBasicStringListValueElements().length);
|
||||
IOption libFilesOption = tool.getOptionBySuperClassId("bug531106.tests.option.libFiles");
|
||||
assertEquals(count, libFilesOption.getBasicStringListValueElements().length);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -51,6 +51,8 @@ import org.eclipse.core.runtime.Status;
|
|||
import org.osgi.framework.Version;
|
||||
|
||||
public class Option extends BuildObject implements IOption, IBuildPropertiesRestriction {
|
||||
private static final String IS_BUILTIN_EMPTY = "IS_BUILTIN_EMPTY";
|
||||
private static final String IS_VALUE_EMPTY = "IS_VALUE_EMPTY";
|
||||
// Static default return values
|
||||
public static final String EMPTY_STRING = "";
|
||||
public static final String[] EMPTY_STRING_ARRAY = new String[0];
|
||||
|
@ -642,17 +644,10 @@ public class Option extends BuildObject implements IOption, IBuildPropertiesRest
|
|||
// Note: These string-list options do not load either the "value" or
|
||||
// "defaultValue" attributes. Instead, the ListOptionValue children
|
||||
// are loaded in the value field.
|
||||
List<OptionStringValue> vList = null;
|
||||
List<OptionStringValue> biList = null;
|
||||
List<OptionStringValue> vList = new ArrayList<OptionStringValue>();
|
||||
List<OptionStringValue> biList = new ArrayList<OptionStringValue>();
|
||||
configElements = element.getChildren();
|
||||
for (ICStorageElement veNode : configElements) {
|
||||
if (vList==null) {
|
||||
vList = new ArrayList<OptionStringValue>();
|
||||
}
|
||||
if (biList==null) {
|
||||
biList = new ArrayList<OptionStringValue>();
|
||||
}
|
||||
|
||||
if (veNode.getName().equals(LIST_VALUE)) {
|
||||
OptionStringValue ve = new OptionStringValue(veNode);
|
||||
if(ve.isBuiltIn()) {
|
||||
|
@ -662,12 +657,30 @@ public class Option extends BuildObject implements IOption, IBuildPropertiesRest
|
|||
}
|
||||
}
|
||||
}
|
||||
if(vList != null && vList.size() != 0) {
|
||||
|
||||
//Assume not empty unless specificaly flagged
|
||||
boolean isValueEmpty = false;
|
||||
boolean isBuiltinEmpty = false;
|
||||
|
||||
if (element.getAttribute(IS_VALUE_EMPTY) != null) {
|
||||
Boolean isEmpty = new Boolean(element.getAttribute(IS_VALUE_EMPTY));
|
||||
if (isEmpty.booleanValue()) {
|
||||
isValueEmpty = true;
|
||||
}
|
||||
}
|
||||
if (element.getAttribute(IS_BUILTIN_EMPTY) != null) {
|
||||
Boolean isEmpty = new Boolean(element.getAttribute(IS_BUILTIN_EMPTY));
|
||||
if (isEmpty.booleanValue()) {
|
||||
isBuiltinEmpty = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(vList.size() != 0 || isValueEmpty) {
|
||||
value = vList;
|
||||
} else {
|
||||
value = null;
|
||||
}
|
||||
if(biList != null && biList.size() != 0) {
|
||||
if(biList.size() != 0 || isBuiltinEmpty) {
|
||||
builtIns = biList;
|
||||
} else {
|
||||
builtIns = null;
|
||||
|
@ -883,14 +896,32 @@ public class Option extends BuildObject implements IOption, IBuildPropertiesRest
|
|||
ICStorageElement valueElement = element.createChild(LIST_VALUE);
|
||||
optValue.serialize(valueElement);
|
||||
}
|
||||
|
||||
if(stringList.isEmpty()) {
|
||||
element.setAttribute(IS_VALUE_EMPTY, Boolean.TRUE.toString());
|
||||
} else {
|
||||
element.setAttribute(IS_VALUE_EMPTY, Boolean.FALSE.toString());
|
||||
}
|
||||
} else {
|
||||
element.setAttribute(IS_VALUE_EMPTY, Boolean.FALSE.toString());
|
||||
}
|
||||
|
||||
// Serialize the built-ins that have been overridden
|
||||
if (builtIns != null) {
|
||||
for (OptionStringValue optionValue : builtIns) {
|
||||
ICStorageElement valueElement = element.createChild(LIST_VALUE);
|
||||
optionValue.serialize(valueElement);
|
||||
}
|
||||
|
||||
if(builtIns.isEmpty()) {
|
||||
element.setAttribute(IS_BUILTIN_EMPTY, Boolean.TRUE.toString());
|
||||
} else {
|
||||
element.setAttribute(IS_BUILTIN_EMPTY, Boolean.FALSE.toString());
|
||||
}
|
||||
} else {
|
||||
element.setAttribute(IS_BUILTIN_EMPTY, Boolean.FALSE.toString());
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue