Skip to content

Commit 00bf219

Browse files
committed
- Added build script for command-line build with Rake (install Ruby 1.86 or later, run InstallGems.bat)
- Added support for building against NHib 2.0GA and NHib 2.1 trunk/latest/whatever - Including NUnit console runner git-svn-id: https://fluent-nhibernate.googlecode.com/svn/trunk@119 48f0ce17-cc52-0410-af8c-857c09b6549b
1 parent 4bf948a commit 00bf219

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+143546
-4
lines changed

Build.bat

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rake

BuildUtils.rb

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
require 'erb'
2+
3+
class NUnitRunner
4+
include FileTest
5+
6+
def initialize(paths)
7+
@sourceDir = paths.fetch(:source, 'source')
8+
@resultsDir = paths.fetch(:results, 'results')
9+
@compilePlatform = paths.fetch(:platform, 'x86')
10+
@compileTarget = paths.fetch(:compilemode, 'debug')
11+
12+
if ENV["teamcity.dotnet.nunitlauncher"] # check if we are running in TeamCity
13+
# We are not using the TeamCity nunit launcher. We use NUnit with the TeamCity NUnit Addin which needs tO be copied to our NUnit addins folder
14+
# http://blogs.jetbrains.com/teamcity/2008/07/28/unfolding-teamcity-addin-for-nunit-secrets/
15+
# The teamcity.dotnet.nunitaddin environment variable is not available until TeamCity 4.0, so we hardcode it for now
16+
@teamCityAddinPath = ENV["teamcity.dotnet.nunitaddin"] ? ENV["teamcity.dotnet.nunitaddin"] : 'c:/TeamCity/buildAgent/plugins/dotnetPlugin/bin/JetBrains.TeamCity.NUnitAddin-NUnit'
17+
cp @teamCityAddinPath + '-2.4.7.dll', 'tools/nunit/addins'
18+
end
19+
20+
@nunitExe = "tools/nunit/nunit-console#{(@compilePlatform.nil? ? '' : "-#{@compilePlatform}")}.exe /nothread"
21+
end
22+
23+
def executeTests(assemblies)
24+
Dir.mkdir @resultsDir unless exists?(@resultsDir)
25+
26+
assemblies.each do |assem|
27+
file = File.expand_path("#{@sourceDir}/#{assem}/bin/#{(@compilePlatform.nil? ? '' : "#{@compilePlatform}/")}#{@compileTarget}/#{assem}.dll")
28+
sh "#{@nunitExe} #{file}"
29+
end
30+
end
31+
end
32+
33+
class MSBuildRunner
34+
def self.compile(attributes)
35+
version = attributes.fetch(:clrversion, 'v3.5')
36+
compileTarget = attributes.fetch(:compilemode, 'debug')
37+
solutionFile = attributes[:solutionfile]
38+
39+
frameworkDir = File.join(ENV['windir'].dup, 'Microsoft.NET', 'Framework', version)
40+
msbuildFile = File.join(frameworkDir, 'msbuild.exe')
41+
42+
sh "#{msbuildFile} #{solutionFile} /maxcpucount /v:m /property:BuildInParallel=false /property:Configuration=#{compileTarget} /t:Rebuild"
43+
end
44+
end
45+
46+
class AspNetCompilerRunner
47+
def self.compile(attributes)
48+
49+
webPhysDir = attributes.fetch(:webPhysDir, '')
50+
webVirDir = attributes.fetch(:webVirDir, '')
51+
52+
frameworkDir = File.join(ENV['windir'].dup, 'Microsoft.NET', 'Framework', 'v2.0.50727')
53+
aspNetCompiler = File.join(frameworkDir, 'aspnet_compiler.exe')
54+
55+
sh "#{aspNetCompiler} -p #{webPhysDir} -v #{webVirDir}"
56+
end
57+
end
58+
59+
class AsmInfoBuilder
60+
attr_reader :buildnumber
61+
62+
def initialize(baseVersion, properties)
63+
@properties = properties;
64+
65+
@buildnumber = baseVersion + (ENV["CCNetLabel"].nil? ? '0' : ENV["CCNetLabel"].to_s)
66+
@properties['Version'] = @properties['InformationalVersion'] = buildnumber;
67+
end
68+
69+
70+
71+
def write(file)
72+
template = %q{
73+
using System;
74+
using System.Reflection;
75+
using System.Runtime.InteropServices;
76+
77+
<% @properties.each {|k, v| %>
78+
[assembly: Assembly<%=k%>Attribute("<%=v%>")]
79+
<% } %>
80+
}.gsub(/^ /, '')
81+
82+
erb = ERB.new(template, 0, "%<>")
83+
84+
File.open(file, 'w') do |file|
85+
file.puts erb.result(binding)
86+
end
87+
end
88+
end
89+
90+
class InstallUtilRunner
91+
def installServices(services, parameters)
92+
services.each do |service|
93+
params = ""
94+
parameters.each_pair {|key, value| params = params + "/" + key + "=" + value + " "}
95+
sh "tools/installutil /i #{params} #{service}"
96+
end
97+
end
98+
99+
def uninstallServices(services)
100+
services.each do |service|
101+
begin
102+
sh "tools/installutil /u #{service}"
103+
rescue Exception => e
104+
puts 'IGNORING ERROR: ' + e
105+
end
106+
end
107+
end
108+
109+
end
110+
111+
112+

InstallGems.bat

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@ECHO *** Installing Rake
2+
@call gem install rake --include-dependencies
3+
4+
@ECHO *** Installing ActiveRecord
5+
@call gem install activerecord --include-dependencies
6+
7+
@ECHO *** Installing RubyZip
8+
@call gem install rubyzip --include-dependencies
9+
10+
@ECHO *** Installing Rails
11+
@call gem install rails --include-dependencies

RakeFile

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
COMPILE_TARGET = "debug"
2+
require "BuildUtils.rb"
3+
4+
include FileTest
5+
6+
require 'rubygems'
7+
8+
gem 'rubyzip'
9+
require 'zip/zip'
10+
require 'zip/zipfilesystem'
11+
12+
RESULTS_DIR = "results"
13+
BUILD_NUMBER = "0.1.0."
14+
PRODUCT = "FluentNHibernate"
15+
COPYRIGHT = 'Copyright 2008 Jeremy D. Miller, James Gregory, Andrew Stewart, Paul Batum, Chad Myers et al. All rights reserved.';
16+
COMMON_ASSEMBLY_INFO = 'src/CommonAssemblyInfo.cs';
17+
CLR_VERSION = "v3.5"
18+
19+
versionNumber = ENV["BUILD_NUMBER"].nil? ? 0 : ENV["BUILD_NUMBER"]
20+
21+
props = { :archive => "build" }
22+
23+
desc "Compiles, unit tests, generates the database, and then runs integration tests"
24+
task :all => [:default]
25+
26+
desc "**Default**, compiles and runs tests"
27+
task :default => [:use_nhib_20, :compile, :unit_test]
28+
29+
desc "Builds Fluent NHibernate against the NHibernate 2.1 libs (instead of the normal NHibernate 2.0GA"
30+
task :nhib21 =>[:use_nhib_21, :compile, :unit_test, :use_nhib_20]
31+
32+
desc "Switches NHibernate dependencies to NHibernate 2.1"
33+
task :use_nhib_21 do
34+
switch_nhib_libs('nhib2.1')
35+
end
36+
37+
desc "Switches NHibernate dependencies to NHibernate 2.0"
38+
task :use_nhib_20 do
39+
switch_nhib_libs('nhib2.0GA')
40+
end
41+
42+
#### hidden task, don't call directly
43+
def switch_nhib_libs(nhib_lib_dir)
44+
puts "Switching NHibernate dependencies to #{nhib_lib_dir}"
45+
# clear the nhib dir
46+
Dir.foreach('tools/NHibernate') {|file|
47+
relFile = File.join('tools/NHibernate',file)
48+
File.delete(relFile) if File.file?(relFile)
49+
}
50+
51+
# copy the source files over
52+
Dir.foreach("tools/NHibernate/#{nhib_lib_dir}"){|file|
53+
relFile = File.join("tools/NHibernate/#{nhib_lib_dir}",file)
54+
copy(relFile, 'tools/NHibernate') if File.file?(relFile)
55+
}
56+
end
57+
58+
59+
desc "Displays a list of tasks"
60+
task :help do
61+
taskHash = Hash[*(`rake.cmd -T`.split(/\n/).collect { |l| l.match(/rake (\S+)\s+\#\s(.+)/).to_a }.collect { |l| [l[1], l[2]] }).flatten]
62+
63+
indent = " "
64+
65+
puts "rake #{indent}#Runs the 'default' task"
66+
67+
taskHash.each_pair do |key, value|
68+
if key.nil?
69+
next
70+
end
71+
puts "rake #{key}#{indent.slice(0, indent.length - key.length)}##{value}"
72+
end
73+
end
74+
75+
desc "Update the version information for the build"
76+
task :version do
77+
builder = AsmInfoBuilder.new(BUILD_NUMBER, {'Product' => PRODUCT, 'Copyright' => COPYRIGHT})
78+
buildNumber = builder.buildnumber
79+
puts "The build number is #{buildNumber}"
80+
builder.write COMMON_ASSEMBLY_INFO
81+
end
82+
83+
desc "Prepares the working directory for a new build"
84+
task :clean do
85+
#TODO: do any other tasks required to clean/prepare the working directory
86+
Dir.mkdir props[:archive] unless exists?(props[:archive])
87+
end
88+
89+
desc "Compiles the app"
90+
task :compile => [:clean, :version] do
91+
MSBuildRunner.compile :compilemode => COMPILE_TARGET, :solutionfile => 'src/FluentNHibernate.sln', :clrversion => CLR_VERSION
92+
93+
outDir = "src/FluentNHibernate/bin/#{COMPILE_TARGET}"
94+
95+
Dir.glob(File.join(outDir, "*.{dll,pdb}")){|file|
96+
copy(file, props[:archive]) if File.file?(file)
97+
}
98+
end
99+
100+
desc "Runs unit tests"
101+
task :unit_test => :compile do
102+
runner = NUnitRunner.new :compilemode => COMPILE_TARGET, :source => 'src', :platform => 'x86'
103+
runner.executeTests ['FluentNHibernate.Testing']
104+
end

0 commit comments

Comments
 (0)