-
Notifications
You must be signed in to change notification settings - Fork 28
Rakeify rake tasks #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
drbrain
wants to merge
17
commits into
hone:master
Choose a base branch
from
drbrain:drbrain/rakeify
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
306380d
Rake includes FileUtils at top-level for us
drbrain fdfcb27
Use cd from Rake instead of Dir.chdir
drbrain 903b920
Extract expand_and_set method
drbrain 5e5a3b9
Use ENV.fetch with default value over ||
drbrain fcaa5c2
Use mruby_root for directory task
drbrain f7961c6
Extract package tasks to tasks/package.rake
drbrain f64e50a
Make task to set APP_VERSION
drbrain 1683e02
Use dependencies for checking for Docker
drbrain 42b79cf
Use #import (as Jim Weirich intended)
drbrain 5733c05
Make directory inside (or via) tasks
drbrain a20c617
Run tests from mruby_root
drbrain 0472ccb
Move test tasks to test.rake to fix dependencies
drbrain e7b5002
Update setup.rb to use updated Rakefile, etc
drbrain c6adb30
Remove too-late compiler check
drbrain b6404e4
Remove infinite loop in clean task
drbrain 8515eaf
Fix broken rename of `package_dir`
drbrain 038da05
Update setup.rb with build system changes
drbrain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. another good consequence :) |
||
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 <task>\".") \ | ||
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: "<?define Win64 = \"yes\"?>" | ||
} | ||
else | ||
{ | ||
string: "32-bit", | ||
program_files_folder: "ProgramFilesFolder", | ||
define: "<?define Win64 = \"no\"?>" | ||
} | ||
end | ||
|
||
<<-EOF | ||
<?xml version='1.0' encoding='utf-8'?> | ||
<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'> | ||
|
||
#{arch_wxs[:define]} | ||
|
||
<Product | ||
Name='mruby-cli #{arch_wxs[:string]}' | ||
Id='F43E56B6-5FF2-450C-B7B7-0B12BF066ABD' | ||
Version='#{version}' | ||
Language='1033' | ||
Manufacturer='mruby-cli' | ||
UpgradeCode='12268671-59a0-42d3-b1f2-79e52b5657a6' | ||
> | ||
|
||
<Package InstallerVersion="200" Compressed="yes" Comments="comments" InstallScope="perMachine"/> | ||
|
||
<Media Id="1" Cabinet="cabinet.cab" EmbedCab="yes"/> | ||
|
||
<Directory Id='TARGETDIR' Name='SourceDir'> | ||
<Directory Id='#{arch_wxs[:program_files_folder]}' Name='PFiles'> | ||
<Directory Id='INSTALLDIR' Name='mruby-cli'> | ||
<Component Id='MainExecutable' Guid='3DCA4C4D-205C-4FA4-8BB1-C0BF41CA5EFA'> | ||
<File Id='mruby-cliEXE' Name='mruby-cli.exe' DiskId='1' Source='mruby-cli.exe' KeyPath='yes'/> | ||
</Component> | ||
</Directory> | ||
</Directory> | ||
</Directory> | ||
|
||
<Feature Id='Complete' Level='1'> | ||
<ComponentRef Id='MainExecutable' /> | ||
</Feature> | ||
</Product> | ||
</Wix> | ||
EOF | ||
end | ||
|
||
def info_plist_content(version, arch) | ||
<<-EOF | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleExecutable</key> | ||
<string>mruby-cli</string> | ||
<key>CFBundleGetInfoString</key> | ||
<string>mruby-cli #{version} #{arch}</string> | ||
<key>CFBundleName</key> | ||
<string>mruby-cli</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>mruby-cli</string> | ||
<key>CFBundlePackageType</key> | ||
<string>APPL</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>#{version}</string> | ||
<key>CFBundleSignature</key> | ||
<string>mrbc</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
</dict> | ||
</plist> | ||
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 <task>".' | ||
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" | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
considering what you did with other long tasks, I think I'll extract that one too. For now, we can keep as it, there are already enough changed.