an introduction to software development - build scripts

15
An Introduction To Software Development Using Python Spring Semester, 2014 Class #11: Build Scripts

Upload: blue-elephant-consulting

Post on 05-Aug-2015

83 views

Category:

Education


0 download

TRANSCRIPT

An Introduction To Software Development

Using Python

Spring Semester, 2014

Class #11:Build Scripts

Homework #1 Was Really A Bunch Of Parts

Put Together

Get Inputs

CalculateAge

Encrypt SS

Number Collect Older / Younger

Information

PrintFull

Name

PrintStreet

Address PrintGender

Print Flipped

DOBAndAge

Print Insurance

Status

Print 2 Versions

Of SS Number

Print MedicaidNumber

Print Parent’sName

Software Must Be Usable

• When a new developer joins your team, will he/she know what dependencies to worry about? Or what code is needed to test things?

• Many things can be done with your code:– Compile all of it– Run part of it– Package up– Etc.

• A version control system will do you no good if you can’t be sure that your code will be used correctly once it’s been checked out

Image Credit: 4vector.com

Good code needs to be easy to use in addition to being easy to get

Say Hello To “Build Scripts”

• In order to run a software project, more than just compiling of code must be done.

• The project must be “built”.

• Building a project involves the following steps:– Compiling source files into binary files– Finding dependencies– Packaging up the project– Etc.

Image Credit: www.easyvectors.com

What Dependencies Did We Have In Homework

#1?

Get Inputs

CalculateAge

Encrypt SS

Number Collect Older / Younger

Information

PrintFull

Name

PrintStreet

Address PrintGender

Print Flipped

DOBAndAge

Print Insurance

Status

Print 2 Versions

Of SS Number

Print MedicaidNumber

Print Parent’sName

How To Build A Project

Image Credit: www.pinterest.com, www.clipartpanda.com, www.clker.com, imgkid.com

Since the same steps are performed each time, building a projectIs the prefect candidate for automation using a tool.

Say Hello To Ant

• Apache Ant is a build tool for Java thatcan compile code, create and deletedirectories and even package files for you.

• Ant uses a build script to accomplish all of this

• Build scripts are written in XML

• Build scripts tell Ant what to do when you need to build your program.

Image Credit: en.wikipedia.org

How It All Works

• In Ant, each build file represents a single project

• The file is called a build script

• The file, called build.xml, contains the steps need to build your project

• What is needed to build your project is broken up into steps that are called targets

• Each target can have more than one task

• To build a project, you just run Ant with your build file

Image Credit: www.fg-a.com

Projects, Properties, Targets, and Tasks• Projects: Everything in your build file is part of a single project:

<project name=“Homework 1” default =“dist”>

• Properties: Ant properties are like constants for the script. They let you refer to values in the script; however, you can change those values in a single place.<property name=“version” value=“1.0” />

• Targets: A target is just a set of work. You can group different actions into a target. Example: You might have an init target for setting up your project’s directory structure and a compile target for compiling all of your code. A target has a name and, optionally, a list of targets that must be run before it.<target name=“compile” depends=“init” description=“Compiles code”>

• Tasks: A task in Ant generally maps to a specific command<mkdir dir=“/homework_1” >

No matter what language you are using, a good build tool gives youa way to manage projects, constants, and specific tasks.

Image Credit: www.clipartpanda.com

What A Pain! Why Bother With A Build

Tool?• A build tool, like Ant, lets you get things done faster –

especially when you are working on multiple projects.

• The build tool is really for the team – not just you!

• The tool allows everyone on the team to turn source code into a running application.

• A build script makes it impossible for a developer to leave a step out.

Image Credit: pixgood.com

What Makes A Good Build Script?

• A good build script captures details that the developers don’t have to worry about.

• The description information included in tags in the build file can be used to automatically generate documentation.

• Build scripts compile the code in your project. Ant can handle target dependencies: init depends on compile which depends on dist

• You should always have a target that cleans things up: delete the directories created during compiling

Image Credit: logos.co

A Good Build Script Does More…

• Add required libraries– If your application depends on libraries that you don’t want to store

locally, you can have Ant download during the build process

• Run the application– Does your application require a complex library path?– Does it need a long string of command line options?

• Generate documentation– Ant can display documentation from the build file

• Check out code, run tests, create archives, encrypt files, email you when the build is done

Automation allows you to keep your focus on your code,not on repetitive tasks…

Image Credit: www.polyvore.com

What To Do With The Build Script…?

• It turns out that your build script is code also!

• This code belongs in a repository

• You should always check your build script code into your code repository

• Now it’s available to everyone when they do an update

• Version control software tracks all changes

• Script gets tagged when you do a release

Image Credit: www.gograph.com

What We Covered Today

1. Build scripts

2. Projects

3. Properties

4. Targets

Image Credit: http://www.tswdj.com/blog/2011/05/17/the-grooms-checklist/

What We’ll Be Covering Next Time

1. Testing

2. Continuous integration

Image Credit: http://merchantblog.thefind.com/2011/01/merchant-newsletter/resolve-to-take-advantage-of-these-5-e-commerce-trends/attachment/crystal-ball-fullsize/