openc3/Rakefile
# encoding: ascii-8bit
# Copyright 2022 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 Affero General Public License
# as published by the Free Software Foundation; version 3 with
# attribution addendums as found in the LICENSE.txt
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# Modified by OpenC3, Inc.
# All changes Copyright 2022, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
# if purchased from OpenC3, Inc.
require 'open3'
# Import the rake tasks
import 'tasks/spec.rake'
import 'tasks/gemfile_stats.rake'
# Update the built in task dependencies
task :default => [:spec] # :test
task :devkit do
if RbConfig::CONFIG['target_os'] =~ /mswin|mingw|cygwin/i and RUBY_ENGINE == 'ruby'
msys64_path = File.expand_path(File.join(File.dirname(`where ruby`.split("\n")[0]), '..', 'msys64'))
if File.exist?(msys64_path)
ENV['RI_DEVKIT'] = msys64_path
ENV['MSYSTEM'] = "MINGW64"
ENV['PKG_CONFIG_PATH'] = "/mingw64/lib/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'] = "#{File.join(msys64_path, "mingw64", "bin").gsub("/", "\\")};#{File.join(msys64_path, "usr", "bin").gsub("/", "\\")};" + ENV['PATH']
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 /darwin/.match?(platform)
extensions = [
'burst_protocol',
'crc',
'polynomial_conversion',
'config_parser',
'string',
'array',
'openc3_io',
'tabbed_plots_config',
'telemetry',
'packet',
'platform',
'buffered_file',
'reducer_microservice'
]
extensions.each do |extension_name|
Dir.chdir "ext/openc3/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/openc3/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 :gems 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 openc3.gemspec')
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`
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