-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
101 lines (86 loc) · 2.49 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
require 'fileutils'
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"] || "funky-cli"
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
%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 "Create gem package"
task :gem => :compile do
FileUtils.cd(File.dirname(File.realpath(__FILE__)))
FileUtils.rm_rf("./exe")
FileUtils.mkdir_p("./exe")
files = Dir["mruby/build/**/bin/funky-cli*"].inject({}) do |hash, f|
arch = f.match(/mruby\/build\/(.*)\/bin/)[1]
if arch == "host"
hash
else
if f[-3..-1] == "exe"
hash[f] = "exe/#{arch}.exe"
else
hash[f] = "exe/#{arch}"
end
hash
end
end
files.each do |from,to|
FileUtils.cp(from, to)
end
FileUtils.chmod 0755, Dir["exe/*"]
sh "gem build funky-cli.gemspec"
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