Archive for Development

Doxygen and API docs in Subversion

For one of my projects I have just started checking generated API documentation into Subversion. This has a few benefits:

  • I don’t need separate hosting for the generated API documentation.
  • The API documentation benefits from whatever versioning scheme you adopt in Subversion.
  • By hooking the script into your release process you can make sure that the documentation is always up to date.

However, there’s a couple of things that may snag you too:

  • It requires that your Subversion repository is available over HTTP.
  • You have to set the mime-type of the various file types correctly. Otherwise you just get the raw content of each file.
  • You have to deal with adding and removing files when the documentation changes.
  • Doxygen puts a timestamp in every file so every time you regenerate the documentation all the files will appear to have changed. That’s a lot of unnecessary updates if you’re barely tweaking the version number for a patch release.

If you’re using Google Code your repository is already available over HTTP. The below script snippet deals with the remaining issues. It assumes that you have already run Doxygen and generated documentation in /tmp/doxygen, and that you are running it from your Subversion checkout, and that the directory that contains the API documentation is called apidocs.

rm -f apidocs/*
cp -p /tmp/doxygen/html/* apidocs
cd apidocs

# Revert files that only has one line removed
# and one added. They differ only in the timestamp.
svn diff *.html \
	| diffstat \
	| awk '$3 == 2 { print $1 }' \
	| xargs svn revert

# Add/remove files from subversion.
svn st | awk '
    $1 == "?" { print "svn add", $2 }
    $1 == "!" { print "svn delete",  $2 }
' | sh -

# Set mime-types so files display properly
# rather than just display their raw content.
svn propset svn:mime-type text/html *.html
svn propset svn:mime-type text/css *.css
svn propset svn:mime-type image/png *.png
svn propset svn:mime-type image/gif *.gif

Notice that it doesn’t actually submit the changes, so you can verify that the generated documentation looks like you want it to before you check it in.

Leave a Comment

Objective-C feature request

dictionary.pngObjective-C, particularly after it became 2.0, is my favourite language. It’s partly because of the language itself, but I guess mostly because of the libraries. The Cocoa libraries are awesome.

For the most part. No software is perfect, and even in Cocoa there are things that could be improved. One thing that continue to trip me up is one of NSDictionary‘s initialiser methods.

Dear Apple,

The dictionaryWithObjectsAndKeys: always end up confusing me, as the arguments always seem in the wrong order. It would make much more sense to have the method dictionaryWithKeysAndObjects: where you specified a list of key/value pairs, rather than value/key pairs.

Yours Sincerely,

Stig

Here’s a random sample of the above from the Adium source code. Honestly. I grabbed the first sample from it I could find. I did not hunt for a particularly egregious example:


NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
    [NSValue valueWithPointer:SecKeychainLockAll], AIKEYCHAIN_ERROR_USERINFO_SECURITYFUNCTION,
    @"SecKeychainLockAll", AIKEYCHAIN_ERROR_USERINFO_SECURITYFUNCTIONNAME,
    AI_LOCALIZED_SECURITY_ERROR_DESCRIPTION(err), AIKEYCHAIN_ERROR_USERINFO_ERRORDESCRIPTION,
    nil];

Doesn’t that make a lot more sense like this?


NSDictionary *userInfo = [NSDictionary dictionaryWithKeysAndObjects:
    AIKEYCHAIN_ERROR_USERINFO_SECURITYFUNCTION, [NSValue valueWithPointer:SecKeychainLockAll],
    AIKEYCHAIN_ERROR_USERINFO_SECURITYFUNCTIONNAME, @"SecKeychainLockAll",
    AIKEYCHAIN_ERROR_USERINFO_ERRORDESCRIPTION, AI_LOCALIZED_SECURITY_ERROR_DESCRIPTION(err),
    nil];

This has confused me so many times now that I have filed a feature request with Apple (rdar://problem/6171269) to have a new method with the arguments in the “right” order. (Wondering if that url is broken? See here.) Here’s to hoping that they honour it and put it in Snow Leopard…

Comments (1)

Cocoa JSON Framework v1!

This is an important bugfix release. I bumped the version all the way to the big 1-dot-oh since it now handles all the JSON checker tests correctly. Specifically, the bugs fixed since version 0.2 are:

  • Unicode control characters, that is code points below 0×20, are now always escaped. Earlier only the ones with special two-character shortcuts were.
  • We now correctly throw an exception if any JSON strings contains unescaped control chars. Trailing garbage—extra characters after a JSON payload—is now not allowed.
  • It turned out I was a little too lenient when parsing numbers. Strict JSON does not allow leading zeros (i.e. ’012′), leading plus signs (i.e. ‘+10′), or omission of digits after the exponent (i.e. ’0e’ and ’0e+’). This error has now been fixed.

This project has its own web site at http://code.brautaset.org/JSON/.

Comments (2)

Follow

Get every new post delivered to your Inbox.