From 306380db8bd583af19fd6967c7eb3e27a925aa9c Mon Sep 17 00:00:00 2001 From: Eric Hodel Date: Tue, 10 May 2016 10:20:53 -0700 Subject: [PATCH 01/17] Rake includes FileUtils at top-level for us Also, remove () to be consistent across uses of FileUtils methods --- Rakefile | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Rakefile b/Rakefile index bd93b47..dd11a44 100644 --- a/Rakefile +++ b/Rakefile @@ -1,11 +1,9 @@ -require 'fileutils' - MRUBY_VERSION="1.2.0" file :mruby 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" end APP_NAME=ENV["APP_NAME"] || "mruby-cli" @@ -88,7 +86,7 @@ task :release => :compile do release_dir = "releases/v#{APP_VERSION}" release_path = Dir.pwd + "/../#{release_dir}" 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 @@ -97,8 +95,8 @@ task :release => :compile do 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 arch_release = "#{app_name}-#{arch}" @@ -149,7 +147,7 @@ namespace :package do package_dir = "packages/v#{version}" release_path = Dir.pwd + "/../#{release_dir}" package_path = Dir.pwd + "/../#{package_dir}" - FileUtils.mkdir_p(package_path) + mkdir_p(package_path) def check_fpm_installed? `gem list -i fpm`.chomp == "true" @@ -304,12 +302,12 @@ source $HOME/.bash_profile 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" + 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(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" + 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 From fdfcb2762b279b5537588585f61004f87d7fc1c3 Mon Sep 17 00:00:00 2001 From: Eric Hodel Date: Tue, 10 May 2016 10:21:53 -0700 Subject: [PATCH 02/17] Use cd from Rake instead of Dir.chdir --- Rakefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Rakefile b/Rakefile index dd11a44..1ace05f 100644 --- a/Rakefile +++ b/Rakefile @@ -14,7 +14,7 @@ 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) +cd mruby_root load "#{mruby_root}/Rakefile" load File.join(File.expand_path(File.dirname(__FILE__)), "mrbgem.rake") @@ -89,7 +89,7 @@ task :release => :compile do 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" @@ -98,7 +98,7 @@ task :release => :compile do 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" `tar czf #{release_path}/#{arch_release}.tgz *` @@ -285,7 +285,7 @@ source $HOME/.bash_profile 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 + cd 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}` @@ -300,7 +300,7 @@ source $HOME/.bash_profile 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 + cd dest_dir `tar -zxf #{release_path}/#{release_tar_file}` chmod 0755, "mruby-cli" mkdir_p "mruby-cli.app/Contents/MacOs" From 903b920047647e4bd91a00b9c557a7cb16cfcd48 Mon Sep 17 00:00:00 2001 From: Eric Hodel Date: Tue, 10 May 2016 10:28:50 -0700 Subject: [PATCH 03/17] Extract expand_and_set method This makes it more clear what the commend means --- Rakefile | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Rakefile b/Rakefile index 1ace05f..77c3c41 100644 --- a/Rakefile +++ b/Rakefile @@ -8,11 +8,19 @@ end APP_NAME=ENV["APP_NAME"] || "mruby-cli" APP_ROOT=ENV["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=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 +mruby_root = expand_and_set "MRUBY_ROOT", "#{APP_ROOT}/mruby" +mruby_config = expand_and_set "MRUBY_CONFIG", "build_config.rb" + Rake::Task[:mruby].invoke unless Dir.exist?(mruby_root) cd mruby_root load "#{mruby_root}/Rakefile" From 5e5a3b97824ed4ca0995de31045e38a7a29ac0ea Mon Sep 17 00:00:00 2001 From: Eric Hodel Date: Tue, 10 May 2016 10:29:43 -0700 Subject: [PATCH 04/17] Use ENV.fetch with default value over || --- Rakefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Rakefile b/Rakefile index 77c3c41..b63ed0f 100644 --- a/Rakefile +++ b/Rakefile @@ -6,8 +6,8 @@ file :mruby do mv "mruby-#{MRUBY_VERSION}", "mruby" end -APP_NAME=ENV["APP_NAME"] || "mruby-cli" -APP_ROOT=ENV["APP_ROOT"] || Dir.pwd +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 From fcaa5c25bbad167416bde250715821f4621c7b0f Mon Sep 17 00:00:00 2001 From: Eric Hodel Date: Tue, 10 May 2016 10:39:39 -0700 Subject: [PATCH 05/17] Use mruby_root for directory task I think that previously the Rakefile would always create mruby_root as "mruby" regardless of what was in the MRUBY_ROOT environment variable. Now the correct directory will be created. A `mruby` task is retained for compatibility. --- Rakefile | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Rakefile b/Rakefile index b63ed0f..07be6f8 100644 --- a/Rakefile +++ b/Rakefile @@ -1,11 +1,5 @@ MRUBY_VERSION="1.2.0" -file :mruby 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" -end - APP_NAME = ENV.fetch "APP_NAME", "mruby-cli" APP_ROOT = ENV.fetch "APP_ROOT", Dir.pwd @@ -21,6 +15,14 @@ end 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 + Rake::Task[:mruby].invoke unless Dir.exist?(mruby_root) cd mruby_root load "#{mruby_root}/Rakefile" From f7961c6132b17b6627320478be3c39e70cc9e73b Mon Sep 17 00:00:00 2001 From: Eric Hodel Date: Tue, 10 May 2016 11:08:38 -0700 Subject: [PATCH 06/17] Extract package tasks to tasks/package.rake --- Rakefile | 181 +-------------------------------------------- tasks/package.rake | 178 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 180 insertions(+), 179 deletions(-) create mode 100644 tasks/package.rake diff --git a/Rakefile b/Rakefile index 07be6f8..5f2ce28 100644 --- a/Rakefile +++ b/Rakefile @@ -148,183 +148,6 @@ Rake.application.tasks.each do |task| 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}" - 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 - 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}` - 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| - cd 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 - - 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| - 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(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-#{version}-#{arch}.dmg #{dest_dir}` - end - end - end - -end - -desc "create all packages" -task :package => ["package:deb", "package:rpm", "package:msi", "package:dmg"] +file "../tasks/package.rake" +import "../tasks/package.rake" diff --git a/tasks/package.rake b/tasks/package.rake new file mode 100644 index 0000000..968113b --- /dev/null +++ b/tasks/package.rake @@ -0,0 +1,178 @@ +require 'tmpdir' + +desc "create all packages" +task :package => ["package:deb", "package:rpm", "package:msi", "package:dmg"] + +namespace :package do + release_dir = "releases/v#{APP_VERSION}" + package_dir = "packages/v#{APP_VERSION}" + release_path = Dir.pwd + "/../#{release_dir}" + package_path = Dir.pwd + "/../#{package_dir}" + 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-#{APP_VERSION}-#{arch}-pc-linux-gnu.tgz" + arch_name = (arch == "x86_64" ? "amd64" : arch) + log(package_dir, 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 => [: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_dir, 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 => [: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, 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 => [: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, 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 + From f64e50a4d8b8697433a262a08bbaa17bed89a5d5 Mon Sep 17 00:00:00 2001 From: Eric Hodel Date: Tue, 10 May 2016 11:10:00 -0700 Subject: [PATCH 07/17] Make task to set APP_VERSION This moves us a step closer to not having `cd mruby_root` polluting the package tasks and allows us to make loading mruby use `import` as Jim Weirich intended. --- Rakefile | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Rakefile b/Rakefile index 5f2ce28..c86f2dc 100644 --- a/Rakefile +++ b/Rakefile @@ -29,9 +29,11 @@ load "#{mruby_root}/Rakefile" load File.join(File.expand_path(File.dirname(__FILE__)), "mrbgem.rake") -current_gem = MRuby::Gem.current -app_version = MRuby::Gem.current.version -APP_VERSION = (app_version.nil? || app_version.empty?) ? "unknown" : app_version +task :app_version do + 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 @@ -148,6 +150,6 @@ Rake.application.tasks.each do |task| end end -file "../tasks/package.rake" +file "../tasks/package.rake" => :app_version import "../tasks/package.rake" From 1683e022206babf45cdb9034c6a24496e8ff4a70 Mon Sep 17 00:00:00 2001 From: Eric Hodel Date: Tue, 10 May 2016 14:14:03 -0700 Subject: [PATCH 08/17] Use dependencies for checking for Docker If we rewrite the task Bad Things happen (like a Rake::FileTask turning into a Rake::Task). Instead we can use a dependency because that runs before anything the task does that would require Docker. PS: rake-hooks is a pointless library. Rake already has a way to run things before a task, a prerequisite. Rake already has a way to run things after a task, make the after-task have the before-task a prerequisite. With some organization of tasks the before/after isn't an issue, it just falls out with how you hook up your dependencies. --- Rakefile | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/Rakefile b/Rakefile index c86f2dc..7722f5c 100644 --- a/Rakefile +++ b/Rakefile @@ -123,33 +123,31 @@ task :release => :compile do 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? -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 + 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 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" From 42b79cf7837e211f4a6912575804e8c545da21fb Mon Sep 17 00:00:00 2001 From: Eric Hodel Date: Tue, 10 May 2016 15:00:04 -0700 Subject: [PATCH 09/17] Use #import (as Jim Weirich intended) Rake has the #import method to safely import Rakefiles into the current rake application. Using load or require may cause rakefiles to appear in the wrong place or require cumbersome setup. In this case the cumbersome setup was the `cd "mruby"` that required adjustment for the correct path in the release and package tasks. --- Rakefile | 30 ++++++++++++++++-------------- tasks/package.rake | 9 ++++----- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/Rakefile b/Rakefile index 7722f5c..a165bed 100644 --- a/Rakefile +++ b/Rakefile @@ -23,13 +23,14 @@ end task :mruby => mruby_root -Rake::Task[:mruby].invoke unless Dir.exist?(mruby_root) -cd mruby_root -load "#{mruby_root}/Rakefile" +mruby_rakefile = "#{mruby_root}/Rakefile" +file mruby_rakefile => mruby_root -load File.join(File.expand_path(File.dirname(__FILE__)), "mrbgem.rake") +import mruby_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 @@ -73,9 +74,11 @@ namespace :test do 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? + 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 @@ -94,9 +97,7 @@ 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}" mkdir_p release_path @@ -112,12 +113,12 @@ task :release => :compile 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 @@ -148,6 +149,7 @@ Rake.application.tasks.each do |task| task task.name => "local:ensure_in_docker" end unless ENV["MRUBY_CLI_LOCAL"] -file "../tasks/package.rake" => :app_version +file "tasks/package.rake" => :app_version + +import "tasks/package.rake" -import "../tasks/package.rake" diff --git a/tasks/package.rake b/tasks/package.rake index 968113b..38f9025 100644 --- a/tasks/package.rake +++ b/tasks/package.rake @@ -4,11 +4,10 @@ desc "create all packages" task :package => ["package:deb", "package:rpm", "package:msi", "package:dmg"] namespace :package do - release_dir = "releases/v#{APP_VERSION}" - package_dir = "packages/v#{APP_VERSION}" - release_path = Dir.pwd + "/../#{release_dir}" - package_path = Dir.pwd + "/../#{package_dir}" - mkdir_p(package_path) + release_path = File.expand_path "releases/v#{APP_VERSION}" + package_path = File.expand_path "packages/v#{APP_VERSION}" + + mkdir_p package_path def check_fpm_installed? `gem list -i fpm`.chomp == "true" From 5733c0595159fe25c8c313c3dafc4b6b1080a26b Mon Sep 17 00:00:00 2001 From: Eric Hodel Date: Tue, 10 May 2016 15:38:13 -0700 Subject: [PATCH 10/17] Make directory inside (or via) tasks Otherwise we're making directories when they're not needed. --- tasks/package.rake | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tasks/package.rake b/tasks/package.rake index 38f9025..ef28f36 100644 --- a/tasks/package.rake +++ b/tasks/package.rake @@ -7,7 +7,7 @@ namespace :package do release_path = File.expand_path "releases/v#{APP_VERSION}" package_path = File.expand_path "packages/v#{APP_VERSION}" - mkdir_p package_path + directory package_path def check_fpm_installed? `gem list -i fpm`.chomp == "true" @@ -116,7 +116,7 @@ source $HOME/.bash_profile end desc "create deb package" - task :deb => [:release] do + 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| @@ -128,7 +128,7 @@ source $HOME/.bash_profile end desc "create rpm package" - task :rpm => [:release] do + 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| @@ -139,7 +139,7 @@ source $HOME/.bash_profile end desc "create msi package" - task :msi => [:release] do + 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_dir, APP_VERSION, "mruby-cli-#{APP_VERSION}-#{arch}.msi") @@ -154,7 +154,7 @@ source $HOME/.bash_profile end desc "create dmg package" - task :dmg => [:release] do + 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_dir, APP_VERSION, "mruby-cli-#{APP_VERSION}-#{arch}.dmg") From a20c617316901c86368a2a4f1870180778d0c09d Mon Sep 17 00:00:00 2001 From: Eric Hodel Date: Tue, 10 May 2016 16:20:02 -0700 Subject: [PATCH 11/17] Run tests from mruby_root Missed this one --- Rakefile | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Rakefile b/Rakefile index a165bed..47473cd 100644 --- a/Rakefile +++ b/Rakefile @@ -53,10 +53,12 @@ namespace :test do 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? + 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 From 0472ccb01b9bc96bf65518d1643f78677f84d8e7 Mon Sep 17 00:00:00 2001 From: Eric Hodel Date: Thu, 12 May 2016 11:20:19 -0700 Subject: [PATCH 12/17] Move test tasks to test.rake to fix dependencies The test task depends upon clearing MRuby's test task but we can't do that until after MRuby's Rakefile loads. Moving the test tasks to a separate file we import allows us to clear MRuby's test actions at the proper time. --- Rakefile | 49 +++++-------------------------------------------- tasks/test.rake | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 44 deletions(-) create mode 100644 tasks/test.rake diff --git a/Rakefile b/Rakefile index 47473cd..7c55ddb 100644 --- a/Rakefile +++ b/Rakefile @@ -24,10 +24,14 @@ end task :mruby => mruby_root mruby_rakefile = "#{mruby_root}/Rakefile" -file mruby_rakefile => mruby_root +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" @@ -47,49 +51,6 @@ task :compile => [:all] do end end -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" -Rake::Task['test'].clear -task :test => ['test:bintest', 'test:mtest'] - desc "cleanup" task :clean do sh "rake deep_clean" 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'] + From e7b50028d25963c57e0317afcec37f65a32219d9 Mon Sep 17 00:00:00 2001 From: Eric Hodel Date: Fri, 17 Jun 2016 15:18:23 -0700 Subject: [PATCH 13/17] Update setup.rb to use updated Rakefile, etc Also wrapped some lines at 80 columns to improve readability. --- Rakefile | 5 +- bintest/mruby-cli.rb | 14 +- mrblib/mruby-cli/setup.rb | 386 +++++++++++++++++++++++++++++--------- 3 files changed, 315 insertions(+), 90 deletions(-) diff --git a/Rakefile b/Rakefile index 7c55ddb..36aafc7 100644 --- a/Rakefile +++ b/Rakefile @@ -46,7 +46,8 @@ task :compile => [:all] do `#{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| + %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 @@ -100,7 +101,7 @@ namespace :local do task :ensure_in_docker do unless is_in_a_docker_container? then - abort "Not running in docker, you should type \"docker-compose run \"." + abort 'Not running in docker, you should type "docker-compose run ".' end end end 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/mrblib/mruby-cli/setup.rb b/mrblib/mruby-cli/setup.rb index af2256e..fd551a3 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) @@ -311,86 +315,65 @@ def docker_compose_yml end def rakefile - < 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 binary" -task :compile => [:all] do +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| + puts "checking \#{target.cc.command}" `\#{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 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 - - 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 + %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 - 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 + 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" @@ -400,62 +383,291 @@ def clean_env(envs) 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(package_dir, version, package) + puts "Writing packages #{package_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_dir, 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_dir, 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_dir, 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_dir, 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 From c6adb30dcca4ef8c87a2b87201e2924e14f72bdd Mon Sep 17 00:00:00 2001 From: Eric Hodel Date: Fri, 17 Jun 2016 15:25:33 -0700 Subject: [PATCH 14/17] Remove too-late compiler check This check's dependency is :all which runs the compilers so it can never check what it needs to. Unfortunately there's no place we can move this compiler check so that it will work. Having `task all: :compiler_check` won't work either because the all task depends on the .o files which run the compiler check. I haven't found any tasks in mruby that we can hook into to run such checks. I looked extensively to find a place to hook-in for cross-compiling third party libraries (like libcurl) and such a hook doesn't exist. In order to restore this functionality mruby-cli must not import mruby's Rakefile. Then we can have tasks that run before mruby is built (like cross-compiling libraries or checking the cross-compiler environment). --- Rakefile | 4 ---- mrblib/mruby-cli/setup.rb | 5 ----- 2 files changed, 9 deletions(-) diff --git a/Rakefile b/Rakefile index 36aafc7..3616bdc 100644 --- a/Rakefile +++ b/Rakefile @@ -42,10 +42,6 @@ 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) diff --git a/mrblib/mruby-cli/setup.rb b/mrblib/mruby-cli/setup.rb index fd551a3..3879a66 100644 --- a/mrblib/mruby-cli/setup.rb +++ b/mrblib/mruby-cli/setup.rb @@ -360,11 +360,6 @@ def expand_and_set(env_name, default) desc "compile all the binaries" task :compile => [:all] do - MRuby.each_target do |target| - puts "checking \#{target.cc.command}" - `\#{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| puts "impl strip \#{bin}" From b6404e4d66e410c36ce0cb951afb0776b6dac2e9 Mon Sep 17 00:00:00 2001 From: Eric Hodel Date: Tue, 20 Sep 2016 21:41:45 -0700 Subject: [PATCH 15/17] Remove infinite loop in clean task Previously we had a task rewriter that made sure certain tasks were run in docker that prevented this infinite loop by accident. After removing the task rewriter the dependencies were circular (through #sh) and things could run forever. (Note that the `clean` task didn't change prior to this commit.) Rather than trying to unravel this infinite loop let's run `deep_clean` directly via docker and let it do all the right things. The `clean` task remains for documentation purposes. MRuby already defines it for us, but now our users will know to hook into it. --- Rakefile | 4 +--- docker-compose.yml | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Rakefile b/Rakefile index 3616bdc..f134302 100644 --- a/Rakefile +++ b/Rakefile @@ -49,9 +49,7 @@ task :compile => [:all] do end desc "cleanup" -task :clean do - sh "rake deep_clean" -end +task :clean desc "generate a release tarball" task :release => :compile do 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 From 8515eaffac690c9b8de5ffb0ab37764f1174f065 Mon Sep 17 00:00:00 2001 From: Eric Hodel Date: Tue, 20 Sep 2016 21:51:23 -0700 Subject: [PATCH 16/17] Fix broken rename of `package_dir` --- tasks/package.rake | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tasks/package.rake b/tasks/package.rake index ef28f36..5839b7a 100644 --- a/tasks/package.rake +++ b/tasks/package.rake @@ -111,8 +111,8 @@ source $HOME/.bash_profile EOF end - def log(package_dir, version, package) - puts "Writing packages #{package_dir}/#{version}/#{package}" + def log(dir, version, package) + puts "Writing packages #{dir}/#{version}/#{package}" end desc "create deb package" @@ -122,7 +122,7 @@ source $HOME/.bash_profile ["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_dir, APP_VERSION, "mruby-cli_#{APP_VERSION}_#{arch_name}.deb") + 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 @@ -133,7 +133,7 @@ source $HOME/.bash_profile ["x86_64", "i686"].each do |arch| release_tar_file = "mruby-cli-#{APP_VERSION}-#{arch}-pc-linux-gnu.tgz" - log(package_dir, APP_VERSION, "mruby-cli-#{APP_VERSION}-1.#{arch}.rpm") + 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 @@ -142,7 +142,7 @@ source $HOME/.bash_profile 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_dir, APP_VERSION, "mruby-cli-#{APP_VERSION}-#{arch}.msi") + 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 @@ -157,7 +157,7 @@ source $HOME/.bash_profile 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_dir, APP_VERSION, "mruby-cli-#{APP_VERSION}-#{arch}.dmg") + 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 From 038da05493388972e575a1de86b31c0ed826d6d2 Mon Sep 17 00:00:00 2001 From: Eric Hodel Date: Tue, 20 Sep 2016 21:52:56 -0700 Subject: [PATCH 17/17] Update setup.rb with build system changes --- mrblib/mruby-cli/setup.rb | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/mrblib/mruby-cli/setup.rb b/mrblib/mruby-cli/setup.rb index 3879a66..d757ae1 100644 --- a/mrblib/mruby-cli/setup.rb +++ b/mrblib/mruby-cli/setup.rb @@ -304,7 +304,7 @@ def docker_compose_yml command: rake test:mtest clean: <<: *defaults - command: rake clean + command: rake deep_clean shell: <<: *defaults command: bash @@ -370,9 +370,7 @@ def expand_and_set(env_name, default) end desc "cleanup" -task :clean do - sh "rake deep_clean" -end +task :clean desc "generate a release tarball" task :release => :compile do @@ -551,8 +549,8 @@ def osx_setup_bash_path_script EOF end - def log(package_dir, version, package) - puts "Writing packages #{package_dir}/#{version}/#{package}" + def log(dir, version, package) + puts "Writing packages #{dir}/#{version}/#{package}" end desc "create deb package" @@ -562,7 +560,7 @@ def log(package_dir, version, package) ["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_dir, APP_VERSION, "mruby-cli_#{APP_VERSION}_#{arch_name}.deb") + 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 @@ -573,7 +571,7 @@ def log(package_dir, version, package) ["x86_64", "i686"].each do |arch| release_tar_file = "mruby-cli-#{APP_VERSION}-#{arch}-pc-linux-gnu.tgz" - log(package_dir, APP_VERSION, "mruby-cli-#{APP_VERSION}-1.#{arch}.rpm") + 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 @@ -582,7 +580,7 @@ def log(package_dir, version, 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_dir, APP_VERSION, "mruby-cli-#{APP_VERSION}-#{arch}.msi") + 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 @@ -597,7 +595,7 @@ def log(package_dir, version, 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_dir, APP_VERSION, "mruby-cli-#{APP_VERSION}-#{arch}.dmg") + 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