-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathRakefile.rb
361 lines (297 loc) · 10.2 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
# Define constants for file locations etc
HFM_VER = ENV['hfm'] || '11.1.2.2'
HFM_LIB = "lib/hfm-#{HFM_VER}"
LOG4NET35_LIB = 'lib\log4net-1.2.11\bin\net\3.5\release'
LOG4NET40_LIB = 'lib\log4net-1.2.11\bin\net\4.0\release'
FRAMEWORK35_DIR = 'C:\WINDOWS\Microsoft.NET\Framework\v3.5'
FRAMEWORK40_DIR = 'C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319'
BUILD_DIR = 'gen'
RELEASE_DIR = 'bin'
PACKAGE_DIR = 'package'
BUILD35_DIR = "#{BUILD_DIR}/NET_3.5_HFM_#{HFM_VER}"
RELEASE35_DIR = "#{RELEASE_DIR}/NET_3.5_HFM_#{HFM_VER}"
HFMCMD35_EXE = "#{BUILD35_DIR}/HFMCmd.exe"
HFMCMD35_BUNDLE = "#{RELEASE35_DIR}/HFMCmd.exe"
BUILD40_DIR = "#{BUILD_DIR}/NET_4.0"
RELEASE40_DIR = "#{RELEASE_DIR}/NET_4.0"
HFMCMD40_EXE = "#{BUILD40_DIR}/HFMCmd.exe"
HFMCMD40_BUNDLE = "#{RELEASE40_DIR}/HFMCmd.exe"
RESOURCES = FileList['resources/*.resx']
PROPERTIES = FileList['properties/*']
SOURCE_FILES = FileList['src/**/*.cs']
PACKAGE_FILES = ['README.md', 'LICENSE', 'HISTORY']
def settings_for_version(version)
s = {}
case version
when "3.5"
s[:exe] = HFMCMD35_EXE.gsub('/', '\\')
s[:bundle] = HFMCMD35_BUNDLE.gsub('/', '\\')
s[:log4net] = LOG4NET35_LIB
s[:dotnet] = FRAMEWORK35_DIR
s[:hfm_ref] = "/reference"
s[:ilmerge] = "v2"
when "4.0"
s[:exe] = HFMCMD40_EXE.gsub('/', '\\')
s[:bundle] = HFMCMD40_BUNDLE.gsub('/', '\\')
s[:log4net] = LOG4NET40_LIB
s[:dotnet] = FRAMEWORK40_DIR
s[:hfm_ref] = "/link"
s[:ilmerge] = "v4"
else
raise "Invalid .NET version number"
end
s
end
def increment_build(version, build_dir)
require 'erb'
FileUtils.mkdir_p build_dir
commits = `git log --oneline`
commits = commits.split("\n")
@build_num = commits.size
@git_hash = commits[0].split(' ')[0]
@platform = ".NET #{version}"
if version == "3.5"
@platform += " / HFM #{HFM_VER}"
end
template = File.read('properties/AssemblyInfo.cs.erb')
erb = ERB.new(template)
File.open("#{build_dir}/AssemblyInfo.cs", "w") do |f|
f.puts erb.result
end
puts "Build is now: #{@build_num}"
end
def get_version
f = File.new('properties/AssemblyInfo.cs.erb', 'r')
begin
f.each_line do |line|
if line =~ /AssemblyVersion\("(\d+\.\d+\.\d+)/
return $1
end
end
ensure
f.close
end
end
def compile_resource(source)
name = File.basename(source, '.resx')
"tools\\ResGen.exe #{source} gen\\HFMCmd.Resource.#{name}.resources /str:cs,HFMCmd.Resource,#{name},gen\\#{name}Resource.cs"
end
def compile(version)
build_dir = version == "3.5" ? BUILD35_DIR : BUILD40_DIR
late_bind = version == "4.0"
increment_build(version, build_dir)
s = settings_for_version(version)
options = "/nologo /target:exe /main:HFMCmd.Launcher /out:#{s[:exe]} /debug /optimize+ /define:HFM_#{HFM_VER.gsub('.', '_')}"
options += " /define:HFM_11_1_2_2" if HFM_VER =~ /11\.1\.2\.2\.\d+/
options += " /define:HFM_11_1_2_2" if HFM_VER =~ /11\.1\.2\.3(\.\d+)?/
options += " /define:HFM_11_1_2_2_300" if HFM_VER =~ /11\.1\.2\.3(\.\d+)?/
options += " /define:LATE_BIND" if late_bind
log4net_ref = "/lib:#{s[:log4net]} /reference:log4net.dll"
hfm = ["/lib:#{HFM_LIB}"]
if late_bind
hfm << "#{s[:hfm_ref]}:Interop.HFMCONSTANTSLib.dll"
hfm << "#{s[:hfm_ref]}:Interop.HSVSECURITYACCESSLib.dll"
hfm << "#{s[:hfm_ref]}:Interop.HSVSTARSCHEMAACMLib.dll"
hfm << "#{s[:hfm_ref]}:Interop.HSVCDATALOADLib.dll"
hfm << "#{s[:hfm_ref]}:Interop.HSVJOURNALLOADACVLib.dll"
hfm << "#{s[:hfm_ref]}:Interop.HSVMETADATALOADACVLib.dll"
hfm << "#{s[:hfm_ref]}:Interop.HSVSECURITYLOADACVLib.dll"
fso_ref = ''
else
FileList["#{HFM_LIB}/*.dll"].each do |dll|
hfm << "#{s[:hfm_ref]}:#{File.basename(dll)}"
end
fso_ref = "/lib:lib /reference:Interop.SCRIPTINGLib.dll"
end
resources = FileList['gen/*.resources'].map{ |f| "/resource:#{f.gsub('/', '\\')}" }
source = "src\\*.cs src\\command\\*.cs src\\commandline\\*.cs src\\yaml\\*.cs src\\hfm\\*.cs gen\\*.cs #{build_dir}\\*.cs"
"#{s[:dotnet]}\\csc.exe #{options} #{log4net_ref} #{fso_ref} #{hfm.join(' ')} #{resources.join(' ')} #{source}"
end
# Bundles all log4net and HFM interop .dlls into the HFMCmd.exe,
# so that HFMCmd can be distributed as a single .exe
def bundle(version)
s = settings_for_version(version)
tgt = version == "3.5" ? '' : "/targetplatform:#{s[:ilmerge]},#{s[:dotnet]}"
"tools\\ILMerge\\ILMerge.exe #{tgt} /wildcards /lib:#{s[:dotnet]} /out:#{s[:bundle]} #{s[:exe]} #{s[:hfm_ref] == '/link' ? '' : "#{HFM_LIB}\\*.dll"} #{s[:log4net]}\\log4net.dll lib\\Interop.SCRIPTINGLib.dll"
end
# Creates a zip file archive containing HFMCmd.exe and the README, LICENSE, and
# HISTORY documents
def package(package_name, *files)
file_list = files.flatten.map { |f| %Q{"#{Dir.pwd}/#{f}"} }.join(' ')
"tools\\7za.exe a #{PACKAGE_DIR}/#{package_name}.zip #{file_list}"
end
MethodInfo = Struct.new(:version, :library, :class, :method_name, :slot, :args)
def compare_hfm_versions
versions = []
methods = Hash.new{ |h, k| h[k] = {} }
FileList['lib/hfm-*'].each do |hfm_dir|
hfm_dir =~ /([\d.]+)$/
versions << $1
process_dlls(hfm_dir, $1, methods)
end
slot_count = 0
arg_count = 0
FileUtils.mkdir_p('diff')
f1 = File.new('diff/hfm_vtable_changes.txt', 'w')
f2 = File.new('diff/hfm_arg_changes.txt', 'w')
f1.puts "Library\tClass\tMethod\t#{versions.join("\t")}"
f2.puts "Library\tClass\tMethod\tVersion\tArguments"
methods.sort.each do |key, vers|
slots = vers.map{ |ver, mi| mi.slot }
args = vers.map{ |ver, mi| mi.args.join(', ') }
if slots.uniq.size > 1
f1.puts "#{key}\t#{versions.map{ |ver| vers[ver] && vers[ver].slot || '-' }.join("\t")}"
slot_count += 1
end
if args.map(&:upcase).uniq.size > 1
versions.map do |ver|
f2.puts "#{key}\t#{ver}\t#{vers[ver].args.join(', ')}" if vers[ver]
end
arg_count += 1
end
end
f1.close
f2.close
puts "Found #{slot_count} vtable layout changes and #{arg_count} argument changes"
puts "Results can be found in the diff directory"
end
def process_dlls(dir, ver, methods)
puts "Processing #{dir}..."
FileList["#{dir}/*.dll"].each do |dll|
out = dump_vtable(dll)
dll =~ /Interop\.(\w+)\.dll/
mod = $1
cls_or_ifc = nil
count = 0
is_class = false
get_name = false
mthd = nil
slot = nil
out.each do |line|
if line =~ /^\.class/
puts " #{mod} #{cls_or_ifc}... #{count}" if count > 0
mthd = nil
is_class = !line.match(/\binterface\b/)
cls_or_ifc = line.match(/(\w+)$/)[1]
count = 0
next
end
if is_class
if line =~ /^\s+\.method \/\*([0-9A-F]+)/
get_name = true
slot = $1
elsif get_name
if line =~ /(\w+)(?:\(\)|\(\[(?:in|out)\])/
mthd = MethodInfo.new(ver, mod, cls_or_ifc, $1, slot, [])
methods["#{mod}\t#{cls_or_ifc}\t#{$1}"][ver] = mthd
count += 1
get_name = false
end
end
if line =~ /(\[(?:in|out)\]) (\w+)(?:.*) (\w+)(?:,|(?:\)[^\)]*))/
mthd.args << "#{$1} #{$2} #{$3}"
end
end
end
end
end
def dump_vtable(dll)
`tools\\ILDasm.exe /tokens /text /noca /pubonly #{dll}`.split("\n")
end
# ---------
directory BUILD_DIR
directory BUILD35_DIR
directory BUILD40_DIR
# Define a rule for converting .resx files into .resources
rule '.resources' => proc{ |t| "resources/#{t.split('.')[2]}.resx" } do |t|
sh compile_resource(t.source)
end
# Define resource dependencies on .resx files
desc "Generate resources"
task :resources => BUILD_DIR
RESOURCES.each do |resx|
file resx
name = File.basename(resx, '.resx')
task :resources => "gen/HFMCmd.Resource.#{name}.resources"
end
namespace :dotnet35 do
directory RELEASE35_DIR
# Define .exe dependencies on source files
file HFMCMD35_EXE => :resources
file HFMCMD35_EXE => :properties
SOURCE_FILES.each do |src|
file HFMCMD35_EXE => src
end
file HFMCMD35_EXE => BUILD35_DIR do
sh compile("3.5")
end
file HFMCMD35_BUNDLE => [RELEASE35_DIR, HFMCMD35_EXE] do
sh bundle("3.5")
end
desc "Compile and package HFMCmd using the .NET 3.5 framework"
task :build => HFMCMD35_BUNDLE
desc "Create a download package for the .NET 3.5 framework"
task :package => :build do
ver = get_version
sh package "HFMCmd_#{ver}_for_.NET_3.5_HFM_#{HFM_VER}", HFMCMD35_BUNDLE, PACKAGE_FILES
end
end
namespace :dotnet40 do
directory RELEASE40_DIR
# Define .exe dependencies on source files
file HFMCMD40_EXE => :resources
file HFMCMD40_EXE => :properties
SOURCE_FILES.each do |src|
file HFMCMD40_EXE => src
end
file HFMCMD40_EXE => BUILD40_DIR do
sh compile("4.0")
end
file HFMCMD40_BUNDLE => [RELEASE40_DIR, HFMCMD40_EXE] do
sh bundle("4.0")
end
desc "Compile and package HFMCmd using the .NET 4.0 framework"
task :build => HFMCMD40_BUNDLE
desc "Create a download package for the .NET 4.0 framework"
task :package => :build do
ver = get_version
sh package "HFMCmd_#{ver}_for_.NET_4.0", HFMCMD40_BUNDLE, PACKAGE_FILES
end
end
desc "Remove all generated files"
task :clean do
FileUtils.rm_rf BUILD_DIR
FileUtils.rm_rf RELEASE_DIR
end
desc "Dump intreop assembly details to a text file"
task :dump_vtables do
puts "Dumping interop details as text to #{HFM_LIB}..."
count = 0
FileList["#{HFM_LIB}/*.dll"].each do |dll|
out = dump_vtable(dll)
File.open("#{HFM_LIB}/#{File.basename(dll, '.dll')}.txt", "w") { |f| f.puts out }
count += 1
end
puts " Output #{count} assembly dumps"
end
desc "Compare HFM libraries for breaking changes"
task :compare_hfm_versions do
compare_hfm_versions
end
desc "Re-generate build.bat, useful for building HFMCmd without Ruby / rake"
task "build.bat" do |t|
require 'erb'
template = File.read("build.bat.erb")
@resources = RESOURCES.map { |res| compile_resource(res) }
@compile_35 = compile("3.5")
@compile_40 = compile("4.0")
@bundle_35 = bundle("3.5")
@bundle_40 = bundle("4.0")
erb = ERB.new(template)
File.open("build_for_#{HFM_VER}.bat", "w") do |f|
f.puts erb.result
end
end
task :default => 'dotnet35:build'
task :build => ['dotnet35:build', 'dotnet40:build']
task :package => [:build, 'dotnet35:package', 'dotnet40:package']