require "BuildUtils.rb" require "fileutils" include FileTest require 'rubygems' gem 'rubyzip' require 'zip/zip' require 'zip/zipfilesystem' #building stuff COMPILE_TARGET = "debug" CLR_VERSION = "v3.5" SOLUTION = "src/CoreLib.sln" MAIN_PROJECT = "CoreLib" # versioning stuff BUILD_NUMBER = "0.1.0." PRODUCT = "CoreLib" COPYRIGHT = "Copyright © 2009 Jon Fuller" COMPANY = "Jon Fuller" COMMON_ASSEMBLY_INFO = "src/CommonAssemblyInfo.cs" desc "Compiles, tests" task :all => [:default] desc "Compiles, tests" task :default => [:compile, :unit_test, :package] desc "Update the version information for the build" task :version do builder = AsmInfoBuilder.new BUILD_NUMBER, :product => PRODUCT, :copyright => COPYRIGHT, :company => COMPANY builder.write COMMON_ASSEMBLY_INFO end desc "Prepares the working directory for a new build" task :clean do rm_rf(output_dir) Dir.mkdir output_dir unless exists?(output_dir) MSBuildRunner.clean :solutionfile => SOLUTION ["src/**/bin", "src/**/obj"].each do |dir| Dir.glob(dir).each { |d| rm_rf d } end end desc "Compiles the app" task :compile => [:clean, :version] do MSBuildRunner.compile :compilemode => COMPILE_TARGET, :solutionfile => SOLUTION, :clrversion => CLR_VERSION end desc "Runs unit tests" task :unit_test => :compile do runner = NUnitRunner.new :compilemode => COMPILE_TARGET, :source => 'src', :tools => 'tools', :results_file => File.join(output_dir, "nunit.xml") runner.executeTests Dir.glob("src/*Test*").map { |proj| proj.split('/').last } end desc "Displays a list of tasks" task :help do taskHash = Hash[*(`rake.cmd -T`.split(/\n/).collect { |l| l.match(/rake (\S+)\s+\#\s(.+)/).to_a }.collect { |l| [l[1], l[2]] }).flatten] indent = " " puts "rake #{indent}#Runs the 'default' task" taskHash.each_pair do |key, value| if key.nil? next end puts "rake #{key}#{indent.slice(0, indent.length - key.length)}##{value}" end end desc "Packages the binaries into a zip" task :package => :compile do source_files = Dir.glob("src/#{MAIN_PROJECT}/bin/#{COMPILE_TARGET}/**/*") dest_files = source_files.map{ |f| f.sub("src/#{MAIN_PROJECT}/bin/#{COMPILE_TARGET}/", "#{MAIN_PROJECT}/")} Zip::ZipFile.open(File.join(output_dir, "#{MAIN_PROJECT}.zip"), 'w') do |zipfile| 0.upto(source_files.size-1) do |i| puts "Zipping #{source_files[i]} to #{dest_files[i]}" zipfile.add(dest_files[i], source_files[i]) end end end def output_dir if ENV.keys.include?('CC_BUILD_ARTIFACTS') return ENV['CC_BUILD_ARTIFACTS'] else return 'results' end end