Rake Venkat Subramaniam – svenkat@cs.uh.edu 1 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 Venkat Subramaniam – svenkat@cs.uh.edu 2
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 Venkat Subramaniam – svenkat@cs.uh.edu 3 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 Venkat Subramaniam – svenkat@cs.uh.edu 4
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 Venkat Subramaniam – svenkat@cs.uh.edu 5 Let’s Give It a Try Venkat Subramaniam – svenkat@cs.uh.edu 6
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 Venkat Subramaniam – svenkat@cs.uh.edu 7 Rake Dry Run • Allows you to see what Rake will do • -- trace option will trace the task calls as it executes Venkat Subramaniam – svenkat@cs.uh.edu 8
Rake prerequisites • You can find what the pre-requisite for tasks are using the -P option Venkat Subramaniam – svenkat@cs.uh.edu 9 Task and description • You can write a description for task and check those out using –T option Venkat Subramaniam – svenkat@cs.uh.edu 10
Prerequisite Specification • You can specify when you define a task • You can also specify separately Venkat Subramaniam – svenkat@cs.uh.edu 11 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 Venkat Subramaniam – svenkat@cs.uh.edu 12
Using file Venkat Subramaniam – svenkat@cs.uh.edu 13 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 Venkat Subramaniam – svenkat@cs.uh.edu 14
Recommend
More recommend