It’s been quite a while since I looked at that code, but what I remember is there are actually two states of the option. The getOptionById I believe gets you the working copy of the option. So if you have the build settings UI open, that’s the current
value in the UI, whereas getOptionBySuperTypeId gets you the persisted value. When the UI is not open I think you just get the persisted option. Basically when the id ends in .some_number it’s the possibly dirty working copy.
I also remember that changing these toolchain-wide options does not dirty the configuration by default. Since you probably want to rebuild the configuration when changing such options, you need to handle that yourself. It’s pretty easy though. Just
specify a valueHandler for each option. Your valueHandler can extend ManagedOptionValueHandler and override handleValue. Something like this:
@Override
public
boolean handleValue(IBuildObject configuration,
IHoldsOptions holder, IOption option, String extraArgument,
int event) {
if (event == IManagedOptionValueHandler.EVENT_APPLY && ((Option)
option).isDirty()) {
IConfiguration config = ((IToolChain)holder).getParent();
if (config !=
null) {
config.setRebuildState(true);
}
return
true;
}
return
false;
}
Hi Warren,
Thanks for your response.
Earlier, I had played around a bit with Command-line generators (but at the option level). I had noticed that at least the 'All Options' scroll box in the Build Settings UI for tools was not getting updated when I changed the toolchain-level option value. The
command generator was getting invoked but it was NOT picking the value entered in the UI, but was picking the value saved earlier probably in the .cproject file. The code for the command-generator for the option (added on the invisible option) is inlined below:
public String generateCommand(IOption option, IVariableSubstitutor macroSubstitutor) {
// get the selected project from workbench
IProject p = getSelectedProject();
if (p == null) return "";
IManagedBuildInfo buildInfo = ManagedBuildManager.getBuildInfo(p);
IConfiguration activeConfig = buildInfo.getDefaultConfiguration();
IToolChain tc = activeConfig.getToolChain();
for (IOption optn : tc.getOptions()) {
if (option.getBaseId().equals("my.toolchain.compiler.model"))
{
if (optn.getBaseId().equals("my.toolchain.general.model")) {
return "--model" + optn.getValue();
}
}
}
return "";
}
My questions are:
1. Does the command-generator always picks the saved settings (from .cproject) and not from the UI? Would even the tool-level command generator (as you recommend) do the same? Or, is above code not correct to access tool-chain option value?
2. Does pressing 'Ok' on the C++ Build Settings dialog guarantee that the settings are saved on the file-system? I've sometimes noticed that the changes done in the build-settings UI are not getting reflected in the .cproject file?
Thanks,
Ashutosh