-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
271 lines (223 loc) · 7.59 KB
/
Rakefile
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
require 'yaml'
# ModBoost root path
ROOT_PATH = File.expand_path File.dirname(__FILE__)
# Load the YAML configuration file
CONF_FILE = File.join ROOT_PATH, 'modboost.yaml'
CONF = File.open(CONF_FILE) { |f| YAML.load f }
raise "Unable to load YAML configuration file from #{CONF_FILE}" unless CONF
CONF.each do |param, val|
Object.const_set "CONF_#{param.upcase}", val
end
[
'components',
'default_branch',
'default_base_repo',
'cmake_args',
'publish_path'
].each do |param|
raise "Missing mandatory parameter '#{param}' in configuration file." unless CONF[param]
end
COMPONENTS = CONF_COMPONENTS.keys
# ModBoost workspace
WORK_PATH = File.join ROOT_PATH, 'workspace'
# Required binaries
BINARIES = ['git', 'cmake', 'make']
BINARIES.each do |bin|
bin_path = %x[ which #{bin} ].strip
raise "Executable #{bin} not found!" unless File.executable?(bin_path)
Object.const_set "#{bin.upcase}_BIN", bin_path
end
# Number of make jobs
MAKE_JOBS = [ENV['jobs'].to_i, 1].max
# Path to cloned sources
def component_src_path(cmp)
File.join WORK_PATH, 'src', cmp
end
# Path to build output
def component_build_path(cmp)
File.join WORK_PATH, 'build', cmp
end
# Path to installed components
def component_install_path(cmp)
File.join WORK_PATH, 'install', cmp
end
# Run a shell command
def do_shell(cmd)
puts "[MODBOOST]:#{Dir.pwd}$ #{cmd}"
raise "Shell command failure" unless system(cmd)
end
# Lookup the Git branch of a component
def component_branch(cmp)
CONF_COMPONENTS[cmp].fetch('branch', CONF_DEFAULT_BRANCH)
end
# Lookup the build dependencies of a component
def component_deps(cmp)
CONF_COMPONENTS[cmp].fetch('deps', [])
end
# Lookup the repository of a component
def component_repo(cmp)
CONF_COMPONENTS[cmp].fetch('repo', "#{CONF_DEFAULT_BASE_REPO}/#{cmp}.git")
end
# Lookup the CMake variables of a component
def lookup_cmake_vars(cmp)
cmp_src_path = component_src_path cmp
cmp_build_path = component_build_path cmp
cmake_vars = {}
if File.executable?(cmp_src_path) && File.executable?(cmp_build_path)
::Dir.chdir(cmp_build_path) do
result = %x[ #{CMAKE_BIN} -N -LA #{cmp_src_path} ]
if $?.success?
result.split("\n").each do |line|
variable, value = line.split(':', 2)
cmake_vars[variable] = value.split('=', 2).last if value
end
else
STDERR.puts "CMake error while loading the cache from #{cmp_build_path}"
end
end
end
cmake_vars
end
COMPONENTS_CMAKE_VARS = {}
def component_cmake_vars(cmp)
COMPONENTS_CMAKE_VARS[cmp] ||= lookup_cmake_vars cmp
end
# Version of a component
def component_version(cmp)
component_cmake_vars(cmp)['PACKAGE_VERSION']
end
# Library path of a component
def component_libpath(cmp)
vars = component_cmake_vars cmp
libdir = vars.fetch('INSTALL_LIB_DIR', 'lib')
File.join component_install_path(cmp), libdir
end
# Makefile of a component
def component_makefile(cmp)
File.join component_build_path(cmp), 'Makefile'
end
desc "Display configuration information"
task :info do
puts "Components:"
COMPONENTS.each do |cmp|
cmp_deps = component_deps cmp
cmp_repo = component_repo cmp
cmp_branch = component_branch cmp
cmp_version = component_version cmp
cmp_libpath = component_libpath cmp
puts " * #{cmp}"
puts " Git repository : #{cmp_repo}"
puts " Checkout branch : #{cmp_branch}"
puts " Depends on : #{cmp_deps.join ', '}" unless cmp_deps.empty?
puts " Source cloned at : #{component_src_path cmp}"
puts " Built from : #{component_build_path cmp}"
puts " Installed to : #{component_install_path cmp}"
puts " Library path : #{cmp_libpath}"
puts " Release version : #{cmp_version}" if cmp_version
puts
end
puts "CMake arguments : #{CONF_CMAKE_ARGS}"
puts "Publish to : #{CONF_PUBLISH_PATH}"
end
directory WORK_PATH
# Define all global tasks
SIMPLE_GIT_TASKS = [
:status, :push, :pull
]
SIMPLE_MAKE_TASKS = [
:check, :install, :clean, :rebuild_cache, :test
]
COMPLEX_TASKS = [
:clone, :checkout, :configure, :build, :dist
]
(SIMPLE_GIT_TASKS + SIMPLE_MAKE_TASKS + COMPLEX_TASKS).each do |t|
desc "#{t.to_s.capitalize} on all components"
task t
end
COMPONENTS.each do |cmp|
cmp_deps = component_deps cmp
cmp_repo = component_repo cmp
cmp_branch = component_branch cmp
cmp_src_path = component_src_path cmp
cmp_build_path = component_build_path cmp
cmp_install_path = component_install_path cmp
cmp_makefile = component_makefile cmp
# Clone tasks
file cmp_src_path => WORK_PATH do
do_shell "#{GIT_BIN} clone -n #{cmp_repo} #{cmp_src_path}"
end
desc "Clone component #{cmp} in #{cmp_src_path}"
task "clone_#{cmp}" => cmp_src_path
task :clone => "clone_#{cmp}"
# Wrappers for simple git tasks
SIMPLE_GIT_TASKS.each do |gittask|
cmp_task = "#{gittask}_#{cmp}"
desc "#{gittask.to_s.capitalize} on component #{cmp} in #{cmp_src_path}"
task cmp_task => cmp_src_path do
::Dir.chdir(cmp_src_path) do
do_shell "#{GIT_BIN} #{gittask}"
end
end
task gittask => cmp_task
end
# Checkout tasks
desc "Checkout branch #{cmp_branch} of component #{cmp}"
task "checkout_#{cmp}" => "pull_#{cmp}" do
::Dir.chdir(cmp_src_path) do
do_shell "#{GIT_BIN} checkout #{cmp_branch}"
end
end
task :checkout => "checkout_#{cmp}"
# Configuration tasks
cmake_deps_args = cmp_deps.map { |dep| "-DWITH_#{dep.upcase}_PREFIX=#{component_install_path dep}" }.join ' '
config_prereqs = ["checkout_#{cmp}"] + cmp_deps.map { |dep| "install_#{dep}" }
file cmp_makefile => config_prereqs do
mkdir_p cmp_build_path
do_shell "#{CMAKE_BIN} #{cmake_deps_args} #{CONF_CMAKE_ARGS} -DCMAKE_INSTALL_PREFIX=#{cmp_install_path} -DBUILDDIR=#{cmp_build_path} -DBUILDSTEP=config -P build.cmake"
end
desc "Configure component #{cmp} in #{cmp_build_path}"
task "configure_#{cmp}" => cmp_makefile
task :configure => "configure_#{cmp}"
# Build tasks
#cmake_deps_args = cmp_deps.map { |dep| "-DWITH_#{dep.upcase}_PREFIX=#{component_install_path dep}" }.join ' '
cmp_build = "build_#{cmp}"
build_prereqs = ["configure_#{cmp}"] + cmp_deps.map { |dep| "install_#{dep}" }
task cmp_build => build_prereqs do
do_shell "#{CMAKE_BIN} #{cmake_deps_args} #{CONF_CMAKE_ARGS} -DCMAKE_INSTALL_PREFIX=#{cmp_install_path} -DBUILDDIR=#{cmp_build_path} -DBUILDSTEP=build -P build.cmake"
end
desc "Build component #{cmp} in #{cmp_build_path}"
task :build => "build_#{cmp}"
# Wrappers for simple make tasks
SIMPLE_MAKE_TASKS.each do |maketask|
cmp_task = "#{maketask}_#{cmp}"
desc "#{maketask.to_s.capitalize} on component #{cmp} in #{cmp_build_path}"
task cmp_task => cmp_makefile do
::Dir.chdir(cmp_build_path) do
do_shell "#{MAKE_BIN} -j#{MAKE_JOBS} #{maketask}"
end
end
task maketask => cmp_task
end
# Distribution tasks
cmp_version = component_version cmp
if cmp_version
arch_name = "#{cmp}-#{cmp_version}.tar.bz2"
arch_path_src = File.join cmp_build_path, arch_name
file arch_path_src => cmp_makefile do
::Dir.chdir(cmp_build_path) do
do_shell "#{MAKE_BIN} dist"
end
end
directory CONF_PUBLISH_PATH
arch_path_dst = File.join CONF_PUBLISH_PATH, arch_name
file arch_path_dst => [arch_path_src, CONF_PUBLISH_PATH] do
cp arch_path_src, arch_path_dst
end
desc "Publish component #{cmp} to #{arch_path_dst}"
task "dist_#{cmp}" => arch_path_dst
task :dist => "dist_#{cmp}"
else
puts "Warning: package version of component #{cmp} is not available. You have to install it first."
end
end
task :default => :build