/
bbh.rb
162 lines (141 loc) · 4.23 KB
/
bbh.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
require 'find'
require 'fileutils'
require 'rexml/document'
# BooBuildHelper (Bbh)
class Bbh
def initialize()
end
def self.findBooFilesIn(baseDir)
findFilesWithExtensionInBaseDir(baseDir, '.boo').join(' ')
end
def self.createFolderIfNeeded(path)
Dir.mkdir(path) unless File.directory?(path)
end
def self.removeFolderIfNeeded(path)
FileUtils.rm_rf path unless !File.directory?(path)
end
def self.outputTo(directory, fileName)
'-o:' + convertToPlatformSeparator(directory + '/' + fileName) + ' '
end
def self.referenceAssemblies(assemblies)
cleanAsms = []
assemblies.each do |path|
temp = convertToPlatformSeparator(path)
cleanAsms.push(temp)
end
"-r:"+cleanAsms.join(',') + ' '
end
def self.copyNonGacDependenciesTo(buildDir, projFilePath, isRelativePath)
buildDir = convertToPlatformSeparator(buildDir)
path = convertToPlatformSeparator(projFilePath)
projFile = REXML::Document.new File.read(path)
dirName = File.dirname(path)
hintPaths = []
projFile.elements.each('Project/ItemGroup/Reference') do |reference|
if reference.elements['HintPath'] != nil
reference.elements.each('HintPath') do |path|
if isRelativePath
hintPaths.push convertToPlatformSeparator(dirName + "/" + path.text)
else
hintPaths.push convertToPlatformSeparator(path.text)
end
end
end
end
hintPaths.each do |path|
cp(path, buildDir)
end
end
def self.copyAllFilesFromTo(fromPath, toPath)
fromPath = convertToPlatformSeparator(fromPath)
toPath = convertToPlatformSeparator(toPath)
files = []
exploreDirSearchForFilesAndStoreInList(fromPath, nil, files)
files.each do |path|
cp(path, toPath)
end
end
def self.dllTarget
'-target:library '
end
def self.exeTarget
'-target:exe '
end
def self.referenceDependenciesInMSBuild(path, projectRefsBinPath, isRelativePath)
path = convertToPlatformSeparator(path)
projFile = REXML::Document.new File.read(path)
dirName = File.dirname(path)
asmNames = []
hintPaths = []
projFile.elements.each('Project/ItemGroup/Reference') do |reference|
asmNames.push reference.attributes['Include']
if reference.elements['HintPath'] != nil
reference.elements.each('HintPath') do |path|
if isRelativePath
hintPaths.push convertToPlatformSeparator(dirName + "/" + path.text)
else
hintPaths.push convertToPlatformSeparator(path.text)
end
end
else
hintPaths.push ''
end
end
refs = []
asmNames.each_with_index do |asmName, i|
if hintPaths[i] == ''
refs.push asmName
else
refs.push hintPaths[i]
end
end
projRefs = referenceProjectReferences(convertToPlatformSeparator(projectRefsBinPath), projFile)
projRefs.each do |ref|
refs.push ref
end
referenceAssemblies(refs)
end
def self.referenceProjectReferences(referenceBinsPath, projFile)
refs = []
projFile.elements.each('/Project/ItemGroup/ProjectReference/Name') do |name|
puts name.text
refs.push(convertToPlatformSeparator(referenceBinsPath + '/' + name.text + '.dll'))
end
refs
end
def self.convertToPlatformSeparator(path)
separator = File::SEPARATOR
if isWindowsPlatform
separator = File::ALT_SEPARATOR
end
path.gsub(/(\\|\/)/, separator)
end
def self.isWindowsPlatform
proc, platform, *rest = RUBY_PLATFORM.split('-')
if platform == 'mswin32'
return true
else
return false
end
end
def self.findFilesWithExtensionInBaseDir(baseDir, extension)
arr = []
baseDir = convertToPlatformSeparator(baseDir)
exploreDirSearchForFilesAndStoreInList(baseDir, extension, arr)
arr.uniq
end
def self.exploreDirSearchForFilesAndStoreInList(dir, extension, arr)
Find.find(dir) do |path|
if path == dir
next
end
if FileTest.directory?(path)
exploreDirSearchForFilesAndStoreInList(path, extension, arr)
else
if extension == nil || File.extname(path).downcase == extension
arr.push(convertToPlatformSeparator(path))
end
end
end
end
end