Making rake package zip on Windows
Oct/071
If you want to do rake package on Windows and specify need_zip = true, it’s a bit of a problem because Windows doesn’t come with a command-line zip program. To be sure, one could always install Cygwin.
I’ve seen blogs talking about hacking rake, but that seems really gross.
Another option is to clone as much of zip as rake needs (not much!) with the rubyzip gem. After doing gem install rubyzip, the following seems to be acceptable for rake (haven’t tested this a lot; feel free to fix my code
). This little bit of code — simulating what command-line zip does — seems to be a sort of missing link in the documentation and tests for rubyzip. It’s easy, but not super-obvious from the docs.
require 'zip/zip'
recursive = false
if ARGV[0] == '-r'
recursive = true
ARGV.shift
end
archive = ARGV.shift
ARGV.each do |arg|
files = recursive ? Dir[ arg + '/**/*.*' ] : [arg]
files.each do |f|
Zip::ZipFile.open(archive, Zip::ZipFile::CREATE) do |z|
z.add( f, f)
puts " adding #{f}"
end
end
end
And then in your Rakefile.rb, something like:
desc "Zip up project"
Rake::PackageTask.new("#{PROJECT}-#{USER}", "1.0.0") do |p|
p.need_zip = true
p.zip_command = 'ruby ../myzip.rb'
p.package_files.include("./**/*")
p.package_files.exclude("./**/*.svn")
p.package_files.exclude("./doc")
p.package_files.exclude("./pkg")
end
Leave a comment
No trackbacks yet.

12:53 am on October 8th, 2007
Or you could install a commandline zip utility even without Cygwin (not that I ever use a Windows machine for more than 1 day without installing Cygwin…)