Whether writing code for a small, single-platform environment or contributing to a sophisticated cross-platform, multi-language application, one truth remains consistent: a disorganized or poorly implemented build management strategy will adversely affect a developer's workflow.
Because developers possess an intimate working knowledge of the structure of their code, they are often called upon to write and maintain build scripts. When integration build problems occur during QA, their phones ring. When build problems prevent applications from rolling into production, their inboxes are flooded. These kinds of intrusions on a developer's daily coding practices may start small, but over time, as applications grow in complexity, they can bring a company's entire application development process to a grinding halt. This eventual result can be avoided by implementing a well-thought-out build-management system that empowers the developer while meeting enterprise-level requirements.
In small- and medium-sized environments, using a properly implemented in-house build system can mitigate many of the risks and challenges associated with builds. In addition, with a few simple steps, the burdensome task of developing and maintaining build scripts can be significantly reduced, allowing developers to focus on writing code rather than debugging builds. As development efforts grow in size and complexity, however, there comes a point where significant benefits can be realized by moving to an automated system. Whether using a manually scripted or automated build solution, every enterprise should strive for build consistency, portability, and repeatability.
Build Management Evolution
Application builds are traditionally managed using a rules-based program derived from Make, one of the oldest, best-known build tool. Make controls the generation of executables and other non-source files from a program's source files. There are many Make versions, each with a unique file syntax that precludes portability between development tools, operating systems, or even compilers within the same operating environment.
Java development required a new, platform-independent build tool, leading to the creation of Apache Software Foundation's Java-based Ant, so-named by developer James Duncan Davidson because, "…it is a little thing that can build big things." Ant eliminates Make's platform-dependent problems and is extended not with shell-based commands but Java classes. Configuration files are XML-based, calling out a target tree where various tasks get executed. Each task is run by a Java class that implements a particular task interface.
Ant is powerful, but the XML configuration scripts can create limitations. XML does not handle conditional logic effectively and therefore it's difficult to use Ant to write "intelligent" build scripts that support robust batch processing. In addition, many development projects include Java and non-Java components that require both Ant and Make, as neither handles both languages. Scripting for the two is very different. Make scripts are the input to Make programs and dictate how to build each software component. A Make file tells the Make program which binaries are to be created from which source modules. Make rules are then "fired" based on out-of-date conditions between source and object. In contrast, Ant/XML scripting uses serial batch processing. Rules for creating Java binaries such as .jar, .war, and .ear are handled statically for each step or "task" in the XML script. Listing 1 shows the differences between Make and Ant scripts for a similar type of build task.
For either approach, the programmer must understand not only how the application is constructed, but also the specific syntax requirements of the build scripting language they are using. In addition, Make and Ant/XML scripts are not re-usable because static application information is coded into the script.
Make and Ant/XML Challenges
As client/server and Java development has evolved, so has build complexity, especially with Make. When Make is used recursively (one Make file per final target executable, or binary - the most common method of managing large build processes), an application with 50 binaries would require 50 Make files plus a "driver" Make file. The system build is completed by calling the Make program repeatedly and passing a different Make file each time. Dependency checking between the individual Make files is impossible, which means large application Make files can't be managed by a single Make file. Developers get around Make challenges through clever file-ordering to track dependencies, along with object-borrowing and multisystem parallel building techniques to reduce the associated long system build times. The process is still difficult and cumbersome - especially when there are multiple circular dependencies between executables and libraries, which require multiple builds to achieve the desired results.
Although most Ant build systems do not appear to be as complex as many Make-based build systems, it is only a matter of time. Because Ant is a relatively young technology, Ant-based build systems have not been subjected to the years of additions and changes that can corrupt and obscure what originally appears to be an elegant build scripting solution. Over the years, as Ant scripts suffer from being passed through different developers' hands, as new technology emerges that effects the way Ant scripts are coded or used, and as applications grow more complex, Ant will encounter many of the problems associated with a Make-based system.
Scripted build processes also introduce other challenges that devour developers' time. In fact, build scripting can be the most time-consuming and resource-intensive component faced by development teams. Problems scale with an environment's size and complexity. The key is to implement best practices for manual scripting starting with an in-house build system, while monitoring factors that would signal the need to move to an automated, non-scripting approach.
Solving Typical Scripting Problems
Scripting challenges are easier to solve in small, homogeneous development environments confined to a single language and target operating system. However, most companies strive to expand product reach and capabilities; as scope grows, development complexity follows. A company that lays the groundwork for an organized build process early on will better overcome future growth challenges.
The first step is to shift from a developer-centric view of builds to a team-centric view, and from the notion of scripting "my build solution" to scripting "our build solution."
Build inconsistency is the toughest problem. If developers use their own build scripts in the language or tool of choice, it can be difficult to know whether problems result from bad code or a bad build. Build administrators must standardize on a single scripting approach that best suits the language being used.
The first step to reducing build inconsistency between individual developer's build scripts is to develop build script templates that can be used as a basis for all build scripts. All builds require the same basic information: source code, compiler, and final target. Individual developers can populate the build script templates with their own build specifics, i.e., the source code location, compiler location, and a final target description. Build script templates should be well commented and clearly organized to ease the process of populating the template with build-specific information.
A major contributing factor to build inconsistency is a lack of compiler and third-party library standardization. In a disparate build environment, developers frequently build against different versions of compilers and third-party libraries. This makes it difficult to re-create builds and diagnose problems. Instead, to promote standardization, all compilers should be centralized on a network drive accessible by all developers, on a clean and "locked down" machine. The build script templates should specifically reference the standard compiler versions on the mapped network drives, ensuring that all builds occur against consistent compiler versions. All third-party libraries should similarly be consolidated on a shared network drive so that the latest, approved versions are used.
Another commonly faced problem is a lack of build portability. Builds often work only on an individual developer's machine, which by default becomes the "production" build machine. The philosophy is, "build it where it builds and get it out the door." Obviously, this approach to builds can cause severe problems when trying to track down bugs that are discovered once an application has been released to production. To solve this problem, development teams should standardize their directory structure. All developers should work on code in the same directory structure. If a versioning or CM tool is used, pull the directory structure from it; if not, enforce strong directory conventions for all developers.
Portability problems can also be mitigated by using global variables in the build script templates that identify the root location for all source code, compilers, and common libraries. By setting environment variables, such as SRC_HOME, COMPILER_HOME and COMMON_HOME, the same build scripts should work on all machines. Using global variables in the build script templates also reduces the amount of template editing that is required by developers.
The Make code (see Listing 2) is a generic example that demonstrates the use of a standardized compiler to ensure build consistency and the use of global variables to guarantee portability. Note the global variables defined at the top of the script. Each developer can edit the values to suit his or her own workstation. In addition, the cc compiler is pulled in through a shared network drive referenced in the COMPILERDIR variable.
The Ant script in Listing 3 demonstrates a similar use of global properties to ensure consistency and standardization.
Finally, isolate the build scripts to just that: builds. Too often, "build" scripts include substantial pre- and post-build logic unrelated to the build. Pre- and post-build logic can be extremely complex, especially as an application matures and development is being performed on multiple versions simultaneously. The Ant script in Listing 4 demonstrates a build script with a very basic and generic deployment portion.
Rather than writing pre- and post-build logic within a build script (where the functionality is often limited by the scripting language or tool), place the non-build logic in external scripts. The external scripts should be written in a scalable, lightweight, and cross-platform language such as PERL or PYTHON. Tightly focused build scripts can then have built-in hooks to the external build utility. Listing 5 takes the overly complex build script of the prior example and replaces it with a call to an external script.
By partitioning the build scripts in this way, developers (or build masters) who encounter build problems can drill down to the root cause very rapidly. In addition, as development grows in complexity and new languages or target operating systems are added, the in-house build utility can scale more effectively. For example, consider a C and C++ development shop that uses an entirely Make-based build system with all pre- and post-build logic written in the Make scripts. When the development shop decides to add a Java component to their application, they are faced with writing an Ant component (equivalent to their existing Make scripts) that manages all Java-related pre-build, build, and post-build logic. However, if the development shop has a build utility, written in PERL, that executes Make scripts limited to build execution, they only have to write Ant scripts that handle the Java builds, and can use the existing PERL framework as a basis for all of the non-build functionality.
Dealing with Growth
As development environments grow, new distributed-management requirements are introduced and problems grow more complex. Good build management approaches will, for the most part, scale effectively, but there are several new problems that are often added to the mix.
For instance, the more complex the environment, the more likely it is that there will be longer delays between when builds break and when those breaks are identified. Developers might execute builds on their own machine and perform successful unit testing, only for the integration build to break when the developer's code is introduced. The solution is to perform a regular "nightly" build once build scripts are consistent, predictable, and portable. This ensures that each developer's latest revisions will be tested in an integration build so problems are immediately identified. Another solution is to place all enterprise-wide common code on a shared network drive (often called a reference directory). This ensures that all development teams are building against the latest approved versions of enterprise-wide common code. If a change in common code corrupts a developer's work, it will be discovered immediately.
Another common problem in complex environments is build scripting inconsistency resulting from development in multiple languages. Build administrators can either force a single scripting language or maintain different build scripts for different teams (Make, for example, works for C and C++, but is not particularly well suited for Java). The best approach is to maintain different scripts with isolated build functionality using a consistent, cross-platform, lightweight scripting language for all non-build functionality (e.g., retrieving code from a CM tool, moving files around, deploying binaries, etc.). Separating build functionality from all non-build functionality limits variances. There is no reason to be using Make or Ant scripts to copy files around or make a logical decision during batch processing.
The third most common problem in complex environments is the lack of an effective audit trail. Log all build script templates and "non-build" script components and make sure audit trails track source code to the executable. For each action that touches source code (check-out, move, compile, etc.), embed a logging message into the script templates. This is facilitated by adding a basic bill of materials report to the in-house build solution, including:
One of the first breaking points occurs when the amount of time it takes for an application to build begins to limit unit- and integration-testing effectiveness. Only the items that need to be built should be built, in a true incremental approach. Another breaking point is excessive problem-resolution turnaround time, because the development environment scales beyond the capabilities of the in-house scripted manual build system. Developers find themselves spending most of their time tracking down what source code and common libraries went into a built object rather than resolving coding problems.
A sure sign that developers are reaching the limits of manual scripting efficiency is when they find themselves consistently spending as much as an hour a day working on build problems (either their own, or debugging build problems of a centralized CM team). Many companies actually assign a dedicated CM team whose sole responsibility is to execute builds. Developers find themselves waiting for the CM team to build their applications before they can move on to the next development effort. It can reach the point where the centralized CM team simply cannot keep up with the demand, especially when builds are cross-language, cross-platform and incredibly complex.
Conclusion
Through careful build-management planning and implementation, developers are freed up to focus on the development they were hired to perform. By optimizing a developer's workflow, companies are more capable of meeting market pressures with increasingly sophisticated and robust applications. The practices outlined above can be used to develop a build system that handles current build requirements, while paving the way for an orderly transition to automated build strategies that will enable significantly more flexible and manageable development environments.
Migrating to an Automated, Non-Scripting Build-Management Environment
To solve the problems described in the article, teams within medium- to large-sized development environments are now turning to tools based on a true client/server architecture with a central build knowledge base. Introduced over the past five years, this new class of build tool provides a standardized method for creating and managing Build Control files that replace Make and Ant/XML manual scripting. This approach eliminates the portability issues of rule-based programs derived from Make, while resolving the standardization challenges associated with scripted build processes based on Ant/XML.
One example of this approach is Openmake, a build management tool from Catalyst Systems Corporation that weaves together human and machine intelligence to automate and standardize the enterprise build process. It incorporates a browser-based user interface and a Tomcat, WebSphere, or OC4J Application Server to provide access to an Openmake Knowledge Base Server (see Figure 1). Enterprise-based features allow for the connection to multiple remote build servers. Simple Object Access Protocol (SOAP) is used as the communication layer between the browser and the application servers.
Developers interface with Openmake through a Web client, a command-line interface, or indirectly through IDE plug-ins. Build metadata is stored and managed via the central Openmake Knowledge Base Server and reused by multiple developers to generate Ant/XML scripts for Java support, or to generate "Make"-like scripts for traditional build requirements. Build Control files can be generated to build a single object (supporting developer daily compile activities) or a complete application (containing hundreds of interdependent modules). When a complete application Build Control file is generated, it eliminates the problem of recursive Make and ensures the accuracy of incremental builds. Builds can be managed from an empty build directory pulling source code from a predefined search path, or by retrieving source code from a version management tool. Openmake also allows control over environment variable settings such as LIB, INCLUDE, and CLASSPATH so that, regardless of the build machine, the build results are the same.
Developers begin by choosing from among an extensive list of predefined build types, with the option of modifying these templates, as needed. The build type templates are comprised of one or more preconfigured build tasks, enabling developers to quickly and easily craft a completely customized build framework without having to write custom scripts or build classes. Because the build types are stored centrally, all development teams work in a consistent, standardized manner throughout the distributed build process.
Openmake does not replace Ant for completing Java builds, but rather extends the use of Jakarta Ant without the need for manually coding XML scripts. In the place of hard-coded Make and Ant/XML scripts, for instance, Openmake's powerful rules engine takes advantage of its knowledge base of build metadata, such as target name and dependency information, to dynamically generate portable, PERL-based build processes at build time that can be referenced by multiple development teams.