forked from BallAerospace/COSMOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
335 lines (295 loc) · 9.53 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
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
# encoding: ascii-8bit
# Copyright 2014 Ball Aerospace & Technologies Corp.
# All Rights Reserved.
#
# This program is free software; you can modify and/or redistribute it
# under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 3 with
# attribution addendums as found in the LICENSE.txt
require 'open3'
# Cross-platform way of finding an executable in the $PATH.
#
# which('ruby') #=> /usr/bin/ruby
def which(cmd)
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
exts.each { |ext|
exe = File.join(path, "#{cmd}#{ext}")
return exe if File.executable?(exe) && !File.directory?(exe)
}
end
return nil
end
# Pure Ruby CRC class to avoid circular dependency with c_cosmos
class RakeCrc32
attr_reader :crc32_poly
attr_reader :crc32_seed
attr_reader :crc32_xor
attr_reader :crc32_table
attr_reader :crc32_raw_table
# Default Polynomial for 32-bit CRC
DEFAULT_CRC32_POLY = 0x04C11DB7
# Default Seed for 32-bit CRC
DEFAULT_CRC32_SEED = 0xFFFFFFFF
def initialize(crc32_poly = DEFAULT_CRC32_POLY, crc32_seed = DEFAULT_CRC32_SEED, crc32_xor = true)
@crc32_poly = crc32_poly
@crc32_seed = crc32_seed
@crc32_xor = crc32_xor
@crc32_table = []
(0..255).each do |index|
entry = compute_crc32_table_entry(index)
@crc32_table << entry
end
end
# Calculate a 32-bit CRC
def calc(data, seed = nil)
seed = @crc32_seed unless seed
crc = seed
data.each_byte do |byte|
index = ((crc >> 24) ^ byte) & 0xFF
crc = ((crc << 8) ^ @crc32_table[index]) & 0xFFFFFFFF
end
if @crc32_xor
crc ^ 0xFFFFFFFF
else
crc
end
end
protected
# Compute a single entry in the 32-bit crc lookup table
def compute_crc32_table_entry(index)
crc = index << 24
8.times do
if ((crc & 0x80000000) != 0)
crc = (crc << 1) ^ @crc32_poly
else
crc = crc << 1
end
end
return (crc & 0xFFFFFFFF)
end
end
require 'yard' if RUBY_ENGINE == 'ruby'
# Import the rake tasks
import 'tasks/manifest.rake'
import 'tasks/spec.rake'
import 'tasks/gemfile_stats.rake'
# Update the built in task dependencies
task :default => [:spec] # :test
task :require_version do
unless ENV['VERSION']
puts "VERSION is required: rake <task> VERSION=X.X.X"
exit 1
end
end
task :devkit do
if RUBY_ENGINE == 'ruby'
if RUBY_PLATFORM[0..2] == 'x64'
if File.exist?("C:/msys64/mingw64")
ENV['RI_DEVKIT'] = "C:\\msys64"
ENV['MSYSTEM']="MINGW64"
ENV['PKG_CONFIG_PATH']="/mingw64/lib/pkgconfig:/mingw64/share/pkgconfig"
ENV['ACLOCAL_PATH']="/mingw64/share/aclocal:/usr/share/aclocal"
ENV['MANPATH']="/mingw64/share/man"
ENV['MINGW_PACKAGE_PREFIX']="mingw-w64-x86_64"
ENV['LANG']="en_US.UTF-8"
ENV['PATH'] = 'C:\\msys64\\mingw64\\bin;C:\\msys64\\usr\\bin;' + ENV['PATH']
end
else
if File.exist?("C:/msys64/mingw32")
ENV['RI_DEVKIT'] = "C:\\msys64"
ENV['MSYSTEM']="MINGW32"
ENV['PKG_CONFIG_PATH']="/mingw32/lib/pkgconfig:/mingw32/share/pkgconfig"
ENV['ACLOCAL_PATH']="/mingw32/share/aclocal:/usr/share/aclocal"
ENV['MANPATH']="/mingw32/share/man"
ENV['MINGW_PACKAGE_PREFIX']="mingw-w64-i686"
ENV['LANG']="en_US.UTF-8"
ENV['PATH'] = 'C:\\msys64\\mingw32\\bin;C:\\msys64\\usr\\bin;' + ENV['PATH']
end
end
end
end
task :build => [:devkit] do
if RUBY_ENGINE == 'ruby'
_, platform, *_ = RUBY_PLATFORM.split("-")
saved = Dir.pwd
shared_extension = 'so'
shared_extension = 'bundle' if platform =~ /darwin/
extensions = [
'crc',
'low_fragmentation_array',
'polynomial_conversion',
'config_parser',
'string',
'array',
'cosmos_io',
'tabbed_plots_config',
'telemetry',
'line_graph',
'packet',
'platform',
'buffered_file']
extensions.each do |extension_name|
Dir.chdir "ext/cosmos/ext/#{extension_name}"
FileUtils.rm_f Dir.glob('*.o')
FileUtils.rm_f Dir.glob("*.#{shared_extension}")
FileUtils.rm_f Dir.glob('*.def')
FileUtils.rm_f 'Makefile'
system('ruby extconf.rb')
system('make')
FileUtils.copy("#{extension_name}.#{shared_extension}", '../../../../lib/cosmos/ext/.')
FileUtils.rm_f Dir.glob('*.o')
FileUtils.rm_f Dir.glob("*.#{shared_extension}")
FileUtils.rm_f Dir.glob('*.def')
FileUtils.rm_f 'Makefile'
Dir.chdir saved
end
end
end
task :git_checkout_master do
system('git checkout master')
end
task :install_crc do
saved = Dir.pwd
Dir.chdir 'demo'
system('bundle exec rake crc_official')
Dir.chdir saved
saved = Dir.pwd
Dir.chdir 'install'
system('bundle exec rake crc_official')
Dir.chdir saved
end
task :gem => [:require_version] do
_, platform, *_ = RUBY_PLATFORM.split("-")
if platform == 'mswin32' or platform == 'mingw32'
raise "Building gem is not supported on Windows because file permissions are lost"
end
system('gem build cosmos.gemspec')
end
task :commit_release_ticket => [:require_version, :git_checkout_master] do
system('git add data/crc.txt')
system('git add demo/config/data/crc.txt')
system('git add install/config/data/crc.txt')
system('git add lib/cosmos/version.rb')
system('git add Manifest.txt')
system("git commit -m \"Release COSMOS #{ENV['VERSION']}\"")
system("git push")
end
task :tag_release => [:require_version] do
system("git tag -a v#{ENV['VERSION']} -m \"COSMOS #{ENV['VERSION']}\"")
system("git push --tags")
end
task :version => [:require_version] do
puts "Getting the revision from git"
revision = `git rev-parse HEAD`.chomp
# Update cosmos_version.rb
version = ENV['VERSION'].dup
major,minor,patch = version.to_s.split('.')
File.open('lib/cosmos/version.rb', 'w') do |file|
file.puts "# encoding: ascii-8bit"
file.puts ""
file.puts "COSMOS_VERSION = '#{version}'"
file.puts "module Cosmos"
file.puts " module Version"
file.puts " MAJOR = '#{major}'"
file.puts " MINOR = '#{minor}'"
file.puts " PATCH = '#{patch}'"
file.puts " BUILD = '#{revision}'"
file.puts " end"
file.puts " VERSION = '#{version}'"
file.puts "end"
end
puts "Successfully updated lib/cosmos/version.rb"
# Create the crc.txt file
crc = RakeCrc32.new
File.open("data/crc.txt",'w') do |file|
Dir[File.join('lib','**','*.rb')].each do |filename|
file_data = File.open(filename, 'rb').read.gsub("\x0D\x0A", "\x0A")
file.puts "\"#{filename}\" #{sprintf("0x%08X", crc.calc(file_data))}"
end
end
end
task :metrics do
puts "\nRunning flog and creating flog_report.txt"
`flog lib > flog_report.txt`
puts "\nRunning flay and creating flay_report.txt"
`flay lib > flay_report.txt`
puts "\nRunning reek and creating reek_report.txt"
`reek lib > reek_report.txt`
puts "\nRunning roodi and creating roodi_report.txt"
`roodi -config=roodi.yml lib > roodi_report.txt`
end
task :stress do
puts "Running each spec individual with GC.stress = true..."
puts
ENV['STRESS'] = "1"
failed = []
Dir['spec/**/*_spec.rb'].each do |spec_file|
puts "Running: rspec #{spec_file}"
output, status = Open3.capture2e("rspec #{spec_file}")
if status.success?
puts " success (#{status}):"
#puts output
puts
else
puts " error (#{status}):"
puts output
puts
failed << spec_file
end
end
if failed.length > 0
puts "Failed specs:"
failed.each do |f|
puts " #{f}"
end
else
puts "Success!"
end
end
# Make all the main.sh files executable in the demo and install Mac applications
task :mac_app_exec_bit do
%w(demo install).each do |root|
Dir["#{root}/tools/mac/**/Contents/MacOS/main.sh"].each do |main|
`git add --chmod=+x #{main}`
end
end
end
if RUBY_ENGINE == 'ruby'
YARD::Rake::YardocTask.new do |t|
t.options = ['--protected'] # See all options by typing 'yardoc --help'
end
end
task :release => [:require_version, :git_checkout_master, :build, :spec, :manifest, :version, :install_crc, :gem]
task :commit_release => [:commit_release_ticket, :tag_release]
task :docker_build do
_, platform, *_ = RUBY_PLATFORM.split("-")
if (platform == 'mswin32' or platform == 'mingw32') and which('winpty')
system('winpty docker build --tag cosmos-dev .')
else
system('docker build --tag cosmos-dev .')
end
end
task :docker_run do
STDOUT.puts "Note, this is not automated on purpose to ensure each step is successful (with user entry of credentials for github/rubygems.org)"
STDOUT.puts "Steps to perform a COSMOS release:"
STDOUT.puts "1. git config --global user.name \"Last, First\""
STDOUT.puts "2. git config --global user.email \"[email protected]\""
STDOUT.puts "3. git pull"
STDOUT.puts "4. export VERSION=X.X.X"
STDOUT.puts "5. rake release"
STDOUT.puts "6. rake commit_release"
STDOUT.puts "7. export PATH=/opt/jruby/bin:$PATH"
STDOUT.puts "8. rake gem"
STDOUT.puts "9. /usr/bin/gem push cosmos-X.X.X.gem"
STDOUT.puts "10. /usr/bin/gem push cosmos-X.X.X-java.gem"
STDOUT.puts "11. cd /devel/cosmos-docker"
STDOUT.puts "12. git pull"
STDOUT.puts "13. Update COSMOS_VERSION in all Dockerfiles. Also update README.md"
STDOUT.puts "14. git commit -a -m \"Release COSMOS vX.X.X\""
STDOUT.puts "15. git push"
STDOUT.puts "16. git checkout -b vX.X.X"
STDOUT.puts "17. git push --set-upstream origin vX.X.X"
STDOUT.puts "18. Update release notes on github.com and cosmosrb.com"
system('docker run -it --rm cosmos-dev')
end