CSC/ECE 517 Fall 2012/ch2a 2w12 sv

From Expertiza_Wiki
Jump to navigation Jump to search

Build Management

Introduction

Build Management is the process of delivering the software in an executable format .The final deliverables are known as software builds . For simple programs one single file is used for compilation but for complex software there will be a main file which in turn will invoke several other files for code compilation.

Consider the following example

A software build may consist of several ‘.c’ and ‘.h’ files. There will be number of make files which will compile the code files. For building the entire software one main Makefile is written which will call other make files for generating the executable. The files are compiled and linked in order by the Build Utility. If there are no code changes in a file then recompilation is not required. Moreover complicated build utilities and linkers do not recompile the code to save time required for the entire build generation.

Build Automation is a component of Build Management and involves automating the activities that developers perform regularly such as compiling source code into binary code and packaging them, running tests and deploying code at the production site and create documentation related to the same.

History and the need for development

Build automation tools are used to call compilers and linkers from inside the build script. Prior to build script, there was a need to specify the order of the files which the compiler needs to call from the command line. However , it is easier to pass a single file to a compiler which then reads from it and then linker reads from the single build file to create the deployable object. Using build automation, we write build scripts that are called in series which the compilers and linkers use to build software. Additional features were added which allows source code dependency management as well as incremental build management. With the advancement of build automation, different ways were provided to specify pre-jobs and post jobs. Pre-jobs are the jobs which should be executed before the execution of the actual program. Post-jobs are the jobs, which should be executed after the execution of the jobs given in the build file.

Build Management Tools

Make

The make command makes use of the Makefile for compiling the code. The Makefile is generally written in Perl or some other scripting language. The wrapper script takes into account the tasks needed for build automation i.e. source code check out, unit tests execution and deployment of the code by placing it in the suitable directory.

A rule in make file specifies how set of instructions should be executed to generate target files from source files.

A simple rule is of the form
 target: dependencies…
         commands…

Code can be compiled by typing make on the command prompt which looks for a Makefile in the present directory and executes it.The build process has two steps in which the compiler first takes the source code and creates object files. The linker then takes the object files and generates an executable. When executing make the target needs to be specified else it updates the first target mentioned in the Makefile. The intermediate targets are updated before the updation of the final target.The target files should always be up to date. If dependencies are older than the target file, then the target file is already up to date, and it needn’t be generated again.

Here is how a Makefile for compiling kernel modules is

obj-m += helloWorld.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

The above Makefile compiles a kernel module helloWorld.c .all: is the default target for all files and make utility executes this if no other target is specified. The clean: target clears all the compiled code.

Ant

Acronym for Another Neat Tool, ant was developed on a Windows Laptop and now owned by Apache. Ant makes use of XML to describe build processes and corresponding dependencies. By default the build file is given the name build.xml. Ant is useful in building Java applications. Ant can also be used for building non-Java application like C and C++. Ant uses Java to specify the types and tasks to be performed which are stored in “antlibs” . Ant is quite flexible and does not enforce the usage of coding convention and directory layouts to the Java projects which use it as a build tool. An Ant file for compiling a helloWorld.java program

<?xml version="1.0" encoding="UTF-8"?>
<project name="HW.makejar" default="makejar" basedir=".">
<target name ="makejar" description="Create a jar for the HW project">
  <jar jarfile="HelloWorld.jar" includes="*.class" basedir="bin"/>
</target>
</project>

Maven

Apache Maven is a software project management and comprehension tool. Derived from the project object model (POM), Maven manages project's build, reports and documentation from a central piece of information.

Maven configuration is effusive, difficult to read and write. Tasks which can be done in one or two lines of Ruby or XML with Rake or Ant require six or seven lines of pom.xml configuration (assuming it’s possible to write it in Maven).

In Maven certain things are configured as classpath references to .properties files bundled in .jar files configured as dependencies, some things are configured as absolute or relative paths to files on disk, and some things are configured as system properties in the JVM running Maven. Sometimes Maven can recursively build projects in the correct order, but sometimes it’s not.

Rake

Rake is the best build tool for Java Projects. The common build tasks in Rake are performed using certain standard methods and uses Ruby programming language for specifying the commands in Rakefiles which are equivalent of Makefiles when using make.

 file 'helloWorld.o' => ['helloWorld.c'] do
   sh 'cc -c -o helloWorld.o helloWorld.c'
 end
 file 'helloWorld' => ['helloWorld.o'] do
   sh 'cc -o helloWorld helloWorld.o'
 end

Follwing the steps for build process the first sh command creates an object file and then the next sh command creates an executable from object file i.e. helloWorld from helloWorld.o

Scons

Scons is a Python based language and is acronym for Software Construction.SConstruct files which are similar to Makefiles are easier to maintain.SCons also supports C/C++ and Java™ files, and as compared to make Scons needs a lot lesser code.

References