forked from hone/mruby-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
118 lines (90 loc) · 2.95 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
MRUBY_VERSION="1.2.0"
APP_NAME = ENV.fetch "APP_NAME", "mruby-cli"
APP_ROOT = ENV.fetch "APP_ROOT", Dir.pwd
def expand_and_set(env_name, default)
unexpanded = ENV.fetch env_name, default
expanded = File.expand_path unexpanded
ENV[env_name] = expanded
end
# avoid redefining constants in mruby Rakefile
mruby_root = expand_and_set "MRUBY_ROOT", "#{APP_ROOT}/mruby"
mruby_config = expand_and_set "MRUBY_CONFIG", "build_config.rb"
directory mruby_root 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/#{MRUBY_VERSION}.tar.gz -s -o - | tar zxf -"
mv "mruby-#{MRUBY_VERSION}", mruby_root
end
task :mruby => mruby_root
mruby_rakefile = "#{mruby_root}/Rakefile"
file mruby_rakefile => mruby_root
import mruby_rakefile
test_rakefile = "tasks/test.rake"
file test_rakefile => mruby_rakefile
import test_rakefile
task :app_version do
load "mrbgem.rake"
current_gem = MRuby::Gem.current
app_version = MRuby::Gem.current.version
APP_VERSION = (app_version.nil? || app_version.empty?) ? "unknown" : app_version
end
desc "compile all the binaries"
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
desc "cleanup"
task :clean do
sh "rake deep_clean"
end
desc "generate a release tarball"
task :release => :compile do
require 'tmpdir'
release_path = File.expand_path "releases/v#{APP_VERSION}"
app_name = "#{APP_NAME}-#{APP_VERSION}"
mkdir_p release_path
Dir.mktmpdir do |tmp_dir|
cd tmp_dir do
MRuby.each_target do |target|
next if name == "host"
arch = name
bin = "#{build_dir}/bin/#{exefile(APP_NAME)}"
mkdir_p name
cp bin, name
cd arch do
arch_release = "#{app_name}-#{arch}"
puts "Writing #{release_path}/#{arch_release}.tgz"
`tar czf #{release_path}/#{arch_release}.tgz *`
end
end
puts "Writing #{release_path}/#{app_name}.tgz"
`tar czf #{release_path}/#{app_name}.tgz *`
end
end
end
def is_in_a_docker_container?
`grep -q docker /proc/self/cgroup`
$?.success?
end
namespace :local do
desc "show version"
task :version do
puts "#{APP_NAME} #{APP_VERSION}"
end
task :ensure_in_docker do
unless is_in_a_docker_container? then
abort "Not running in docker, you should type \"docker-compose run <task>\"."
end
end
end
Rake.application.tasks.each do |task|
next if task.name.start_with?("local:")
next if Rake::FileTask === task
task task.name => "local:ensure_in_docker"
end unless ENV["MRUBY_CLI_LOCAL"]
file "tasks/package.rake" => :app_version
import "tasks/package.rake"