@@ -135,3 +135,185 @@ Rake.application.tasks.each do |task|
135135 end
136136 end
137137end
138+
139+ namespace :package do
140+ require 'fileutils'
141+ require 'tmpdir'
142+ require_relative "#{ MRUBY_ROOT } /../mrblib/mruby-cli/version"
143+
144+ version = MRubyCLI ::Version ::VERSION
145+ release_dir = "releases/v#{ version } "
146+ package_dir = "packages/v#{ version } "
147+ release_path = Dir . pwd + "/../#{ release_dir } "
148+ package_path = Dir . pwd + "/../#{ package_dir } "
149+ FileUtils . mkdir_p ( package_path )
150+
151+ def check_fpm_installed?
152+ `gem list -i fpm` . chomp == "true"
153+ end
154+
155+ def check_msi_installed?
156+ `wixl --version`
157+ $?. success?
158+ end
159+
160+ def check_dmg_installed?
161+ `genisoimage --version`
162+ $?. success?
163+ end
164+
165+ def wxs_content ( version , arch )
166+ arch_wxs = case arch
167+ when "x86_64"
168+ {
169+ string : "64-bit" ,
170+ program_files_folder : "ProgramFiles64Folder" ,
171+ define : "<?define Win64 = \" yes\" ?>"
172+ }
173+ else
174+ {
175+ string : "32-bit" ,
176+ program_files_folder : "ProgramFilesFolder" ,
177+ define : "<?define Win64 = \" no\" ?>"
178+ }
179+ end
180+
181+ <<-EOF
182+ <?xml version='1.0' encoding='utf-8'?>
183+ <Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>
184+
185+ #{ arch_wxs [ :define ] }
186+
187+ <Product
188+ Name='mruby-cli #{ arch_wxs [ :string ] } '
189+ Id='F43E56B6-5FF2-450C-B7B7-0B12BF066ABD'
190+ Version='#{ version } '
191+ Language='1033'
192+ Manufacturer='mruby-cli'
193+ UpgradeCode='12268671-59a0-42d3-b1f2-79e52b5657a6'
194+ >
195+
196+ <Package InstallerVersion="200" Compressed="yes" Comments="comments" InstallScope="perMachine"/>
197+
198+ <Media Id="1" Cabinet="cabinet.cab" EmbedCab="yes"/>
199+
200+ <Directory Id='TARGETDIR' Name='SourceDir'>
201+ <Directory Id='#{ arch_wxs [ :program_files_folder ] } ' Name='PFiles'>
202+ <Directory Id='INSTALLDIR' Name='mruby-cli'>
203+ <Component Id='MainExecutable' Guid='3DCA4C4D-205C-4FA4-8BB1-C0BF41CA5EFA'>
204+ <File Id='mruby-cliEXE' Name='mruby-cli.exe' DiskId='1' Source='mruby-cli.exe' KeyPath='yes'/>
205+ </Component>
206+ </Directory>
207+ </Directory>
208+ </Directory>
209+
210+ <Feature Id='Complete' Level='1'>
211+ <ComponentRef Id='MainExecutable' />
212+ </Feature>
213+ </Product>
214+ </Wix>
215+ EOF
216+ end
217+
218+ def info_plist_content ( version , arch )
219+ <<-EOF
220+ <?xml version="1.0" encoding="UTF-8"?>
221+ <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
222+ <plist version="1.0">
223+ <dict>
224+ <key>CFBundleExecutable</key>
225+ <string>mruby-cli</string>
226+ <key>CFBundleGetInfoString</key>
227+ <string>mruby-cli #{ version } #{ arch } </string>
228+ <key>CFBundleName</key>
229+ <string>mruby-cli</string>
230+ <key>CFBundleIdentifier</key>
231+ <string>mruby-cli</string>
232+ <key>CFBundlePackageType</key>
233+ <string>APPL</string>
234+ <key>CFBundleShortVersionString</key>
235+ <string>#{ version } </string>
236+ <key>CFBundleSignature</key>
237+ <string>mrbc</string>
238+ <key>CFBundleInfoDictionaryVersion</key>
239+ <string>6.0</string>
240+ </dict>
241+ </plist>
242+ EOF
243+ end
244+
245+ def osx_setup_bash_path_script
246+ <<-EOF
247+ #!/bin/bash
248+ echo "export PATH=$PATH:/Applications/mruby-cli.app/Contents/MacOs" >> $HOME/.bash_profile
249+ source $HOME/.bash_profile
250+ EOF
251+ end
252+
253+ def log ( package_dir , version , package )
254+ puts "Writing packages #{ package_dir } /#{ version } /#{ package } "
255+ end
256+
257+ desc "create deb package"
258+ task :deb => [ :release ] do
259+ abort ( "fpm is not installed. Please check your docker install." ) unless check_fpm_installed?
260+
261+ [ "x86_64" , "i686" ] . each do |arch |
262+ release_tar_file = "mruby-cli-#{ version } -#{ arch } -pc-linux-gnu.tgz"
263+ arch_name = ( arch == "x86_64" ? "amd64" : arch )
264+ log ( package_dir , version , "mruby-cli_#{ version } _#{ arch_name } .deb" )
265+ `fpm -s tar -t deb -a #{ arch } -n mruby-cli -v #{ version } --prefix /usr/bin -p #{ package_path } #{ release_path } /#{ release_tar_file } `
266+ end
267+ end
268+
269+ desc "create rpm package"
270+ task :rpm => [ :release ] do
271+ abort ( "fpm is not installed. Please check your docker install." ) unless check_fpm_installed?
272+
273+ [ "x86_64" , "i686" ] . each do |arch |
274+ release_tar_file = "mruby-cli-#{ version } -#{ arch } -pc-linux-gnu.tgz"
275+ log ( package_dir , version , "mruby-cli-#{ version } -1.#{ arch } .rpm" )
276+ `fpm -s tar -t rpm -a #{ arch } -n mruby-cli -v #{ version } --prefix /usr/bin -p #{ package_path } #{ release_path } /#{ release_tar_file } `
277+ end
278+ end
279+
280+ desc "create msi package"
281+ task :msi => [ :release ] do
282+ abort ( "msitools is not installed. Please check your docker install." ) unless check_msi_installed?
283+ [ "x86_64" , "i686" ] . each do |arch |
284+ log ( package_dir , version , "mruby-cli-#{ version } -#{ arch } .msi" )
285+ release_tar_file = "mruby-cli-#{ version } -#{ arch } -w64-mingw32.tgz"
286+ Dir . mktmpdir do |dest_dir |
287+ Dir . chdir dest_dir
288+ `tar -zxf #{ release_path } /#{ release_tar_file } `
289+ File . write ( "mruby-cli-#{ version } -#{ arch } .wxs" , wxs_content ( version , arch ) )
290+ `wixl -v mruby-cli-#{ version } -#{ arch } .wxs && mv mruby-cli-#{ version } -#{ arch } .msi #{ package_path } `
291+ end
292+ end
293+ end
294+
295+ desc "create dmg package"
296+ task :dmg => [ :release ] do
297+ abort ( "dmg tools are not installed. Please check your docker install." ) unless check_dmg_installed?
298+ [ "x86_64" , "i386" ] . each do |arch |
299+ log ( package_dir , version , "mruby-cli-#{ version } -#{ arch } .dmg" )
300+ release_tar_file = "mruby-cli-#{ version } -#{ arch } -apple-darwin14.tgz"
301+ Dir . mktmpdir do |dest_dir |
302+ Dir . chdir dest_dir
303+ `tar -zxf #{ release_path } /#{ release_tar_file } `
304+ FileUtils . chmod 0755 , "mruby-cli"
305+ FileUtils . mkdir_p "mruby-cli.app/Contents/MacOs"
306+ FileUtils . mv "mruby-cli" , "mruby-cli.app/Contents/MacOs"
307+ File . write ( "mruby-cli.app/Contents/Info.plist" , info_plist_content ( version , arch ) )
308+ File . write ( "add-mruby-cli-to-my-path.sh" , osx_setup_bash_path_script )
309+ FileUtils . chmod 0755 , "add-mruby-cli-to-my-path.sh"
310+ `genisoimage -V mruby-cli -D -r -apple -no-pad -o #{ package_path } /mruby-cli-#{ version } -#{ arch } .dmg #{ dest_dir } `
311+ end
312+ end
313+ end
314+
315+ end
316+
317+ desc "create all packages"
318+ task :package => [ "package:deb" , "package:rpm" , "package:msi" , "package:dmg" ]
319+
0 commit comments