rake: not your father's build tool

31
rake Not your father’s build tool 1

Upload: filmprog

Post on 12-Jan-2015

1.425 views

Category:

Technology


2 download

DESCRIPTION

Rake is a fantastic tool

TRANSCRIPT

Page 1: Rake: Not Your Father's Build Tool

rakeNot your father’s build tool

1

Page 2: Rake: Not Your Father's Build Tool

whatchutalk’nboutwillis

• Where it came from

• What it’s related to

• How to use it

2

Page 3: Rake: Not Your Father's Build Tool

What’s in a name?

• Usually the first thing people learn about rake is the etymology of the name: “Ruby Make”.

• But it’s much more than a catchy turn of phrase.

• It’s a fully featured Build Language. That almost never existed...

3

Page 4: Rake: Not Your Father's Build Tool

Ruby Version of Make?

• Jim tells the birth of rake as code he never intended to write.

• It started with a simple itch to scratch...

4

Page 5: Rake: Not Your Father's Build Tool

Jim Thought “What if...”

"What if you could specify the make tasks in Ruby, like this ..."

task "build" do

java_compile(...args, etc ...)

end

"The task function would register "build" as a target to be made,

and the block would be the action executed whenever the build

system determined that it was time to do the build target."

5

Page 6: Rake: Not Your Father's Build Tool

100 Lines Later

• It worked!

• Rake’s prototype lives in the repo: doc/proto_rake.rdoc

• But it didn’t have timebased file dependencies... so back to the text-editor.

• And the rest is in the commit history.

6

Page 7: Rake: Not Your Father's Build Tool

A Build Language

• The basic unit of a build language are tasks.

• A build has source files that it uses to produce a desired product.

• The two most common other build languages are make and ant.

7

Page 8: Rake: Not Your Father's Build Tool

Comparison

make ant rake

Imperative Style Imperative Style Dependency Based

External DSL External DSL Internal DSL

Custom Syntax XML based Syntax Ruby Syntax

8

Page 9: Rake: Not Your Father's Build Tool

Imperative Style

9

Page 10: Rake: Not Your Father's Build Tool

Imperative Style

• Both the code_generation methods will be called during test.

• At best that will waste time.

• At worst that can produce undesired results.

10

Page 11: Rake: Not Your Father's Build Tool

Dependency Based

11

Page 12: Rake: Not Your Father's Build Tool

Dependency Based

• A dependency based system gives the test method the power to evaluate what prerequisites it has.

• Then because ruby can evaluate the code without running it, it can prepare it to be run in the correct order that will only run each task once.

12

Page 13: Rake: Not Your Father's Build Tool

Comparison

make ant rake

Imperative Style Imperative Style Dependency Based

External DSL External DSL Internal DSL

Custom Syntax XML based Syntax Ruby Syntax

13

Page 14: Rake: Not Your Father's Build Tool

External vs Internal DSL

• With make and ant you need to use external scripts or nasty syntax to be creative.

• Rake can use full power of Ruby at any time.

14

Page 15: Rake: Not Your Father's Build Tool

Hello World

15

Page 16: Rake: Not Your Father's Build Tool

Building Blocks of Rake

• task

• file

• directory

• namespace

• multitask

• FileUtils

• clean

• clobber

16

Page 17: Rake: Not Your Father's Build Tool

task

In the DSL of rake, a task is a method that takes two arguments. The first argument is a hash, and the second is a block.

17

Page 18: Rake: Not Your Father's Build Tool

task dependencies

18

Page 19: Rake: Not Your Father's Build Tool

file

Rake file tasks are most similar to tasks in make. They get run only when needed. File tasks are declared using a string rather than a symbol. The following file task creates a executable program (named prog) given two object files name a.o and b.o.

19

Page 20: Rake: Not Your Father's Build Tool

directory

It is common to need to create directories upon demand. The directory convenience method is a short-hand for creating a FileTask that creates the directory.

20

Page 21: Rake: Not Your Father's Build Tool

directory

The directory method does not accept prerequisites or actions, but both prerequisites and actions can be added later.

21

Page 22: Rake: Not Your Father's Build Tool

namespaces

22

Page 23: Rake: Not Your Father's Build Tool

multitask

Multitask can help you save time by running tasks in your build that are safe to run in parallel.

23

Page 24: Rake: Not Your Father's Build Tool

multitask

It even has the ability to determine any prerequisites that need to be run before hand. It will complete this prep_for_copy only once then the three tasks would begin to run together.

24

Page 25: Rake: Not Your Father's Build Tool

FileUtils

• Use the FileUtils module and rake gives you the most common filesystem commands:

• cd, pwd, mkdir, mkdir_p, rmdir, ln, ln_s, ln_sf, cp, cp_r, mv, rm, rm_r, rm_rf, install, chmod, touch

• Create a map of files with FileList:

• FileList[‘**/*.rb’].each {|f| puts f}

25

Page 26: Rake: Not Your Father's Build Tool

Clean/Clobber

• require 'rake/clean'

• Use a pair of file lists: CLEAN and CLOBBER.

• You can then add items to the file lists with expressions like CLEAN.include('*.o').

• Remember that the clean task removes everything in the clean list, and clobber removes everything in both lists.

26

Page 27: Rake: Not Your Father's Build Tool

Built In Tasks

• GemPackageTask (in Ruby Gems now)

• PackageTask

• RdocTask (in Rdoc now)

• TestTask

27

Page 28: Rake: Not Your Father's Build Tool

Rake & Rails

• The default task for a rails project runs your test suite.

• If you want to see how the rake tasks you enjoy with Rails are built search for .rake in the gem source.

• Because as we all know, Rails is Magic!

28

Page 29: Rake: Not Your Father's Build Tool

rake

• Jim Weirich created in 2003.

• Similar to make and ant. With the power of Ruby.

• Hope you’ve got some ideas on how you’d like to use it.

29

Page 30: Rake: Not Your Father's Build Tool

Credits

• Jim Weirich - Rakehttp://rake.rubyforge.org/

• Martin Fowler - Using the Rake Build Languagehttp://martinfowler.com/articles/rake.html

• Josh Nichols - Rake: The Familiar Strangerhttp://vimeo.com/2496890

30

Page 31: Rake: Not Your Father's Build Tool

Thank You

[email protected]

• @filmprog

• filmprog.com

31