Wednesday, September 19, 2007

Patching And Building Extensions

This is a quick lil' run through on how to apply a patch and build an extension.

Applying a pizzzatch
Pre-condition: Before starting this I'm assuming you have already checked out the code from cvs.

1) Download the patch, this may seem straight forward but I actually tripped on this. The patches
I were applying are https://bugzilla.mozilla.org/show_bug.cgi?id=393881, you must open each attachment in the
browser and then go to file->save as and that will save it as a .patch. Not knowing how any of this
works thought the attachment was going to be a straight forward .cpp file. So when confronted with a bunch of C++ code and then some, I got twisted.

2) Go into the path that contains the file you're about to patch and run the following command
patch -p0 -i /the/path/to/your/patch'/you/just/downloaded/
Doing so will patch the appropriate files. I got the following output when I did the above.

cozbymac:~/Documents/development/MozillaBuildStuff/mozilla/extensions/metrics cozby$ patch -p0 -i ~/Documents/development/MozillaBuildStuff/patches/metrics-places-update-01.patch
patching file src/nsProfileCollector.cpp
cozbymac:~/Documents/development/MozillaBuildStuff/mozilla/extensions/metrics cozby$ patch -p0 -i ~/Documents/development/MozillaBuildStuff/patches/metrics-places-update-02.patch
patching file install.rdf
patching file src/nsProfileCollector.cpp
Hunk #6 succeeded at 779 (offset -5 lines).
patching file src/nsProfileCollector.h
patching file src/nsUICommandCollector.cpp

3) Super, now thats all patched up I need to make sure the extension I want gets built. So I needed to add the following line to my .mozconfig file
ac_add_options --enable-extensions=metrics
in my case I'm building the metrics extension, if you want to build something replace metrics with the name of the extension.

4) Build. make -f client.mk build
5) Wait...
6) It worked!

UPDATE:
Thanks to Dave, I now know a much much easier way to build extensions. Instead of building World every time, you can just go into your objdir/extension/some_extension/ and type 'make'.
Thats it... it'll build just the extension and place the .xpi accordingly. EPIC.

No comments: