A New Internet Library: Add Your Website/Blog or Suggest A Website/Blog to our Free Web Directory http://anil.myfunda.net.

Its very simple, free and SEO Friendly.
Submit Now....

Monday, August 25, 2008

OMG Rake!

Rake is just... lovely. There's no other way to describe it. I just moved the XEVA Framework build script to rake and ended up with this build script weighing in at only 35 lines:

  DOT_NET_PATH = "C:/Windows/Microsoft.NET/Framework/v3.5/"  NUNIT_PATH = "tools//nunit-2.4.6//nunit-console.exe"  PACKAGE_PATH = "build/package"  SOLUTION = "src/XF.sln"  CONFIG = "Debug"    task :default => ["build:all"]    namespace :build do        task :all => [:compile, :harvest, :test]        desc "Use MSBuild to build the solution: '#{SOLUTION}'"    task :compile do      sh "#{DOT_NET_PATH}msbuild.exe /p:Configuration=#{CONFIG} #{SOLUTION}"    end        desc "Harvest build outputs to: '#{pwd}\\#{PACKAGE_PATH}'"    task :harvest => [:compile] do      require 'build/scripts/file_handling.rb'      package_files    end      desc "Executes class specifications (BDD)"    task :test => [:harvest] do      specs = Dir.glob(File.join("#{PACKAGE_PATH}", "*.Specs.dll")).join " "      xml_file = File.join(PACKAGE_PATH, "nunit-test-report.xml")      sh "#{NUNIT_PATH} #{specs} /nologo /xml=#{xml_file}"    end      end  

Check out the :harvest task where I'm requiring an external file that's contains code for bundling up the various build outputs, currently just .dll and .pdb files. The file looks like this:

  class Dir  	def self.exists?(path)  		File.directory?(path)  	end  end    def package_files	  	rm_r PACKAGE_PATH if Dir.exists?(PACKAGE_PATH)  	mkdir PACKAGE_PATH  	copy_third_party_libraries  	copy_asset "Framework.Specs", "Specs"  	["Shared", "Model", "Store", "Services", "UI.Smart"].each do |item|  		copy_conventional_asset item	  	end  end    def copy_third_party_libraries  	files = Dir.glob(File.join("lib/**", "*.dll")) + Dir.glob(File.join("lib/**", "*.pdb"))  	files.each do |item|  		cp_r item, "#{PACKAGE_PATH}"  	end  end    def copy_asset(asset_path, asset_name)  	cp "src\\#{asset_path}\\bin\\#{CONFIG}\\XF.#{asset_name}.dll", "#{PACKAGE_PATH}"  	if #{CONFIG}.downcase == "debug"  		cp "src\\#{asset_path}\\bin\\#{CONFIG}\\XF.#{asset_name}.pdb", "#{PACKAGE_PATH}"  	end  end    def copy_conventional_asset(assets)  	assets.each do |asset|  		copy_asset "Framework.#{asset}", "#{asset}"  		copy_asset "Framework.#{asset}.Specs", "#{asset}.Specs"  	end  end  

I'm in love with Rake -- and the idea of executable configuration in general -- for a few reasons:

1) I can take my scripts down to a reasonable size. The NAnt script for this simple build weighed in at a hefty 162 lines. These two files combined hover around 65. That's much better signal to noise and it only gets better with the more complex scripts.

2) I can make new tasks lickity split. With ruby you just write some code inside a task. It's easy to leverage popular libraries like Hpricot for XML poking and peeking and such. No need to compile tasks and manage separate projects just for build code.

3) I can see what's happening! Ruby is a very flexible language. I can use it's tricks to pimp out my build scripts and I don't need to sift through angle bracket madness. Note how I opened up the Dir class to define a new method, exists?. Ah the joys of ruby. We can make things somewhat familiar to our .NET teams while keeping it idiomatic. With tools like IronRuby this prospect get's even juicier.

Gettting Started

If you're just getting started with rake, you need ruby first. The "one click install" at the official Ruby site is what I'm using and it's a pain-free setup. There's plenty on Google, but I recommend giving the Rails Envy boys a click for a super-basic-but-effective primer. Remember the sh method is your friend and, when in doubt, RTFM!



Source Click Here.

No comments:

Post a Comment

Post your comments here:

Originals Enjoy