Skip to content

Commit

Permalink
Upgrade to mruby-cli 0.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
jkutner committed Dec 2, 2015
1 parent e25d45c commit 25c70de
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 30 deletions.
68 changes: 51 additions & 17 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
require 'fileutils'

MRUBY_VERSION="1.2.0"

file :mruby do
sh "git clone --depth=1 https://github.com/mruby/mruby"
#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"] || "mjruby"
APP_NAME=ENV["APP_NAME"] || "hello-mruby"
APP_ROOT=ENV["APP_ROOT"] || Dir.pwd
# avoid redefining constants in mruby Rakefile
mruby_root=File.expand_path(ENV["MRUBY_ROOT"] || "#{APP_ROOT}/mruby")
Expand All @@ -14,26 +20,27 @@ Dir.chdir(mruby_root)
load "#{mruby_root}/Rakefile"

desc "compile binary"
task :compile => [:mruby, :all] do
%W(#{MRUBY_ROOT}/build/host/bin/#{APP_NAME} #{MRUBY_ROOT}/build/i686-pc-linux-gnu/#{APP_NAME}").each do |bin|
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] + MRuby.targets.values.map {|t| t.build_mrbtest_lib_only? ? nil : t.exefile("#{t.build_dir}/test/mrbtest") }.compact do
# mruby-io tests expect to be in MRUBY_ROOT
Dir.chdir(MRUBY_ROOT) 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
load "#{MRUBY_ROOT}/test/mrbtest.rake"
MRuby.each_target do |target|
# only run unit tests here
target.enable_bintest = false
run_test unless build_mrbtest_lib_only?
end
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

Expand All @@ -53,7 +60,7 @@ namespace :test do
task :bintest => :compile do
MRuby.each_target do |target|
clean_env(%w(MRUBY_ROOT MRUBY_CONFIG)) do
run_bintest if bintest_enabled?
run_bintest if target.bintest_enabled?
end
end
end
Expand All @@ -65,5 +72,32 @@ task :test => ["test:mtest", "test:bintest"]

desc "cleanup"
task :clean do
sh "cd #{MRUBY_ROOT} && rake deep_clean"
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
13 changes: 1 addition & 12 deletions build_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def gem_config(conf)

conf.enable_bintest
conf.enable_debug
conf.enable_test

gem_config(conf)
end
Expand All @@ -28,8 +29,6 @@ def gem_config(conf)
cc.flags << "-ldl"
end

conf.build_mrbtest_lib_only

gem_config(conf)
end

Expand All @@ -42,8 +41,6 @@ def gem_config(conf)
cc.flags << "-ldl"
end

conf.build_mrbtest_lib_only

gem_config(conf)
end

Expand All @@ -60,8 +57,6 @@ def gem_config(conf)
conf.build_target = 'x86_64-pc-linux-gnu'
conf.host_target = 'x86_64-apple-darwin14'

conf.build_mrbtest_lib_only

gem_config(conf)
end

Expand All @@ -78,8 +73,6 @@ def gem_config(conf)
conf.build_target = 'i386-pc-linux-gnu'
conf.host_target = 'i386-apple-darwin14'

conf.build_mrbtest_lib_only

gem_config(conf)
end

Expand All @@ -96,8 +89,6 @@ def gem_config(conf)
conf.build_target = 'x86_64-pc-linux-gnu'
conf.host_target = 'x86_64-w64-mingw32'

conf.build_mrbtest_lib_only

gem_config(conf)
end

Expand All @@ -114,7 +105,5 @@ def gem_config(conf)
conf.build_target = 'i686-pc-linux-gnu'
conf.host_target = 'i686-w64-mingw32'

conf.build_mrbtest_lib_only

gem_config(conf)
end
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ compile: &defaults
build: .
volumes:
- .:/home/mruby/code:rw
#- ../mruby-jvm:/home/mruby/mruby-jvm
command: rake compile
test:
<<: *defaults
Expand Down
2 changes: 1 addition & 1 deletion mrbgem.rake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ MRuby::Gem::Specification.new('mjruby') do |spec|
spec.summary = 'mjruby'
spec.bins = ['mjruby']

spec.add_dependency 'mruby-mtest', :mgem => 'mruby-mtest'
spec.add_test_dependency 'mruby-mtest', :mgem => 'mruby-mtest'
spec.add_dependency 'mruby-env', :mgem => 'mruby-env'
spec.add_dependency 'mruby-dir', :mgem => 'mruby-dir'
spec.add_dependency 'mruby-string-ext', :core => 'mruby-string-ext'
Expand Down

0 comments on commit 25c70de

Please sign in to comment.