The Road To Build Enlightenment

by Jason Sankey on Wednesday, 23 August 2006

Introduction

Software developers interact with build systems many times a day. However, development and improvement of the build system is often not a high priority. After all, developers are time-poor and need to devote their energy to the software itself. Once a passable system is in place, it will often be tolerated, and the team will get on with the immediate job at hand.

This attitude belies the fact that a better build system will actually save time in the long run. The best build systems not only build and test the software efficiently and effectively, they can also provide crucial feedback during the development cycle. This feedback helps improve team communication, software quality and overall productivity.

This article describes the properties of an effective build system, starting from the most basic requirements and working towards more advanced features. Follow the article step-by-step to drag your build system out of the darkness and attain build enlightenment!

Prerequisites

Source/Version Control

Before discussing the build system proper, an absolute requirement for an effective build system is use of a source/version control server such as Subversion. Source control brings many advantages, most of which are beyond the scope of this document. Crucially for the build system, the source control server provides a central repository containing the One True copy of the project source. The project source, including the build system itself, should be accessible from the source control server via a simple checkout.

Basic Necessities

Step 1: Machine Independence

The build must be independent of the machine it is executed on. Rather than having a single "build machine" that is set up to perform builds, every development machine should be capable of executing a full build. Even external dependencies (such as compilers and libraries) should be kept to a minimum, and made available as simply as possible. One way to ensure easy availability is to check these dependencies into your source control server. Some build tools (such as maven) will themselves assist in managing some types of dependencies.

Key Benefits

Challenges

Step 2: Scripted Builds

Put simply, you must be able to build your project by executing a single command from a command-line/shell. The build process must be automatic and repeatable. Scripted builds are typically achieved using a build tool such as ant, make, or MSBuild. The advantage of using such tools is they allow large parts of the build to be scripted declaratively, and have support for common tasks such as dependency analysis. Don't roll your own build tool: leverage what is already available.

Key Benefits

Challenges

Step 3: Scripted Tests

Being able to build your software is not very useful if you have no way to determine whether the built product actually works. To determine this, you need to test the product. Further, developers need to be able to do this frequently (several times a day). The only practical way to achieve this is via an automated test suite. Using one of the many "xUnit" testing libraries (born out of JUnit) you can write code to exercise and verify the functionality of your product. Once you have an automated test suite in place, you should integrate it with your scripted build. With a single command, you should be able to build and test your software.

Key Benefits

Challenges

Step 4: Regular Builds

Now that you can build and test your software automatically, the next stage is to do so regularly. This build should run on one or more independent machines (i.e. machines not used during regular developments). This will help identify unwanted dependencies on the development environment. A regular build provides vital feedback: if your build or tests break, it is best to find out as soon as possible. Think of it as a regular health checkup for your project. Again, various tools (including our product Pulse) are available to help set up regular builds. These tools offer various features to help schedule builds and report on the results.

Key Benefits

Challenges

Taking it to the Next Level

Step 5: Continuous Integration

Once you have the facility to perform regular builds, a natural question is how often you should execute the build. The answer is simple: as frequently as possible. One particularly useful way to schedule automated builds is whenever a change is committed to the source control server. This facilitates early feedback when a change breaks the build, allowing the problem to be addressed immediately. The longer a build breakage goes unnoticed, the more team members will be affected, and the harder it will be to track down the change(s) that caused the problem. Scheduling builds in this way is one of the core practices of continuous integration. I strongly recommend that you read the original article by Martin Fowler, which both gave a name to and helped popularise this practice.

Key Benefits

Challenges

Step 6: Automated Releases

By now, you should have a taste for the efficiency benefits of automation. A natural extension of your automated builds is handling releases of your software. This typically includes tasks such as assiging a version number, tagging the project source code, building the product, creating release notes, creating installation packages and publishing them to a repository. By scripting the release process, you make building releases trivial. Apart from being more efficient, this allows releases to be made quickly in response to customer requirements. By releasing early and often, you can enjoy feedback from your customers earlier in the development cycle.

Key Benefits

Challenges

Step 7: Building in Multiple Environments

Most software is designed to support multiple environments, such as different operating systems, runtimes and so on. To properly verify the software, it should be tested in as many environments as possible. This can be achieved by running builds on multiple machines, and/or by parameterising the build script so that it can target different environments. A good automated build system will support building in multiple environments, including the ability to execute builds across multiple machines.

Key Benefits

Challenges

Extra Credit

Static Analysis

From the venerable lint to newer products such as Coverity and PMD there are many, many tools that can statically analyse your code and warn of potential problems. After the initial setup cost, an effective static analysis tool will easily pay for itself by detecting problems early in the development process. Integrating static analysis into your automated build system will ensure any problems found by these tools are noticed as soon as they are introduced.

Dynamic Analysis

Running your build and test suite frequently provides a prime opportunity for dynamic analysis of your software as it runs. For example, you may employ a code coverage tool such as Clover or BullseyeCoverage to report how well your code is exercised by your test suite. This is especially useful for identifying sections of your code that need further testing.

Return to articles index.