From 25c70de066cb5815003a605e180cecb4fcfea35f Mon Sep 17 00:00:00 2001 From: Joe Kutner Date: Wed, 2 Dec 2015 16:43:29 -0600 Subject: [PATCH] Upgrade to mruby-cli 0.0.4 --- Rakefile | 68 ++++++++++++++++++++++++++++++++++------------ build_config.rb | 13 +-------- docker-compose.yml | 1 + mrbgem.rake | 2 +- 4 files changed, 54 insertions(+), 30 deletions(-) diff --git a/Rakefile b/Rakefile index 1092773..fee91d6 100644 --- a/Rakefile +++ b/Rakefile @@ -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") @@ -14,8 +20,13 @@ 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 @@ -23,17 +34,13 @@ 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 @@ -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 @@ -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 \".") unless is_in_a_docker_container? + old_task.invoke + end + end end diff --git a/build_config.rb b/build_config.rb index 77f6b9d..e9d1569 100644 --- a/build_config.rb +++ b/build_config.rb @@ -16,6 +16,7 @@ def gem_config(conf) conf.enable_bintest conf.enable_debug + conf.enable_test gem_config(conf) end @@ -28,8 +29,6 @@ def gem_config(conf) cc.flags << "-ldl" end - conf.build_mrbtest_lib_only - gem_config(conf) end @@ -42,8 +41,6 @@ def gem_config(conf) cc.flags << "-ldl" end - conf.build_mrbtest_lib_only - gem_config(conf) end @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml index 6cb08fc..db28e70 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,6 +2,7 @@ compile: &defaults build: . volumes: - .:/home/mruby/code:rw + #- ../mruby-jvm:/home/mruby/mruby-jvm command: rake compile test: <<: *defaults diff --git a/mrbgem.rake b/mrbgem.rake index d891741..3d07f31 100644 --- a/mrbgem.rake +++ b/mrbgem.rake @@ -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'