SVN shared modules / dependency management

dependenciesdependency-managementlibrariessvn

I'm working with a small-ish team of developers. We're using Subversion for version control. Much of the software is for embedded systems.

We want to set up a reasonably convenient way to share internally-developed software/firmware modules among multiple projects. Desirable features include:

  1. To be able to pull shared modules down inside whatever projects use them, and build them in place. (Makes for easy zipping / exporting.)

  2. To have traceability into what projects uses a shared module, if possible. (i.e. To be able to answer the question, "Which projects use FancySharedWidget?".)

Questions

  1. I'm thinking a reasonable repo setup / folder hierarchy with svn:externals (with explicit revision numbers) will meet #1 nicely. Right?

  2. Can I meet requirement #2 with svn:externals?

    a. Maybe with a post-commit hook, to track when external svn props are added or modified? Do any such scripts already exist?

  3. Are there better tools approaches for the job? (Preferably in addition to combination with svn. I don't forsee convincing the company to move away from svn , though I'm personally interested in hearing what else is out there.)

4. Meta: does this post belong here, or on Stack Overflow?

Best Answer

Externals can be used for what you are trying, but first you should check if you really need them. For our team, it is mostly sufficient to have our shared modules in a folder below named shared_libs, and let all using projects reference that folder by a relative path. However, one will need externals if you are going to have the libs/shared modules in different local folders below your project folder. That way, you can handle situations where you need

  • Project A to reference shared module L version/revision 1.0

  • Project B to reference shared module L version/revision 1.1

both at the same time in local your development environment. By using externals, you cannot just control to have different copies at different locations in your development environment, you get also fine grained control which revision, or branch, or tagged version of the lib/module you want to have placed there.

For us, however, it is mostly sufficient to have different versions of the same lib in our production environment only (we use some externals, but not for the majority of shared libs). For testing and deployment, most of our build scripts pull the compiled results into a test or deployment folder, without the help of SVN.

The drawback of using externals is that you have increased administrative effort - you might need to update explicitly to a newer version of a lib in each project which uses it. For editing and commiting changes your libraries source code directly in the external's checkout folder you will have to utilize the peg-revision mechanism of SVN (or maybe its exactly what you want to prohibit). And if your shared libs are dependent from other shared libs, maybe recursively, you have to make sure the relative paths of all those libs in your local file system are always similar to each other. You will have to validate if this what you need and/or what you want.

Concerning your second question: SVN is not really the right tool for tracking dependencies, the only reliable place where the dependencies are stored are your make files / project files / build scripts / linker files (whatever you use for your build process), so my first suggestion would be to scan those files by a script to collect dependency information. Nevertheless, if you are going to use SVN externals consequently for every shared module dependency, I am sure you can write a script which iterates over the projects in your repo(s) and collects which externals are added there. And I do not think you will need a hook for that, just utilize svn propget svn:externals for this, as shown here.