Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev] Programmatically excluding files from build - not saved

I take the lack of response to my previous question as confirmation that nobody knows of a better way to achieve my goal and excluding files from build is the way to go. So, on to my next question that I already alluded to in passing:

I'm trying to programmatically set the "exclude from build" setting of a file in a CDT project, i.e. modify the source folders and exclusion patterns of the active configuration. I have found two ways of doing that:

	bool exclude = true;
IManagedBuildInfo buildInfo = ManagedBuildManager.getBuildInfo(project);
	IConfiguration activeConfig = buildInfo.getDefaultConfiguration();
	ICSourceEntry[] sourceEntries = activeConfig.getSourceEntries();
	Path newPath = new Path("my/test/file.cpp");
sourceEntries = CDataUtil.setExcluded(newPath, false, exclude, sourceEntries);
	activeConfig.setSourceEntries(sourceEntries);

or

	bool exclude = true;
	IFile file = project.getFile("my/test/file.cpp");
IResourceConfiguration ResConfig = activeConfig.createResourceConfiguration(file);
	ResConfig.setExclude(exclude);

Both achieve the desired modification in "Properties > C/C++ Build" on the file and "Properties > C/C++ General > Paths and Symbols > Source Location" on the project, however the change is neither saved to the .cproject file immediately nor does it appear to be scheduled for future saving - when I close the project at this point and reopen it, the change is lost. Only when I manually make another change to the project (opening the Properties dialog on any file and clicking OK seems to be sufficient), the exclusion is properly saved.

What do I have to do in addition to the code above to make the change persistent?

I have tried setting the "dirty" flags that exist on various involved objects (activeConfig, buildInfo, buildInfo.getManagedProject()) but that didn't help (IIRC most were already set anyway).

I have also noticed that during the Scanner Configuration Builder (my code runs in a custom builder before that), code is executed that serializes the project to XML, and that serialization does contain my modification, but apparently doesn't end up in the .cproject file (I have not followed its complicated paths any further).

 -Christian


Back to the top