The Eclipse CDT build system automatically scans the files in my project folders and adds them to the list of files to be built. That works great if files are added through Eclipse and its plugins: That way Eclipse is notified and aware, and has the files added. But what if I have added files externally (outside of Eclipse)? how can I make Eclipse aware of it?
A new file could have been added by an external script, e.g. to generate new source file with a pre-build step with a time stamp or any other build related information. If that file is always new and does have a different file name, Eclipse is not aware of it. So I need to make sure the Eclipse project ‘knows’ about it before the build. So I need to ‘refresh’ the project or workspace before the build.
In this post I’m using Eclipse Neon 4.6 with the example of MCUXpresso IDE, but any other Eclipse distribution or version can be used.
Obviously, there is the ‘Refresh’ menu to manually update the list of files:
And then the new file will show up:
But this is a manual process. What I would like to do this automatically before every build.
There is the Eclipse ‘Refresh Policy’ feature. Unfortunately, that refresh is only *after* the build:
So this does not help.
There is are two settings in the workspace which usually are not turned on:
This will do extra polling in the background, or when I access the files/folders in the project view.
It works that way, however because of the polling this adds more load to my host system, especially with many open projects in the workspace. Plus it is for *all* projects in the workspace. What I need is something just for a single project.
Custom Builder for Refresh
The solution I’m using is to add a custom action to the project ‘Builders’ setting:
Use the ‘New…’ button to add a new builder action, and use afterwards the ‘Up’ button to have it first in the list so it gets executed before the ‘CDT Builder’:
As program to execute specify something, for a refresh it really does not matter. So it could be any ‘dummy’ program. What I’m using on my side is the ‘echo’ program from the GNU ARM Eclipse build tools suite:
What it does it prints the argument string to the console like this:
So the program does not matter. What matters are the refresh settings for that action:
With this, the action (either a dummy action or the action to create a new file with a timestamp) will cause a refresh of the selected (project) folder and all folders inside (recursively). Done :-).
I love Eclipse because it can do pretty much everything. With the custom builder settings I can do custom actions before (or after) the build without the need to manually write make or build files (but make files are still very, very useful).
Happy Refreshing 🙂