Skip to content
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

A task to package mruby-cli as deb or rpm #10

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
mruby/
releases/
packages/
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,14 @@ This means that if you want to add a new rake task `my_task`, you need to add it
Just type: `docker-compose run release`

After this command finishes, you'll see the releases for each target in the `releases` directory.

### Create package

We can package the ad hoc release as deb, rpm, msi, or dmg for the following
Linux.

To create all the package, just type

```
docker-compose run package
```
214 changes: 214 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ load "#{mruby_root}/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
Expand Down Expand Up @@ -103,3 +107,213 @@ task :release => :compile do
end
end
end

namespace :local do
desc "show help"
task :version do
require_relative 'mrblib/mruby-cli/version'
puts "mruby-cli #{MRubyCLI::Version::VERSION}"
end
end

def is_in_a_docker_container?
`grep -q docker /proc/self/cgroup`
$?.success?
end

Rake.application.tasks.each do |task|
next if ENV["MRUBY_CLI_LOCAL"]
unless task.name.start_with?("local:")
# Inspired by rake-hooks
# https://github.com/guillermo/rake-hooks
old_task = Rake.application.instance_variable_get('@tasks').delete(task.name)
desc old_task.full_comment
task old_task.name => old_task.prerequisites do
abort("Not running in docker, you should type \"docker-compose run <task>\".") \
unless is_in_a_docker_container?
old_task.invoke
end
end
end

namespace :package do
require 'fileutils'
require 'tmpdir'
require_relative "#{MRUBY_ROOT}/../mrblib/mruby-cli/version"

version = MRubyCLI::Version::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
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|
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

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

end

desc "create all packages"
task :package => ["package:deb", "package:rpm", "package:msi", "package:dmg"]

5 changes: 3 additions & 2 deletions bintest/mruby-cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Dir.mktmpdir do |tmp_dir|
Dir.chdir(tmp_dir) do
app_name = "new_cli"
output, status = Open3.capture2(BIN_PATH, "--setup", app_name)
output, status = Open3.capture2("#{BIN_PATH} --setup=#{app_name}")

assert_true status.success?, "Process did not exit cleanly"
assert_true Dir.exist?(app_name)
Expand All @@ -25,13 +25,14 @@
Dir.mktmpdir do |tmp_dir|
Dir.chdir(tmp_dir) do
app_name = "hello_world"
APP_PATH = File.join("mruby/bin/#{app_name}")
Open3.capture2(BIN_PATH, "--setup", app_name)

Dir.chdir(app_name) do
output, status = Open3.capture2("rake compile")
assert_true status.success?, "`rake compile` did not exit cleanly"

output, status = Open3.capture2("mruby/bin/#{app_name}")
output, status = Open3.capture2(APP_PATH)
assert_true status.success?, "`#{app_name}` did not exit cleanly"
assert_include output, "Hello World"

Expand Down
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ shell:
release:
<<: *defaults
command: rake release
package:
<<: *defaults
command: rake package
33 changes: 33 additions & 0 deletions mrblib/mruby-cli/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,11 @@ def rakefile

desc "compile binary"
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
Expand Down Expand Up @@ -377,6 +382,34 @@ def clean_env(envs)
task :clean do
sh "rake deep_clean"
end

namespace :local do
desc "show help"
task :version do
require_relative 'mrblib/mruby-cli/version'
puts "mruby-cli \#{MRubyCLI::Version::VERSION}"
end
end

def is_in_a_docker_container?
`grep -q docker /proc/self/cgroup`
$?.success?
end

Rake.application.tasks.each do |task|
next if ENV["MRUBY_CLI_LOCAL"]
unless task.name.start_with?("local:")
# Inspired by rake-hooks
# https://github.com/guillermo/rake-hooks
old_task = Rake.application.instance_variable_get('@tasks').delete(task.name)
desc old_task.full_comment
task old_task.name => old_task.prerequisites do
abort("Not running in docker, you should type \\"docker-compose run <task>\\".") \
unless is_in_a_docker_container?
old_task.invoke
end
end
end
RAKEFILE
end
end
Expand Down