Uploaded on:
Category: Business / Finance
Rake and make A system can comprise of numerous source code records This is constantly valid in Rails! The records might should be gathered in a specific request A few sections of the system might rely on upon different parts being a la mode A UNIX makefile is a document that portrays these conditions
Slide 1


Slide 2

rake and make A project can comprise of numerous source code documents This is constantly valid in Rails! The documents may should be assembled in a sure request Some parts of the system may rely on upon different parts being cutting-edge A UNIX makefile is a record that depicts these conditions UNIX make is a program that peruses a makefile, decides the right request in which to overhaul records, and upgrades them Ruby projects are translated, not arranged; but rather... Rails uses metaprogramming to make source records and information documents from different documents Consequently, something like make is still required rake gives the same usefulness as make , however is actualized in an unexpected way

Slide 3

Rakefiles are composed in Ruby  The accompanying code piece communicates that a record file_1 relies on upon documents file_2 and file_3 document " file_1 " => [" file_2 ", " file_3 "] We can utilize this code part with a square that advises what to do with the reliance document " file_1 " => [" file_2 ", " file_3 "] do # code to make file_1 from file_2 and file_3 end A rakefile can comprise essentially of various these squares Like make , rake takes a gander at the change dates of records and just redesigns them as vital

Slide 4

First case, I This sample utilizes C records as illustrations Suppose we have the documents main.c , greet.h , and greet.c main.c is our typical “Hello World” program, yet incorporates greet.h , which determines a welcome strategy (on greet.c ) Our objective (the record we need to manufacture) is hello.o We have the accompanying conditions: document "main.o" => ["main.c", "greet.h"] document "greet.o" => ["greet.c"] record "hello" => ["main.o", "greet.o"] To make the objective, we have to execute these charges: cc - c - o main.o main.c cc - c - o greet.o greet.c cc - o hi main.o greet.o

Slide 5

First case, II Here ’s the rakefile: document "main.o" => ["main.c", "greet.h"] do sh "cc - c - o main.o main.c" end document "greet.o" => [\'greet.c\'] do sh "cc - c - o greet.o greet.c" end document "hello" => ["main.o", "greet.o"] do sh "cc - o hi main.o greet.o" end

Slide 6

Running rake The language structure for running a rake summon is rake [ choices ... ] [ VAR = VALUE ] [ targets ... ] Unless we utilize the choice - f filename , rake will read its orders from a document named rakefile Our objective (the thing we need to make) is named "hello" in this record, so (expecting the system on the past slide is on a record named rakefile ), we run rake by saying rake hi

Slide 7

Additional targets record targets check change dates, subsequently these errands are just done when required Non-record undertakings are constantly performed Non-record assignments utilize the assignment catchphrase rather than document We can determine a default errand, for example, "hello" , like this: assignment :default => ["hello"] Other non-record undertakings are: perfect - Remove makeshift records made amid the manufacture procedure clobber - Remove all documents created amid the construct transform The Rake library actualizes spotless and clobber for you, however you need to let it know what records to spotless or clobber Do this with FileLists spotless and clobber utilize the rundowns named CLEAN and CLOBBER , separately Example: CLEAN = FileList["greet.o"] You can utilize trump cards: CLOBBER = FileList["*.o"]

Slide 8

Dynamically building assignments Example: SRC = FileList[\'*.c\'] SRC.each do |fn| obj = fn.sub(/\.[^.]*$/, \'.o\') record obj do sh "cc - c - o #{obj} #{fn}" end Notes: Remember that Ruby will do substitution in twofold cited strings The record rundown relies on upon the source records ( .c documents), in light of the fact that the item documents ( .o documents) could possibly be available The conditions in the middle of source and article documents are indicated somewhere else Rake can make sense of this

Slide 9

Automatically building undertakings Rather than progressively building undertakings, it ’s more often than not less demanding just to produce them consequently For instance, In C the item .o documents rely on upon the source .c records, so we can say: standard ".o" => ".c" do |t| sh "cc - c - o #{t.name} #{t.source}" end

Slide 10

Final result oblige \'rake/clean\' CLEAN.include(\'*.o\') CLOBBER.include(\'hello\') undertaking :default => ["hello"] SRC = FileList[\'*.c\'] OBJ = SRC.ext(\'o\') principle ".o" => ".c" do |t| sh "cc - c - o #{t.name} #{t.source}" end record "hello" => OBJ do sh "cc - o hi #{OBJ}" end # File conditions go here ... document "main.o" => [\'main.c\', \'greet.h\'] record "greet.o" => [\'greet.c\']

Slide 11

Credit These slides cover just the most fundamental utilization of rake The expanded sample utilized as a part of these slides is taken from http://docs.rubyrake.org/read/book/1 A more thorough clarification of rakefiles can be found at http://www.martinfowler.com/articles/rake.html

Slide 12

The End .:tslidesep.

View more...