14
1 enkat Subramaniam – [email protected] enkat Subramaniam – [email protected] Rake

1 Rake. 2 Automated Build Any non-trivial project needs facility to automate builds –Routine common tasks that need to be carried out several times a

Embed Size (px)

Citation preview

Page 1: 1 Rake. 2 Automated Build Any non-trivial project needs facility to automate builds –Routine common tasks that need to be carried out several times a

1Venkat Subramaniam – [email protected] Subramaniam – [email protected]

Rake

Page 2: 1 Rake. 2 Automated Build Any non-trivial project needs facility to automate builds –Routine common tasks that need to be carried out several times a

2Venkat Subramaniam – [email protected] Subramaniam – [email protected]

Automated Build• Any non-trivial project needs facility to

automate builds– Routine common tasks that need to be

carried out several times a day

• Not very efficient to do manually and also error prone

• Rake is the make utility for Rails

Page 3: 1 Rake. 2 Automated Build Any non-trivial project needs facility to automate builds –Routine common tasks that need to be carried out several times a

3Venkat Subramaniam – [email protected] Subramaniam – [email protected]

What does a make file have?• Typically a make file has

– Commands or tasks

– Dependency between the tasks

– A way to specify which tasks to execute (selectively or all)

– Tasks only execute if necessary

Page 4: 1 Rake. 2 Automated Build Any non-trivial project needs facility to automate builds –Routine common tasks that need to be carried out several times a

4Venkat Subramaniam – [email protected] Subramaniam – [email protected]

make vs. ant• Even though similar quite some

differences

• ant is task based– You specify tasks and instructions to execute

• make allows file type based specification– You can say that a type of file needs to be

built based on another type of file– make will check for timestamp of these files

and decide if it should be built

Page 5: 1 Rake. 2 Automated Build Any non-trivial project needs facility to automate builds –Routine common tasks that need to be carried out several times a

5Venkat Subramaniam – [email protected] Subramaniam – [email protected]

What’s special about Rake?• Ant for Java (NAnt for .NET) uses xml• Jim Weirich’s Rake uses ruby!• Makes it easier to write – you are not

switching languages – feels natural• If you know Ruby, you simply read it and

you get it!• Rake is a internal Domain Specific

Language which uses the Ruby syntax• Rake is very easy to extend – write Ruby

code

Page 6: 1 Rake. 2 Automated Build Any non-trivial project needs facility to automate builds –Routine common tasks that need to be carried out several times a

6Venkat Subramaniam – [email protected] Subramaniam – [email protected]

Let’s Give It a Try

Page 7: 1 Rake. 2 Automated Build Any non-trivial project needs facility to automate builds –Routine common tasks that need to be carried out several times a

7Venkat Subramaniam – [email protected] Subramaniam – [email protected]

Rake Conventions• Rake uses rakefile.rb by default when you

type rake

• => is used for dependency/pre-requisites

• :default is the task that will be executed, err, by default

Page 8: 1 Rake. 2 Automated Build Any non-trivial project needs facility to automate builds –Routine common tasks that need to be carried out several times a

8Venkat Subramaniam – [email protected] Subramaniam – [email protected]

Rake Dry Run• Allows you to see what Rake will do

• -- trace option will trace the task calls as it executes

Page 9: 1 Rake. 2 Automated Build Any non-trivial project needs facility to automate builds –Routine common tasks that need to be carried out several times a

9Venkat Subramaniam – [email protected] Subramaniam – [email protected]

Rake prerequisites• You can find what the pre-requisite for

tasks are using the -P option

Page 10: 1 Rake. 2 Automated Build Any non-trivial project needs facility to automate builds –Routine common tasks that need to be carried out several times a

10Venkat Subramaniam – [email protected] Subramaniam – [email protected]

Task and description• You can write a description for task and

check those out using –T option

Page 11: 1 Rake. 2 Automated Build Any non-trivial project needs facility to automate builds –Routine common tasks that need to be carried out several times a

11Venkat Subramaniam – [email protected] Subramaniam – [email protected]

Prerequisite Specification• You can specify when you define a task• You can also specify separately

Page 12: 1 Rake. 2 Automated Build Any non-trivial project needs facility to automate builds –Routine common tasks that need to be carried out several times a

12Venkat Subramaniam – [email protected] Subramaniam – [email protected]

file tasks• In addition to tasks like we saw so far,

you can define file tasks

• File tasks (like good old make) specify the input output file and pre-requisite input file

• Checks time stamp of output file and if it is earlier than input file, task is executed

Page 13: 1 Rake. 2 Automated Build Any non-trivial project needs facility to automate builds –Routine common tasks that need to be carried out several times a

13Venkat Subramaniam – [email protected] Subramaniam – [email protected]

Using file

Page 14: 1 Rake. 2 Automated Build Any non-trivial project needs facility to automate builds –Routine common tasks that need to be carried out several times a

14Venkat Subramaniam – [email protected] Subramaniam – [email protected]

Rake and Rails• Rails make great use of Rake

• Allows you to run different tasks– Tests– Cloning database– …

• One way to learn rake is to study the rake files in Rails