views:

413

answers:

5

We are migrating our works repository so I want to do a cull of all the unreferenced files that exist in the source tree before moving it into the nice fresh (empty) repository.

So far I have gone through by hand and found all the unreferenced files that I know about but I want to find out if I have caught them all. One way would be to manually move the project file by file to a new folder and see what sticks when compiling. That will take all week, so I need an automated tool.

What do people suggest?

Clarifications:
1) It is C++.
2) The files are mixed. I am looking for files that have been superseded by others but have left to rot in the repository - for instance file_iter.h is not referenced by any other file in the program but remains in the repository just in case someone wants to compile a version from 1996! Now we are moving to a fresh repository we can safely junk all the files that are no longer used.
3) Lint only finds unused includes - not unused files (I have the 7.5 manual in front of me).

+2  A: 

You've tagged this post with c++, so I'm assuming that's the language in question. If that's the only thing that's in the repository then it shouldn't be too hard to grep all files in the repository for each filename to give you a good starting point. If the repository contains other files (metadata, support files, resources, etc) then you're probably going to need to do it manually.

Andrew
A: 

A static source code analysis tool like lint might do the job. They will tell you if a piece of code will never be called.

Maximilian
A: 

Have you taken a look at Source-Navigator? It can be used as an IDE but I found to be very good at analyzing source code structure. For example, it can find out where and if a certain method is used in your source code.

I don't know if it's scriptable but it might be a good starting point for you.

Maximilian
+1  A: 

I can't offer an existing tool for it, but I would expect that you can get a lot of this information from you build tools (with some effort, probably). Typically you can at least let the build tool print the commands it would run, without actually running them. (E.g. the -n option of make and bjam does this.) From it you should be able to extract at least the used source files.

With the -MM of g++ you can get all the non-system header files for the given source files. The output is in the form of a make rule, but with some filtering this shouldn't be a problem.

I don't know if this helps; it's just what I would try in your situation.

mweerden
A: 

You can actually do this indirectly with Lint by running a "whole project analysis" (in which all files are analysed together rather than individually).

Configure it to ignore everything but unreferenced variable/enum/function etc warnings and it should give you a reasonable indicator of where the deadwood lies without those issues being obscured by any others in the codebase.

Anna-Jayne Metcalfe
I'm currently on holiday and don't have the lint manual to hand but I can see how that will show me the unused files in the source code folder. I'd be happy if you show me a way to do that...
graham.reeds
Hi Graham,The trick is to generate a .lnt file which lists all of the files in the solution, and turn off everything but the global wrapup.If you privmail me when you get back (anna AT riverblade . co . uk) I'll be happy to walk you through setting it up and interpreting the results.
Anna-Jayne Metcalfe