-
Notifications
You must be signed in to change notification settings - Fork 7
/
Rakefile
103 lines (91 loc) · 2.83 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
require 'fileutils'
$verbose=true
MRUBY_VERSION="1.2.0"
file :mruby do
#sh "git clone --depth=1 https://github.com/mruby/mruby"
sh "curl -L --fail --retry 3 --retry-delay 1 https://github.com/mruby/mruby/archive/1.2.0.tar.gz -s -o - | tar zxf -"
FileUtils.mv("mruby-1.2.0", "mruby")
end
APP_NAME=ENV["APP_NAME"] || "intercom-export"
APP_ROOT=ENV["APP_ROOT"] || Dir.pwd
# avoid redefining constants in mruby Rakefile
mruby_root=File.expand_path(ENV["MRUBY_ROOT"] || "#{APP_ROOT}/mruby")
mruby_config=File.expand_path(ENV["MRUBY_CONFIG"] || "build_config.rb")
ENV['MRUBY_ROOT'] = mruby_root
ENV['MRUBY_CONFIG'] = mruby_config
Rake::Task[:mruby].invoke unless Dir.exist?(mruby_root)
Dir.chdir(mruby_root)
load "#{mruby_root}/Rakefile"
desc "compile binary"
task :compile => [:all] do
MRuby.each_target do |target|
`#{target.cc.command} --version`
abort("Command #{target.cc.command} for #{target.name} is missing.") unless $?.success?
end
%W(#{mruby_root}/build/x86_64-pc-linux-gnu/bin/#{APP_NAME} #{mruby_root}/build/i686-pc-linux-gnu/#{APP_NAME}").each do |bin|
sh "strip --strip-unneeded #{bin}" if File.exist?(bin)
end
end
namespace :test do
desc "run mruby & unit tests"
# only build mtest for host
task :mtest => :compile do
# in order to get mruby/test/t/synatx.rb __FILE__ to pass,
# we need to make sure the tests are built relative from mruby_root
MRuby.each_target do |target|
# only run unit tests here
target.enable_bintest = false
run_test if target.test_enabled?
end
end
def clean_env(envs)
old_env = {}
envs.each do |key|
old_env[key] = ENV[key]
ENV[key] = nil
end
yield
envs.each do |key|
ENV[key] = old_env[key]
end
end
desc "run integration tests"
task :bintest => :compile do
MRuby.each_target do |target|
clean_env(%w(MRUBY_ROOT MRUBY_CONFIG)) do
run_bintest if target.bintest_enabled?
end
end
end
end
desc "run all tests"
Rake::Task['test'].clear
task :test => ["test:mtest", "test:bintest"]
desc "cleanup"
task :clean do
sh "rake deep_clean"
end
namespace :local do
desc "show help"
task :version do
require_relative 'mrblib/mruby-cli/version'
puts "mruby-cli #{MRubyCLI::Version::VERSION}"
end
end
def is_in_a_docker_container?
`grep -q docker /proc/self/cgroup`
$?.success?
end
Rake.application.tasks.each do |task|
next if ENV["MRUBY_CLI_LOCAL"]
unless task.name.start_with?("local:")
# Inspired by rake-hooks
# https://github.com/guillermo/rake-hooks
old_task = Rake.application.instance_variable_get('@tasks').delete(task.name)
desc old_task.full_comment
task old_task.name => old_task.prerequisites do
abort("Not running in docker, you should type \"docker-compose run <task>\".") unless is_in_a_docker_container?
old_task.invoke
end
end
end