ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ant-...@apache.org
Subject [Ant Wiki] New: AntTools
Date Tue, 05 Oct 2004 22:19:04 GMT
   Date: 2004-10-05T15:19:03
   Editor: JackWoehr <jax@well.com>
   Wiki: Ant Wiki
   Page: AntTools
   URL: http://wiki.apache.org/ant/AntTools

   Explain Buildant briefly with an example

New Page:

= Tools helping the programmer / build jockey to utilize Ant more efficiently =

== Buildant ==

http://softwoehr.com/softwoehr/oss/index.html#Packages.BuildAnt

Buildant is an m4 macro tool for building build.sh scripts to use in conjunction with Apache
Ant projects.                      
                                                                                         
                                      
For every substantial project whose build I automate via Ant scripts, I find myself writing
a build.sh script which takes options and converts them into                             
                       
Ant properties for the build. Buildant automates this process. It writes you a build.sh script
with your options from a simple description file.

Here is the shorter of two sample scripts provided with Buildant:
{{{
# Sample of using buildant to autogenerate build.sh files.                               
                                      
open_buildant(`# My Sample build script'                                                 
                                      
`# Copyright *C* 2004 Jack J. Woehr'                                                     
                                      
`# PO Box 51 Golden Colorado 80402-0051 USA'                                             
                                      
`# jax@well.com'                                                                         
                                      
)dnl                                                                                     
                                      
build_option(`d',                                                                        
                                      
       `dest.dir',                                                                       
                                      
       `Destination directory for built objects',                                        
                                      
       `/tmp',                                                                           
                                      
       `y',                                                                              
                                      
       `destination_directory')dnl                                                       
                                      
build_option(`t',                                                                        
                                      
       `toggle.option',                                                                  
                                      
       `This is a toggle option that is set to true or not set at all.')                 
                                      
close_buildant()dnl
}}}
Here is the script output by the above sample script:
{{{
# Sample of using buildant to autogenerate build.sh files.

# My Sample build script
# Copyright *C* 2004 Jack J. Woehr
# PO Box 51 Golden Colorado 80402-0051 USA
# jax@well.com

# Self documentation 
USAGE_MESSAGE="
Usage: $0  [-option] [-option] ... [--] [-ant_option] [-ant_option] ... [target] [target]
...

    If no targets are passed in, the default target in build.xml will be built.
    Options set in this file override any set in build properties files. The options
    set in this file may also result in calculated settings overriding other options
    in build properties files. To pass options to Ant itself, use the -- option to
    end the options list ... all subsquent options will then be passed to Ant itself.

    All options are:

         -h
             ... Display this help message and exit with return of 0.

         -d destination_directory
             ... Destination directory for built objects

         -t 
             ... This is a toggle option that is set to true or not set at all.

"

# One default to allow you to compose an option for a custom
# Ant invocation ... just define an option called "ant.invocation"
# to override this as used below for the build command.
ANTBUILD_ant_invocation="ant"

# These are the defaults for various options.
# Their names represent the ant properties they shadow in this shell script.

# option -d
ANTBUILD_dest_dir="/tmp"    

# option -t
ANTBUILD_toggle_option=""    

###################################################################
# Function to show a message (and exit if numerical status given).
# Usage: 
#	display_usage
#		- or -
#	display_usage 0
#               - or, e.g. -
#       display_usage 37
###################################################################
function display_usage () {
	cat << END
${USAGE_MESSAGE}
END
if [ $# -gt 0 ]
then
	exit $1
fi
}

#######################################################################
# Function converts script args to Ant build properties as appropriate.
#######################################################################
function convert_args_to_properties () {

    # option -d
    if [ -n "${ANTBUILD_dest_dir}" ]
    then
	BUILD_PROPERTIES="${BUILD_PROPERTIES} -Ddest.dir=${ANTBUILD_dest_dir}"
    fi

    # option -t
    if [ -n "${ANTBUILD_toggle_option}" ]
    then
	BUILD_PROPERTIES="${BUILD_PROPERTIES} -Dtoggle.option=${ANTBUILD_toggle_option}"
    fi
}

# Get arguments to script
while getopts hd:t an_opt

        do
        case $an_opt in
           h) display_usage 0;;
           d) ANTBUILD_dest_dir=${OPTARG};;
           t) ANTBUILD_toggle_option=true;;

          \?) echo "Invalid option \"-${OPTARG}\" to $0"
              display_usage 1;;
        esac
        done

# Clean up options
shift `expr ${OPTIND} - 1`

# What is left is the build target(s)
# and any options like -v for Ant.
TRAILING_OPTIONS_AND_BUILD_TARGETS="$*"

# Process the arguments we got from the command line
convert_args_to_properties

######################
# Prepare command line
######################

# Forumulate the build command.
BUILD_COMMAND="${ANTBUILD_ant_invocation} ${BUILD_PROPERTIES} ${TRAILING_OPTIONS_AND_BUILD_TARGETS}"

# Announce
echo "Ant invocation will be issued as follows: "
echo "${BUILD_COMMAND}"

# Do it!
${BUILD_COMMAND}

###############
# end of script
###############
}}}

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message