forked from commodifusion/asynchttpmachine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile.rb
184 lines (147 loc) · 4.72 KB
/
Rakefile.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
VERSION = "0.1.0"
LICENSE_URL = "https://raw.github.com/bvanderveen/httpmachine/HEAD/LICENSE.txt"
PROJECT_URL = "https://github.com/bvanderveen/httpmachine"
PROJECT_FILES = FileList["**/*.csproj"]
CONFIGURATION = "Release"
BUILD_DIR = File.expand_path("build")
OUTPUT_DIR = "#{BUILD_DIR}/out"
BIN_DIR = "#{BUILD_DIR}/bin"
NUGET_DIR = "#{BUILD_DIR}/nug"
require 'albacore'
def is_nix
!RUBY_PLATFORM.match("linux|darwin").nil?
end
def invoke_runtime(cmd)
command = cmd
if is_nix()
command = "mono --runtime=v4.0 #{cmd}"
end
command
end
def load_xml(input)
input_file = File.new(input)
xml = REXML::Document.new input_file
input_file.close
return xml
end
def transform_xml(input, output)
xml = load_xml(input)
yield xml
output_file = File.open(output, "w")
formatter = REXML::Formatters::Default.new()
formatter.write(xml, output_file)
output_file.close
end
def nuspec_for_project(project_file)
project_file.chomp(".csproj").concat(".nuspec")
end
def load_nuspec_info(project_file)
# get description, authors, copyright
x = load_xml(nuspec_for_project(project_file))
{
"description" => x.root.elements["metadata/desciption"].text,
"authors" => x.root.elements["metadata/authors"].text,
"copyright" => x.root.elements["metadata/copyright"].text
}
end
def update_assemblyinfo(project_file, version)
begin
nuspec_info = load_nuspec_info(project_file)
rescue
nuspec_info = nil
end
project_name = File.basename(project_file).chomp(".csproj")
output_file = File.join(File.dirname(project_file), "Properties", "AssemblyInfo.cs")
a = AssemblyInfo.new
unless nuspec_info.nil?
a.company_name = nuspec_info["authors"]
a.copyright = nuspec_info["copyright"]
a.description = nuspec_info["description"]
end
a.version = a.file_version = version
a.product_name = a.title = project_name
a.namespaces "System.Runtime.CompilerServices"
a.custom_attributes :InternalsVisibleTo => "#{project_name}.Tests"
a.output_file = output_file
a.execute
end
def build_nuspec(project_file)
input_nuspec = nuspec_for_project(project_file)
return unless File.exists? input_nuspec
project_name = File.basename(project_file).chomp(".csproj")
nuget_dir = "#{NUGET_DIR}/#{project_name}"
FileUtils.mkdir nuget_dir
output_nuspec = "#{nuget_dir}/#{project_name}.nuspec"
transform_xml input_nuspec, output_nuspec do |x|
x.root.elements["metadata/id"].text = project_name
x.root.elements["metadata/version"].text = VERSION
x.root.elements["metadata/owners"].text = x.root.elements["metadata/authors"].text
x.root.elements["metadata/licenseUrl"].text = LICENSE_URL
x.root.elements["metadata/projectUrl"].text = PROJECT_URL
end
nuget_lib_dir = "#{nuget_dir}/lib"
FileUtils.mkdir nuget_lib_dir
FileUtils.cp_r FileList["#{BIN_DIR}/#{project_name}{.dll,.pdb}"], nuget_lib_dir
nuget = NuGetPack.new
nuget.command = "tools/NuGet.exe"
nuget.nuspec = output_nuspec
nuget.output = BUILD_DIR
#using base_folder throws as there are two options that begin with b in nuget 1.4
nuget.parameters = "-Symbols", "-BasePath \"#{nuget_dir}\""
nuget.execute
end
def ragel()
sh "cd src/HttpMachine; ragel rl/HttpParser.cs.rl -A -o HttpParser.cs"
end
task :default => [:build]
msbuild :build_msbuild do |b|
b.properties :configuration => CONFIGURATION, "OutputPath" => OUTPUT_DIR
b.targets :Build
b.solution = "HttpMachine.sln"
end
xbuild :build_xbuild do |b|
b.properties :configuration => CONFIGURATION, "OutputPath" => OUTPUT_DIR
b.targets :Build
b.solution = "HttpMachine.sln"
end
task :build => :clean do
ragel()
build_task = is_nix() ? "build_xbuild" : "build_msbuild"
Rake::Task[build_task].invoke
end
task :test => :build do
nunit = invoke_runtime("packages/NUnit.2.5.10.11092/tools/nunit-console.exe")
PROJECT_FILES
.reject { |f| not f.include? ".Tests" }
.map { |project_file| File.basename(project_file).chomp(".csproj") }
.each { |project_name| sh "#{nunit} -labels #{OUTPUT_DIR}/#{project_name}.dll" }
end
task :binaries => [:build] do
Dir.mkdir(BIN_DIR)
binaries = FileList["#{OUTPUT_DIR}/*.dll", "#{OUTPUT_DIR}/*.pdb"]
.exclude(/nunit/)
.exclude(/.Tests/)
.exclude(/.exe/)
FileUtils.cp_r binaries, BIN_DIR
end
task :dist_nuget => [:binaries] do
if is_nix()
puts "Not running on Windows, skipping NuGet package creation."
else
Dir.mkdir(NUGET_DIR)
PROJECT_FILES.each do |p|
build_nuspec(p)
end
end
end
zip :dist_zip => [:binaries] do |z|
z.directories_to_zip BIN_DIR
z.output_file = "gate-#{VERSION}.zip"
z.output_path = BUILD_DIR
end
task :dist => [:dist_nuget, :dist_zip] do
end
task :clean do
FileUtils.rm_rf BUILD_DIR
FileUtils.rm_rf FileList["src/**/obj", "src/**/bin"]
end