1. Nov 3rd, 2005

    Creating Zip and Tar packages with Rake on Windows

    To get Rake to build Zip and Tar packages, the first thing you’ll need is zip and tar. In my case I decided it would be easier to use command line tools, so my code would work the same way on Windows and Linux. So the first step involves installing Cygwin, and picking up the right packages from the installer. The next step involves adding cygwin\bin to the path, so you can call tar or zip directly from the command line.

    (You probably can run Ruby from the Cygwin, but that requires a few more steps of hacking, and I didn’t have the time to try it out. Besides, as limited as the Windows command line is, once you get all the Cygwin tools … let’s just say it stops being so damn limiting).

    Creating a zip package worked on the first try, but tar complained that it ‘Cannot fork: Function not implemented’. It turns out that Cygwin’s tar can’t run gzip. So once again, it’s time to fix the Rake source code. This time we’re talking about rake/packagetask.rb, line 117 that calls tar with the z option. I replaced that one line with a separate call to tar and gzip:

     sh %{tar cvf #{package_name}.tar #{package_name}} if flag == 'z'   sh %{gzip #{package_name}.tar} end

    You’ll need to be a bit more fancy if you want to support both .tar.gz and .tgz suffixes, but this little fix will allow you to create .tar.gz.

    Image by pigpogm

    1. Apr 3rd, 2007

      todd

      Just had the same problem on rake-0.7.2

      Patch \lib\rake\packagetask.rb: line 126

      flag = “” if RUBY_PLATFORM =~ /mswin32/

      Such that:
      chdir(package_dir) do
      flag = “” if RUBY_PLATFORM =~ /mswin32/
      sh %{#{@tar_command} #{flag}cvf #{file} #{package_name}}
      end

    2. Apr 9th, 2007

      cnruby

      Tar for Windows
      http://gnuwin32.sourceforge.net/packages/tar.htm

    Your comment, here ⇓

    Or using OpenID