Archive for the ‘Hoe’ Category

Gem Packaging and Manifest.txt

Friday, April 11th, 2008

You may have noticed that when you tried to package your week 2 gem, you get this error:

[][aaron@amac Week_2]$ rake package
(in /Users/aaron/Desktop/Week_2)
rake aborted!
Don't know how to build task 'bin/week_2'

(See full trace by running task with --trace)
[][aaron@amac Week_2]$
  

When building your gem, Hoe looks at all of the files listed in your Manifest.txt file before packaging the gem. If there are discrepancies between the list in your Manifest.txt and the actual files in your project, Hoe will complain. In this case, there is a file listed in your Manifest.txt that has been removed. That file is ‘bin/week_2′. If you remove that entry from Manifest.txt, your gem should build.

How do I know that ‘bin/week_2′ has been removed? Well, I removed it from the package before I zipped up the project! But lets say I hadn’t told you that, and you want to know what should be in Manifest.txt. Hoe comes with a task called ‘check_manifest’ that checks your manifest, and tells you what needs to be fixed. Lets try out the task with the Week 2 homework:

[][aaron@amac Week_2]$ rake check_manifest
(in /Users/aaron/Desktop/Week_2)
--- Manifest.txt	2008-04-08 22:11:47.000000000 -0700
+++ Manifest.tmp	2008-04-11 10:34:31.000000000 -0700
@@ -2,6 +2,5 @@
 Manifest.txt
 README.txt
 Rakefile
-bin/week_2
 lib/week_2.rb
-test/test_week_2.rb
\ No newline at end of file
+test/test_week_2.rb
[][aaron@amac Week_2]$

That task spit out a diff file that tells us how to change the Manifest. It says we need to remove ‘bin/week_2′ and move ‘test/test_week_2.rb’ to the bottom of the file. If you have the ‘patch’ command on your system, you can use the output of this command to fix your Manifest.txt:

[][aaron@amac Week_2]$ rake check_manifest | patch -p0
patching file Manifest.txt
[][aaron@amac Week_2]$

Now when we run the ‘check_manifest’ task, no diff file is produced because our Manifest file is properly updated:

[][aaron@amac Week_2]$ rake check_manifest
(in /Users/aaron/Desktop/Week_2)
[][aaron@amac Week_2]$

Also our gem packaging works now!

[][aaron@amac Week_2]$ rake package
(in /Users/aaron/Desktop/Week_2)
tar zcvf Week2-1.0.0.tgz Week2-1.0.0
Week2-1.0.0/
Week2-1.0.0/History.txt
Week2-1.0.0/Manifest.txt
Week2-1.0.0/README.txt
Week2-1.0.0/Rakefile
Week2-1.0.0/lib/
Week2-1.0.0/lib/week_2.rb
Week2-1.0.0/test/
Week2-1.0.0/test/test_week_2.rb
  Successfully built RubyGem
  Name: Week2
  Version: 1.0.0
  File: Week2-1.0.0.gem
[][aaron@amac Week_2]$

Before you make a gem release, it is always important to make sure that your Manifest file is up to date. Always run check_manifest, look over the changes it wants to make, and apply the correct changes before packaging.