Contributing To Open Source Projects
Contributing To Open Source Projects
1/3/15, 8:17 PM
Contents
Triage
Patches
Making Patches
Using Patches
Licensing
Culture
Gnu Autotools
CVS
Example: Fixing a #include problem
Suggestions
Testing
Invalid Input Testing
Unit Test Coverage Improvement
Wine Header Cleanup
Wine Command Shell Help Text
Continuous Integration Autobuilders
See Also
Triage
Triage is the fine art of looking at bug reports from users, deciding if they're repeatable, and if so, passing the
proper information on to the developers. This is a great way to get familiar with a project, and to earn karma
points. A guide to triage of OpenOffice bugs is online at kegel.com/openoffice Other projects with bug report
backlogs that could use triage include
Wine
Linux-2.6
glibc
gcc
Patches
Most open source projects work like this: all the developers have their own (not quite identical) copies of the
source code. When one developer has a change he wants to share with the others, he emails them a patch.
http://kegel.com/academy/opensource.html
Page 1 of 8
1/3/15, 8:17 PM
Making Patches
To create a patch, you run a program called diff, and save its output to a file. For instance, if the original
source tree is in directory "foobar.old", and your new sources are in directory "foobar.new", the command
diff -Naur foobar.old foobar.new > blarg.patch
will create the file 'blarg.patch' containing your changes in 'unified context diff' format. (See Diff, Patch, and
Friends for more info.)
You can also diff against individual files rather than directories, but you still want to be in the directory above
the project just as if you were doing a directory diff. Also, to represent the addition of a new file, diff it
against /dev/null (since there was no original file).
If you're submitting a patch to a project that uses CVS, you may be able to use cvsdiff to create the patch, but
IIRC that doesn't handle new files; you have to diff against /dev/null for those.
When creating a patch, remember that the people who receive it will look at it very skeptically, and will
probably reject it if it contains lots of unrelated or unneeded changes.
To maximize the likelihood that other developers will bless your patch, review your patch line by line to
verify that there are no extra changes included. If you see anything extraneous (for instance, the unneccessary
addition or deletion of whitespace), you should go fix your edited file, regenerate the diff, and verify that the
extra changes are gone.
diff is part of the Gnu Project; to learn more, read the GNU project's manual for diff and/or the Linux
Using Patches
To use a patch -- that is, to automatically carry out the changes described in a patch file -- you run a program
called patch. For instance, if you're trying to apply the patch 'blarg.patch' to a package called foobar-0.17,
you might say
cd foobar-0.17; patch -p1 < ../blarg.patch
That would merge the changes from blarg.patch into your source tree. (The -p1 tells patch to ignore the first
directory in filenames in the patch; that way a patch generated against the directory foobar-0.11 will still
apply properly.)
patch is part of the Gnu Project; to learn more, read "Merging with Patch" in the GNU project's manual for
diff.
Licensing
Before you submit a patch, be sure you understand the basics of software licensing, otherwise your patch
might be rejected for legal reasons.
http://kegel.com/academy/opensource.html
Page 2 of 8
1/3/15, 8:17 PM
Culture
The culture of successful open source projects, e.g. the Linux kernel, is described in the following pages:
Andrew Morton's SDForum presentation on the new Linux Kernel development model, 16 Nov 2004
(good for nuts-and-bolts discussion of why things are done with patches and email, and not phone
calls)
Eric Raymond's "The Cathedral and the Bazaar" (if you haven't already seen it)
Gnu Autotools
Many open source projects make use of the Gnu Autotools to generate their Makefiles. The learning curve for
the Autotools is steep, but a few tutorials are available. Here are some places to start:
A Very Short Introduction to Autotools by Peter Vrancx
"hello world" autotools demo by Eleftherios Gkioulekas
IBM's tutorial (free registration required)
The Autotools Book
Shlomi Fish's autotools page
Debugging Configure, by Peter Seebach
CVS
CVS is a source code control system that automates and hides the work of using diff and patch. You'll get to
know cvs later; when starting out, it's best to learn how to use diff and patch. (But if you're curious, you can
learn about cvs at cvshome.org.)
Page 3 of 8
1/3/15, 8:17 PM
package in the installer to get the C compiler! Cygwin's installer's user interface takes some learning.)
2. He went to freshmeat.net and browsed around until he found a project that looked interesting. His
choice was Clex, a curses-based file manager (see http://www.clex.sk).
3. He downloaded the clex source code from its home page's download page (in particular, he
downloaded the file www.clex.sk/download/clex-3.1.7.src.tar.gz), and unpacked it with the command
tar -xzvf clex-3.1.7.src.tar.gz
Then he read the README and INSTALL files for instructions on how to build it, and tried building it,
using the commands
cd clex-3.1.7
./configure
make
4. At that point, I explained that term.h was a standard include file that's part of Unix, but it lives at
different places in different versions of Unix. This is the kind of problem that makes it hard to write
programs that will compile on all versions of Unix! Fortunately, since clex uses Gnu Autotools, and
they're good at handling this kind of problem, the solution was fairly simple: figure out what
subdirectory of /usr/include term.h is in on Cygwin (turns out it's in /usr/include/ncurses), and tell
configure.in to look for term.h in both the normal place and in the ncurses subdirectory. (I helped with
this part, since this is one of those things that's not obvious to beginners.) Then run autoheader and
autoconf to regenerate the Makefiles and whatnot, and away you go. (Annoyingly, Cygwin ships with
two versions of Gnu Autotools, and clex seems to prefer the older one, so we had to modify the PATH
environment variable. See the shell script below.)
5. Having fixed the program, he now wanted to share his fix with the Clex author and other developers.
To do that, he needed to make a patch containing his change. So he read a tutorial on how to use 'diff'
to create patches, then created a patch using the commands
make distclean
cd ..
mv clex-3.1.7 clex.new
tar -xzvf clex-3.1.7.src.tar.gz
diff -aur clex-3.1.7 clex.new > cygwin-clex.patch
6. To make sure his patch really worked, he read a tutorial on how to use 'patch', then unpacked the clex
source code again into a new directory, applied the patch with the command
patch -p1 < cygwin-clex.patch
Page 4 of 8
1/3/15, 8:17 PM
patch if they looked for "clex" in the Cygwin mailing list archives) and the author of clex (so he could
fix the next version of Clex).
The Result
The fruit of his labor was a single short message to a mailing list which contained exactly what other
programmers had to do to fix the bug easily. It said:
I ran into a compile problem while building clex under cygwin.
(Clex is a curses-based file manager; see http://www.clex.sk ).
A patch to fix it is attached, along with a little shell script
that demonstrates how to build clex under Cygwin.
(See the GNU diff manual's description of unified diff format for an explanation of what those +'s and -'s
mean.) And here's the shell script he attached:
wget http://www.clex.sk/download/clex-3.1.7.src.tar.gz
tar zxvf clex-3.1.7.src.tar.gz
patch -p0 < cygwin-clex.patch
cd clex-3.1.7
PATH=/usr/autotool/stable/bin:$PATH
rm missing
aclocal
http://kegel.com/academy/opensource.html
Page 5 of 8
1/3/15, 8:17 PM
Try installing Cygwin on a Windows system, and see if his shell script correctly downloads, patches, and
builds Clex! (You may need to apply the patch by hand, since it's hard to copy and paste patches from web
pages.)
Suggestions
Now that you've seen examples of how to contribute to an existing project, here are some suggestions for
picking projects to contribute to.
The best way to find projects to contribute to is to simply use open source software for all your day to day
computing needs. As time goes on, you will find rough edges here and there. Pick one of the smallest rough
edges you can find, and post a patch that makes things work better.
Some projects maintain "to-do" lists for people who want to fix problems others have already identified. Here
are a few:
Wine: Getting actively involved in the Wine project
Wine: Wine Janitors TODO list
Linux kernel: Kernel Janitors TODO list
Linux kernel: 2.5 Porting Items
Also, here are a few small project ideas:
Testing
Several of the following project ideas have to do with testing. Here are a couple web pages on the subject that
are worth reading:
Simplifying Failure-Inducing Input, by Hildebrandt and Zeller. Paper describing three different apps
and how the authors created minimal test cases for bugs in these apps
Data Structures and Software Dependability - a list of tools that might be of interest when testing
software. (Scroll down to the English section if you can't read German.)
Page 6 of 8
1/3/15, 8:17 PM
http://kegel.com/academy/opensource.html
Page 7 of 8
1/3/15, 8:17 PM
Read up on a couple of them, pick one, and try to set it up to watch a popular open source project (e.g. wine)
and send you email whenever it finds problems. Once that's working, document how you set it up, and post
the description to the mailing list for the project you set up the autobuilder for.
See Also
Linux Weekly News - the best source of kernel information. See their Kernel section; they have a good
set of tutorials for kernel developers.
"How to contribute code back to the open source community" by Kraft and Clavey, IBM
DeveloperToolbox Magazine, 2001
"Let your people code" by Russell Pavlicek, April 2002
"Dealing with unhelpful comments on your open source software", by Ploppy, at Avagadro.org. (Read
this for an idea of how the people receiving your patch feel about things.)
Diff, Patch, and Friends by Michael K. Johnson, Linux Journal, 2003
Contributing to the Linux Kernel by Joseph Pranevich, Linux Journal, 2003
Last Change 22 Nov 2004
(C) Dan Kegel 2003-2004
[Return to www.kegel.com]
http://kegel.com/academy/opensource.html
Page 8 of 8