Sunday, August 28, 2005

Rake Experiences Continue

I've been working on the NanoContainer rake file recently. The development seemed to move in 3 significant directions.

  1. It was very procedural and used standard tasks exclusively.

  2. I incorporated many directory and file tasks to take advantage of only updating files when their dependant files were updated.

  3. The final (for now) version is back to being rather procedural; however, I use uptodate? often to get the benefits of the file task.

The final version is both shorter and more readable than version 2. This version is the easiest to follow because of it's procedural nature, and the use of uptodate? gives the most efficient builds.
require 'CSProjFile.rb'

def build(*relative_path)
File.join("src","build",relative_path)
end

task :default => [:compile, :test]
task :all => [:clean, :default]

task :clean do
rm_rf(build)
rm_rf("src/NanoContainer.Tests/bin")
rm_rf("src/TestComp/bin")
end

task :precompile do
mkdir_p(build) unless File.exists?(build)
def _lib(relative_path)
File.join("lib",relative_path)
end
def _precomp(files)
files.each {|f| cp(_lib(f), build) unless uptodate?(build(f), _lib(f))}
end
_precomp(%w(NUnit.Framework.dll PicoContainer.dll Castle.DynamicProxy.dll NMock.dll))
end

task :compile => :precompile do
def _compile(project)
projFile = CSProjFile.new(File.new("src/#{project}/#{project}.csproj"))
unless uptodate?("#{build(project)}.dll",projFile.files.collect {|f| "src/#{project}/#{f}" })
cd "src/#{project}"
sh projFile.create_csc("../build")
cd "../.."
end
end
%w(NanoContainer NanoContainer.Tests TestComp TestComp2 NotStartable).each {|project| _compile(project)}
end

task :pretest do
def tcVsOutput(*relative_path)
File.join("src","TestComp","bin","Debug",relative_path)
end
mkdir_p(tcVsOutput) unless File.exists?(tcVsOutput)
tcdll = "TestComp.dll"
cp(build(tcdll), tcVsOutput) unless uptodate?(tcVsOutput(tcdll), build(tcdll))
def nanoVsOutput(*relative_path)
File.join("src","NanoContainer.Tests","bin","Debug",relative_path)
end
mkdir_p(nanoVsOutput) unless File.exists?(nanoVsOutput)
def _pretest(files)
files.each {|f| cp(build(f),nanoVsOutput) unless uptodate?(nanoVsOutput(f), build(f))}
end
_pretest(%w(NMock.dll PicoContainer.dll Castle.DynamicProxy.dll NUnit.Framework.dll NanoContainer.dll NanoContainer.Tests.dll))
end

task :test => [:compile,:pretest] do
cd nanoVsOutput
sh "../../../../lib/nunit-console.exe NanoContainer.Tests.dll"
end

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.