Some silicon vendors provide their Eclipse example and SDK projects using linked files and folders. For example a bootloader demo application is provided in the context of an SDK or library. That’s fine until the time I want to transform such an example into a real project or if I want to have it without the hundreds of files for all the other devices I don’t need or use. I cannot take the project and put it into a version control system as the linked files won’t be in my VCS. I cannot move the project to another place as the links are pointing to many places. What I need is a ‘standalone’ project: a project which has all the needed files in it and is self-containing.
Don’t take me wrong: Linked files/folders and virtual groups are a great feature in Eclipse (see “Link to Files and Folders in Eclipse“). But as with any great feature, it can be misused or overused. I understand it is easier for the vendor to provide linked files and folder. But to use such a linked files/folder and virtual groups project makes it really hard to start my application and design.
Linked Files and Folders
Linked Files/Folders do not place the files physically into the project. Instead it uses ‘pointers’ to the real files and folders. That’s great if I want to share files between projects and keep a single copy. This is indeed the case for SDK or library files provided by a vendor: the GPIO driver can be shared between multiple derivatives/devices, so the project can link to it:
As with the example above, the fsl_gpio.c is a linked file, and it is using a project relative location:
The problem with that is that as soon the project location gets changed, all the links are broken :-(.
So while for the SDK it makes sense to share the GPIO driver, for any other usage of the project it creates a dependency which is hard to keep up. I rather want to have that GPIO driver inside my project folder structure.
Transforming a Linked Project
Unfortunately there is no magic button to transform a linked project into a normal standalone project. One obvious way is to create a new project and then copy over the needed files. Obviously that is a very time-consuming process.
But what I have found is a process which makes it easier to transform a linked project into a standalone project. What I’m using is to ‘export’ and then ‘import’ the project again.
Export as Archive File
In Eclipse, use the menu File > Export, then use General > Archive File:
In the next dialog, select the projects/files and folders to be exported. Have the following options enabled:
- Resolve and export linked resources
- Create directory structure for files
💡 That checkbox ‘Resolve and export linked ressources’ is present in Eclipse Neon or later. Earlier versions of Eclipse do resolve the linked ressources during export automatically and it cannot be disabled.
This creates an archive (zip) file with folders for the groups and resolved links:
Import Archive File as Existing Project into Workspace
The next step is to import the project again.
💡 Since it is not possible to have the same project name twice in a workspace, either remove the previous project or rename the project, or have it open in a temporary workspace.
Use the menu File > Import and select the Existing Projects into Workspace option:
Select the file we have exported in the previous step and import it:
And now we have a project with all the linked files and folders resolved:
Settings and Missing Files
While we have a great start, probably the project does not fully compile yet. For example the toolchain include/header paths are still pointing to the folders outside the project. You have to fix the settings:
The other missing thing might be header files. The export does only export the folders and header files which are present as links in the project. So there might be headers or include folders which are missing. Copy the missing files and folders into your new project.
💡 It is a good idea to have the ‘linked’ project open in a separate workspace/Eclipse instance. So it is easier to find out where the missing files are located on the disk.
Linked files and folders are a pain if such a project needs to be moved or changed. It is better and easier to have the files standalone and not linked. To transform a linked project into a standalone one, I use the trick to export it as an archive and then import it as ‘existing project’ from that archive. With a few more tweaks, I have a standalone project which is transparent with all the files and which easily can be moved around, passed to a co-worker or put into a version control system. And the presented approach makes it easier to take a project out from of a complex and linked directory structure, and I can use the project in standalone mode, with only the needed files.
Happy Unlinking 🙂