diff --git a/Rakefile b/Rakefile index bd93b47..f134302 100644 --- a/Rakefile +++ b/Rakefile @@ -1,322 +1,113 @@ -require 'fileutils' - MRUBY_VERSION="1.2.0" -file :mruby do +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 -" - FileUtils.mv("mruby-#{MRUBY_VERSION}", "mruby") + mv "mruby-#{MRUBY_VERSION}", mruby_root end -APP_NAME=ENV["APP_NAME"] || "mruby-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" +task :mruby => mruby_root -load File.join(File.expand_path(File.dirname(__FILE__)), "mrbgem.rake") +mruby_rakefile = "#{mruby_root}/Rakefile" -current_gem = MRuby::Gem.current -app_version = MRuby::Gem.current.version -APP_VERSION = (app_version.nil? || app_version.empty?) ? "unknown" : app_version +file mruby_rakefile => mruby_root +import mruby_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 -end +test_rakefile = "tasks/test.rake" +file test_rakefile => mruby_rakefile +import test_rakefile -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 +task :app_version do + load "mrbgem.rake" - 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 + current_gem = MRuby::Gem.current + app_version = MRuby::Gem.current.version + APP_VERSION = (app_version.nil? || app_version.empty?) ? "unknown" : app_version +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 +desc "compile all the binaries" +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 -desc "run all tests" -Rake::Task['test'].clear -task :test => ['test:bintest', 'test:mtest'] - desc "cleanup" -task :clean do - sh "rake deep_clean" -end +task :clean desc "generate a release tarball" task :release => :compile do require 'tmpdir' - # since we're in the mruby/ - release_dir = "releases/v#{APP_VERSION}" - release_path = Dir.pwd + "/../#{release_dir}" + release_path = File.expand_path "releases/v#{APP_VERSION}" app_name = "#{APP_NAME}-#{APP_VERSION}" - FileUtils.mkdir_p(release_path) + mkdir_p release_path Dir.mktmpdir do |tmp_dir| - Dir.chdir(tmp_dir) do + cd tmp_dir do MRuby.each_target do |target| next if name == "host" arch = name bin = "#{build_dir}/bin/#{exefile(APP_NAME)}" - FileUtils.mkdir_p(name) - FileUtils.cp(bin, name) + mkdir_p name + cp bin, name - Dir.chdir(arch) do + cd arch do arch_release = "#{app_name}-#{arch}" - puts "Writing #{release_dir}/#{arch_release}.tgz" + puts "Writing #{release_path}/#{arch_release}.tgz" `tar czf #{release_path}/#{arch_release}.tgz *` end end - puts "Writing #{release_dir}/#{app_name}.tgz" + puts "Writing #{release_path}/#{app_name}.tgz" `tar czf #{release_path}/#{app_name}.tgz *` end end end -namespace :local do - desc "show version" - task :version do - puts "#{APP_NAME} #{APP_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 - -namespace :package do - require 'fileutils' - require 'tmpdir' - - version = APP_VERSION - release_dir = "releases/v#{version}" - package_dir = "packages/v#{version}" - release_path = Dir.pwd + "/../#{release_dir}" - package_path = Dir.pwd + "/../#{package_dir}" - FileUtils.mkdir_p(package_path) - - def check_fpm_installed? - `gem list -i fpm`.chomp == "true" - end - - def check_msi_installed? - `wixl --version` - $?.success? - end - - def check_dmg_installed? - `genisoimage --version` - $?.success? - end - - def wxs_content(version, arch) - arch_wxs = case arch - when "x86_64" - { - string: "64-bit", - program_files_folder: "ProgramFiles64Folder", - define: "" - } - else - { - string: "32-bit", - program_files_folder: "ProgramFilesFolder", - define: "" - } - end - - <<-EOF - - - - #{arch_wxs[:define]} - - - - - - - - - - - - - - - - - - - - - - - EOF - end - - def info_plist_content(version, arch) - <<-EOF - - - - - CFBundleExecutable - mruby-cli - CFBundleGetInfoString - mruby-cli #{version} #{arch} - CFBundleName - mruby-cli - CFBundleIdentifier - mruby-cli - CFBundlePackageType - APPL - CFBundleShortVersionString - #{version} - CFBundleSignature - mrbc - CFBundleInfoDictionaryVersion - 6.0 - - - EOF - end - - def osx_setup_bash_path_script - <<-EOF -#!/bin/bash -echo "export PATH=$PATH:/Applications/mruby-cli.app/Contents/MacOs" >> $HOME/.bash_profile -source $HOME/.bash_profile - EOF - end - - def log(package_dir, version, package) - puts "Writing packages #{package_dir}/#{version}/#{package}" - end - - desc "create deb package" - task :deb => [:release] do - abort("fpm is not installed. Please check your docker install.") unless check_fpm_installed? - - ["x86_64", "i686"].each do |arch| - release_tar_file = "mruby-cli-#{version}-#{arch}-pc-linux-gnu.tgz" - arch_name = (arch == "x86_64" ? "amd64" : arch) - log(package_dir, version, "mruby-cli_#{version}_#{arch_name}.deb") - `fpm -s tar -t deb -a #{arch} -n mruby-cli -v #{version} --prefix /usr/bin -p #{package_path} #{release_path}/#{release_tar_file}` - end +namespace :local do + desc "show version" + task :version do + puts "#{APP_NAME} #{APP_VERSION}" end - desc "create rpm package" - task :rpm => [:release] do - abort("fpm is not installed. Please check your docker install.") unless check_fpm_installed? - - ["x86_64", "i686"].each do |arch| - release_tar_file = "mruby-cli-#{version}-#{arch}-pc-linux-gnu.tgz" - log(package_dir, version, "mruby-cli-#{version}-1.#{arch}.rpm") - `fpm -s tar -t rpm -a #{arch} -n mruby-cli -v #{version} --prefix /usr/bin -p #{package_path} #{release_path}/#{release_tar_file}` + task :ensure_in_docker do + unless is_in_a_docker_container? then + abort 'Not running in docker, you should type "docker-compose run ".' end end +end - desc "create msi package" - task :msi => [:release] do - abort("msitools is not installed. Please check your docker install.") unless check_msi_installed? - ["x86_64", "i686"].each do |arch| - log(package_dir, version, "mruby-cli-#{version}-#{arch}.msi") - release_tar_file = "mruby-cli-#{version}-#{arch}-w64-mingw32.tgz" - Dir.mktmpdir do |dest_dir| - Dir.chdir dest_dir - `tar -zxf #{release_path}/#{release_tar_file}` - File.write("mruby-cli-#{version}-#{arch}.wxs", wxs_content(version, arch)) - `wixl -v mruby-cli-#{version}-#{arch}.wxs && mv mruby-cli-#{version}-#{arch}.msi #{package_path}` - end - end - end +Rake.application.tasks.each do |task| + next if task.name.start_with?("local:") + next if Rake::FileTask === task - desc "create dmg package" - task :dmg => [:release] do - abort("dmg tools are not installed. Please check your docker install.") unless check_dmg_installed? - ["x86_64", "i386"].each do |arch| - log(package_dir, version, "mruby-cli-#{version}-#{arch}.dmg") - release_tar_file = "mruby-cli-#{version}-#{arch}-apple-darwin14.tgz" - Dir.mktmpdir do |dest_dir| - Dir.chdir dest_dir - `tar -zxf #{release_path}/#{release_tar_file}` - FileUtils.chmod 0755, "mruby-cli" - FileUtils.mkdir_p "mruby-cli.app/Contents/MacOs" - FileUtils.mv "mruby-cli", "mruby-cli.app/Contents/MacOs" - File.write("mruby-cli.app/Contents/Info.plist", info_plist_content(version, arch)) - File.write("add-mruby-cli-to-my-path.sh", osx_setup_bash_path_script) - FileUtils.chmod 0755, "add-mruby-cli-to-my-path.sh" - `genisoimage -V mruby-cli -D -r -apple -no-pad -o #{package_path}/mruby-cli-#{version}-#{arch}.dmg #{dest_dir}` - end - end - end + task task.name => "local:ensure_in_docker" +end unless ENV["MRUBY_CLI_LOCAL"] -end +file "tasks/package.rake" => :app_version -desc "create all packages" -task :package => ["package:deb", "package:rpm", "package:msi", "package:dmg"] +import "tasks/package.rake" diff --git a/bintest/mruby-cli.rb b/bintest/mruby-cli.rb index 3286e5e..0bc8203 100644 --- a/bintest/mruby-cli.rb +++ b/bintest/mruby-cli.rb @@ -12,7 +12,19 @@ assert_true status.success?, "Process did not exit cleanly" assert_true Dir.exist?(app_name) Dir.chdir(app_name) do - (%w(.gitignore mrbgem.rake build_config.rb Rakefile Dockerfile docker-compose.yml) + ["tools/#{app_name}/#{app_name}.c", "mrblib/#{app_name}.rb", "bintest/#{app_name}.rb"]).each do |file| + %W[ + .gitignore + mrbgem.rake + build_config.rb + Rakefile + Dockerfile + docker-compose.yml + tasks/package.rake + tasks/test.rake + tools/#{app_name}/#{app_name}.c + mrblib/#{app_name}.rb + bintest/#{app_name}.rb + ].each do |file| assert_true(File.exist?(file), "Could not find #{file}") assert_include output, " create #{file}" end diff --git a/docker-compose.yml b/docker-compose.yml index 1cf6312..3269036 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,7 +14,7 @@ mtest: command: rake test:mtest clean: <<: *defaults - command: rake clean + command: rake deep_clean shell: <<: *defaults command: bash diff --git a/mrblib/mruby-cli/setup.rb b/mrblib/mruby-cli/setup.rb index af2256e..d757ae1 100644 --- a/mrblib/mruby-cli/setup.rb +++ b/mrblib/mruby-cli/setup.rb @@ -15,6 +15,10 @@ def run write_file("Dockerfile", dockerfile) write_file("docker-compose.yml", docker_compose_yml) + create_dir_p("tasks") + write_file("tasks/package.rake", package_rake) + write_file("tasks/test.rake", test_rake) + create_dir_p("tools/#{@name}") write_file("tools/#{@name}/#{@name}.c", tools) @@ -300,7 +304,7 @@ def docker_compose_yml command: rake test:mtest clean: <<: *defaults - command: rake clean + command: rake deep_clean shell: <<: *defaults command: bash @@ -311,151 +315,352 @@ def docker_compose_yml end def rakefile - < mruby_root -current_gem = MRuby::Gem.current -app_version = MRuby::Gem.current.version -APP_VERSION = (app_version.nil? || app_version.empty?) ? "unknown" : app_version +mruby_rakefile = "\#{mruby_root}/Rakefile" -desc "compile binary" -task :compile => [:all] do +file mruby_rakefile => mruby_root +import mruby_rakefile - 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 +test_rakefile = "tasks/test.rake" +file test_rakefile => mruby_rakefile +import test_rakefile -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 +task :app_version do + load "mrbgem.rake" - 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 + current_gem = MRuby::Gem.current + app_version = MRuby::Gem.current.version + APP_VERSION = (app_version.nil? || app_version.empty?) ? "unknown" : app_version +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 +desc "compile all the binaries" +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| + puts "impl strip \#{bin}" + next unless File.exist? bin + + sh "strip --strip-unneeded \#{bin}" end 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 +task :clean desc "generate a release tarball" task :release => :compile do require 'tmpdir' - # since we're in the mruby/ - release_dir = "releases/v\#{APP_VERSION}" - release_path = Dir.pwd + "/../\#{release_dir}" + release_path = File.expand_path "releases/v\#{APP_VERSION}" app_name = "\#{APP_NAME}-\#{APP_VERSION}" - FileUtils.mkdir_p(release_path) + mkdir_p release_path Dir.mktmpdir do |tmp_dir| - Dir.chdir(tmp_dir) do + cd tmp_dir do MRuby.each_target do |target| next if name == "host" arch = name bin = "\#{build_dir}/bin/\#{exefile(APP_NAME)}" - FileUtils.mkdir_p(name) - FileUtils.cp(bin, name) + mkdir_p name + cp bin, name - Dir.chdir(arch) do + cd arch do arch_release = "\#{app_name}-\#{arch}" - puts "Writing \#{release_dir}/\#{arch_release}.tgz" + puts "Writing \#{release_path}/\#{arch_release}.tgz" `tar czf \#{release_path}/\#{arch_release}.tgz *` end end - puts "Writing \#{release_dir}/\#{app_name}.tgz" + 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 -end -def is_in_a_docker_container? - `grep -q docker /proc/self/cgroup` - $?.success? + task :ensure_in_docker do + unless is_in_a_docker_container? then + abort 'Not running in docker, you should type "docker-compose run ".' + end + end 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 + 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" + RAKEFILE + end + + def package_rake + <<-'RAKEFILE' +require 'tmpdir' + +desc "create all packages" +task :package => ["package:deb", "package:rpm", "package:msi", "package:dmg"] + +namespace :package do + release_path = File.expand_path "releases/v#{APP_VERSION}" + package_path = File.expand_path "packages/v#{APP_VERSION}" + + directory package_path + + def check_fpm_installed? + `gem list -i fpm`.chomp == "true" + end + + def check_msi_installed? + `wixl --version` + $?.success? + end + + def check_dmg_installed? + `genisoimage --version` + $?.success? + end + + def wxs_content(version, arch) + arch_wxs = case arch + when "x86_64" + { + string: "64-bit", + program_files_folder: "ProgramFiles64Folder", + define: "" + } + else + { + string: "32-bit", + program_files_folder: "ProgramFilesFolder", + define: "" + } + end + + <<-EOF + + + + #{arch_wxs[:define]} + + + + + + + + + + + + + + + + + + + + + + + EOF + end + + def info_plist_content(version, arch) + <<-EOF + + + + + CFBundleExecutable + mruby-cli + CFBundleGetInfoString + mruby-cli #{version} #{arch} + CFBundleName + mruby-cli + CFBundleIdentifier + mruby-cli + CFBundlePackageType + APPL + CFBundleShortVersionString + #{version} + CFBundleSignature + mrbc + CFBundleInfoDictionaryVersion + 6.0 + + + EOF + end + + def osx_setup_bash_path_script + <<-EOF +#!/bin/bash +echo "export PATH=$PATH:/Applications/mruby-cli.app/Contents/MacOs" >> $HOME/.bash_profile +source $HOME/.bash_profile + EOF + end + + def log(dir, version, package) + puts "Writing packages #{dir}/#{version}/#{package}" + end + + desc "create deb package" + task :deb => [package_path, :release] do + abort("fpm is not installed. Please check your docker install.") unless check_fpm_installed? + + ["x86_64", "i686"].each do |arch| + release_tar_file = "mruby-cli-#{APP_VERSION}-#{arch}-pc-linux-gnu.tgz" + arch_name = (arch == "x86_64" ? "amd64" : arch) + log(package_path, APP_VERSION, "mruby-cli_#{APP_VERSION}_#{arch_name}.deb") + `fpm -s tar -t deb -a #{arch} -n mruby-cli -v #{APP_VERSION} --prefix /usr/bin -p #{package_path} #{release_path}/#{release_tar_file}` + end + end + + desc "create rpm package" + task :rpm => [package_path, :release] do + abort("fpm is not installed. Please check your docker install.") unless check_fpm_installed? + + ["x86_64", "i686"].each do |arch| + release_tar_file = "mruby-cli-#{APP_VERSION}-#{arch}-pc-linux-gnu.tgz" + log(package_path, APP_VERSION, "mruby-cli-#{APP_VERSION}-1.#{arch}.rpm") + `fpm -s tar -t rpm -a #{arch} -n mruby-cli -v #{APP_VERSION} --prefix /usr/bin -p #{package_path} #{release_path}/#{release_tar_file}` + end + end + + desc "create msi package" + task :msi => [package_path, :release] do + abort("msitools is not installed. Please check your docker install.") unless check_msi_installed? + ["x86_64", "i686"].each do |arch| + log(package_path, APP_VERSION, "mruby-cli-#{APP_VERSION}-#{arch}.msi") + release_tar_file = "mruby-cli-#{APP_VERSION}-#{arch}-w64-mingw32.tgz" + Dir.mktmpdir do |dest_dir| + cd dest_dir + `tar -zxf #{release_path}/#{release_tar_file}` + File.write("mruby-cli-#{APP_VERSION}-#{arch}.wxs", wxs_content(APP_VERSION, arch)) + `wixl -v mruby-cli-#{APP_VERSION}-#{arch}.wxs && mv mruby-cli-#{APP_VERSION}-#{arch}.msi #{package_path}` + end + end + end + + desc "create dmg package" + task :dmg => [package_path, :release] do + abort("dmg tools are not installed. Please check your docker install.") unless check_dmg_installed? + ["x86_64", "i386"].each do |arch| + log(package_path, APP_VERSION, "mruby-cli-#{APP_VERSION}-#{arch}.dmg") + release_tar_file = "mruby-cli-#{APP_VERSION}-#{arch}-apple-darwin14.tgz" + Dir.mktmpdir do |dest_dir| + cd dest_dir + `tar -zxf #{release_path}/#{release_tar_file}` + chmod 0755, "mruby-cli" + mkdir_p "mruby-cli.app/Contents/MacOs" + mv "mruby-cli", "mruby-cli.app/Contents/MacOs" + File.write("mruby-cli.app/Contents/Info.plist", info_plist_content(APP_VERSION, arch)) + File.write("add-mruby-cli-to-my-path.sh", osx_setup_bash_path_script) + chmod 0755, "add-mruby-cli-to-my-path.sh" + `genisoimage -V mruby-cli -D -r -apple -no-pad -o #{package_path}/mruby-cli-#{APP_VERSION}-#{arch}.dmg #{dest_dir}` + end end end end -RAKEFILE + RAKEFILE + end + + def test_rake + <<-'RAKEFILE' +# Remove default test task actions from MRuby's Rakefile +Rake::Task['test'].clear + +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 + cd MRUBY_ROOT do + MRuby.each_target do |target| + # only run unit tests here + target.enable_bintest = false + run_test if target.test_enabled? + end + 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 + cd MRUBY_ROOT do + MRuby.each_target do |target| + clean_env(%w(MRUBY_ROOT MRUBY_CONFIG)) do + run_bintest if target.bintest_enabled? + end + end + end + end +end + +desc "run all tests" +task :test => ['test:bintest', 'test:mtest'] + RAKEFILE + end end end diff --git a/tasks/package.rake b/tasks/package.rake new file mode 100644 index 0000000..5839b7a --- /dev/null +++ b/tasks/package.rake @@ -0,0 +1,177 @@ +require 'tmpdir' + +desc "create all packages" +task :package => ["package:deb", "package:rpm", "package:msi", "package:dmg"] + +namespace :package do + release_path = File.expand_path "releases/v#{APP_VERSION}" + package_path = File.expand_path "packages/v#{APP_VERSION}" + + directory package_path + + def check_fpm_installed? + `gem list -i fpm`.chomp == "true" + end + + def check_msi_installed? + `wixl --version` + $?.success? + end + + def check_dmg_installed? + `genisoimage --version` + $?.success? + end + + def wxs_content(version, arch) + arch_wxs = case arch + when "x86_64" + { + string: "64-bit", + program_files_folder: "ProgramFiles64Folder", + define: "" + } + else + { + string: "32-bit", + program_files_folder: "ProgramFilesFolder", + define: "" + } + end + + <<-EOF + + + + #{arch_wxs[:define]} + + + + + + + + + + + + + + + + + + + + + + + EOF + end + + def info_plist_content(version, arch) + <<-EOF + + + + + CFBundleExecutable + mruby-cli + CFBundleGetInfoString + mruby-cli #{version} #{arch} + CFBundleName + mruby-cli + CFBundleIdentifier + mruby-cli + CFBundlePackageType + APPL + CFBundleShortVersionString + #{version} + CFBundleSignature + mrbc + CFBundleInfoDictionaryVersion + 6.0 + + + EOF + end + + def osx_setup_bash_path_script + <<-EOF +#!/bin/bash +echo "export PATH=$PATH:/Applications/mruby-cli.app/Contents/MacOs" >> $HOME/.bash_profile +source $HOME/.bash_profile + EOF + end + + def log(dir, version, package) + puts "Writing packages #{dir}/#{version}/#{package}" + end + + desc "create deb package" + task :deb => [package_path, :release] do + abort("fpm is not installed. Please check your docker install.") unless check_fpm_installed? + + ["x86_64", "i686"].each do |arch| + release_tar_file = "mruby-cli-#{APP_VERSION}-#{arch}-pc-linux-gnu.tgz" + arch_name = (arch == "x86_64" ? "amd64" : arch) + log(package_path, APP_VERSION, "mruby-cli_#{APP_VERSION}_#{arch_name}.deb") + `fpm -s tar -t deb -a #{arch} -n mruby-cli -v #{APP_VERSION} --prefix /usr/bin -p #{package_path} #{release_path}/#{release_tar_file}` + end + end + + desc "create rpm package" + task :rpm => [package_path, :release] do + abort("fpm is not installed. Please check your docker install.") unless check_fpm_installed? + + ["x86_64", "i686"].each do |arch| + release_tar_file = "mruby-cli-#{APP_VERSION}-#{arch}-pc-linux-gnu.tgz" + log(package_path, APP_VERSION, "mruby-cli-#{APP_VERSION}-1.#{arch}.rpm") + `fpm -s tar -t rpm -a #{arch} -n mruby-cli -v #{APP_VERSION} --prefix /usr/bin -p #{package_path} #{release_path}/#{release_tar_file}` + end + end + + desc "create msi package" + task :msi => [package_path, :release] do + abort("msitools is not installed. Please check your docker install.") unless check_msi_installed? + ["x86_64", "i686"].each do |arch| + log(package_path, APP_VERSION, "mruby-cli-#{APP_VERSION}-#{arch}.msi") + release_tar_file = "mruby-cli-#{APP_VERSION}-#{arch}-w64-mingw32.tgz" + Dir.mktmpdir do |dest_dir| + cd dest_dir + `tar -zxf #{release_path}/#{release_tar_file}` + File.write("mruby-cli-#{APP_VERSION}-#{arch}.wxs", wxs_content(APP_VERSION, arch)) + `wixl -v mruby-cli-#{APP_VERSION}-#{arch}.wxs && mv mruby-cli-#{APP_VERSION}-#{arch}.msi #{package_path}` + end + end + end + + desc "create dmg package" + task :dmg => [package_path, :release] do + abort("dmg tools are not installed. Please check your docker install.") unless check_dmg_installed? + ["x86_64", "i386"].each do |arch| + log(package_path, APP_VERSION, "mruby-cli-#{APP_VERSION}-#{arch}.dmg") + release_tar_file = "mruby-cli-#{APP_VERSION}-#{arch}-apple-darwin14.tgz" + Dir.mktmpdir do |dest_dir| + cd dest_dir + `tar -zxf #{release_path}/#{release_tar_file}` + chmod 0755, "mruby-cli" + mkdir_p "mruby-cli.app/Contents/MacOs" + mv "mruby-cli", "mruby-cli.app/Contents/MacOs" + File.write("mruby-cli.app/Contents/Info.plist", info_plist_content(APP_VERSION, arch)) + File.write("add-mruby-cli-to-my-path.sh", osx_setup_bash_path_script) + chmod 0755, "add-mruby-cli-to-my-path.sh" + `genisoimage -V mruby-cli -D -r -apple -no-pad -o #{package_path}/mruby-cli-#{APP_VERSION}-#{arch}.dmg #{dest_dir}` + end + end + end + +end + diff --git a/tasks/test.rake b/tasks/test.rake new file mode 100644 index 0000000..e584242 --- /dev/null +++ b/tasks/test.rake @@ -0,0 +1,45 @@ +# Remove default test task actions from MRuby's Rakefile +Rake::Task['test'].clear + +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 + cd MRUBY_ROOT do + MRuby.each_target do |target| + # only run unit tests here + target.enable_bintest = false + run_test if target.test_enabled? + end + 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 + cd MRUBY_ROOT do + MRuby.each_target do |target| + clean_env(%w(MRUBY_ROOT MRUBY_CONFIG)) do + run_bintest if target.bintest_enabled? + end + end + end + end +end + +desc "run all tests" +task :test => ['test:bintest', 'test:mtest'] +