Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ load "#{mruby_root}/Rakefile"

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
Expand Down Expand Up @@ -103,3 +107,31 @@ task :release => :compile do
end
end
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
5 changes: 3 additions & 2 deletions bintest/mruby-cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Dir.mktmpdir do |tmp_dir|
Dir.chdir(tmp_dir) do
app_name = "new_cli"
output, status = Open3.capture2(BIN_PATH, "--setup", app_name)
output, status = Open3.capture2("#{BIN_PATH} --setup=#{app_name}")

assert_true status.success?, "Process did not exit cleanly"
assert_true Dir.exist?(app_name)
Expand All @@ -25,13 +25,14 @@
Dir.mktmpdir do |tmp_dir|
Dir.chdir(tmp_dir) do
app_name = "hello_world"
APP_PATH = File.join("mruby/bin/#{app_name}")
Open3.capture2(BIN_PATH, "--setup", app_name)

Dir.chdir(app_name) do
output, status = Open3.capture2("rake compile")
assert_true status.success?, "`rake compile` did not exit cleanly"

output, status = Open3.capture2("mruby/bin/#{app_name}")
output, status = Open3.capture2(APP_PATH)
assert_true status.success?, "`#{app_name}` did not exit cleanly"
assert_include output, "Hello World"

Expand Down
33 changes: 33 additions & 0 deletions mrblib/mruby-cli/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,11 @@ def 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
Expand Down Expand Up @@ -377,6 +382,34 @@ def clean_env(envs)
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
RAKEFILE
end
end
Expand Down