Cost of Code Refactoring
we had a little problem since the early days and I thought I may as well fix it in a Thursday afternoon this past week. Or did I?
The problem was that to test that certain features are working as expected, we need to be able to force those features on/off from the test suite. The features involved are such things as communicating with an X server without the Render extension, or forcing image fallbacks in PS/PDF/SVG backends. So the way we were doing this was having functions exported in the shared library with names like _cairo_*_test_*(). Apparently that's less than elegant.
There were two options: 1) to make them only available in "debug" builds, or 2) to move those functions out to a separate shared library used just for testing. First option was not that compelling as it forces some tests turned off in production builds, so I took the second approach. We already have this libcairoboilerplate.so library that is a set of routines used by the test and performance suites. So it was perfect place to move those functions. The catch was: the new functions needed to somehow reach into cairo's internals. Something that cairo users should not be able to do. My solution to this was to use cairo's private header files to tweak certain values inside cairo objects. Clean enough: no global variables, no extra symbols exported in libcairo.so.
So it was basically just moving code around: from cairo/src/ into cairo/boilerplate. But to do that I needed to move certain struct definitions from C source files to header files. While at that, I also decided that it makes a lot more sense if I break cairo-boilerplate.c into backend-specific files. Something that we had planned to do for some time anyway, for good reason. So now I had to break boilerplate into about 9 pieces, move some structs from source files to headers, move some functions from src/ into boilerplate/, and finally update tests to adapt to the new APIs.
What looks like simple enough mud work turned out to be a marathon taking well over 12 hours of intense typing. Renaming symbols to have proper prefix, typing lots of files names like cairo-boilerplate-xlib-private.h, adding those new files to Makefile.am, and to git, populating header files, and making sure the build doesn't break at any time is no small thing.
The result? Not less than 51 commits. Add to that the mutex cleanups I did Thursday morning too, and they will add up to 68. Enough said that I was so mental that in two commit logs, typed "[cairo-commit]" instead of "[cairo-mutex]". I would have had a lot more productive Thursday and Friday if people have had added those bits in the right places in the first place. But then again, that's why maintainers are... or are we?
It also meant that I was not doing what I was supposed to do during the first Toronto olpc meetup
at the linuxcaffe
. I still had great time. Thanks Mike
, and I'll promise to be more useful next time.
Labels: cairo, linuxcaffe, maintenance, olpc, refactoring