I’ve started using Doxygen and JavaDoc style comments on my native C/C++ applications for documentation generation. In keeping with my goal to have everything “just work” on checkout with minimal dependencies (ideally just Visual Studio and version control) I wanted to get it integrated directly into the project. That way anyone can generate the latest version of the documentation from their working copy whenever they need it. Since I use TeamCity for my continuous integration server, it was natural to have the CI server generate and publish the latest documents during the build process.
Setup Doxygen
Setup Doxygen in a Working Copy of your Project
- Download the Windows Doxygen zip package
- Create build/doxygen/bin
- Place DoxyFile in build/doxygen/
- Create build.xml in build/doxygen/
- Test the script using MSBuild in a Visual Studio Command prompt
- Add the documentation/doxygen output folder to your VCS ignore pattern. (e.g. for Mercurial, add the following to the .hgignore file)
- Add the all the files (including doxygen.exe, build.xml, and DoxyFile) to version control, commit the changes and publish them to the master repo (e.g. for Mercurial)
+---build | \---doxygen | \---bin +---code \---documentation
build.xml
<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="3.5" DefaultTargets="Doxygen" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <OutputDirectory>..\..\documentation\doxygen\</OutputDirectory> </PropertyGroup> <Target Name="Doxygen"> <MakeDir Directories="$(OutputDirectory)" /> <Exec Command="bin\doxygen.exe" /> </Target> </Project>
[batch]
cd /path/to/project/build/doxygen
msbuild build.xml
[/batch]
glob:documentation/doxygen/*
[batch]
hg add
hg commit -m"Added Doxygen"
hg push ssh://user@reposerver://srv/hg/project
[/batch]
Setup Public Key Authentication
The following steps must be done on the BUILD SERVER. If you have multiple build servers/build agents for TeamCity, then you’ll need to duplicate most of these steps on each one. Alternatively, you can use a shared RSA key.
Generate an RSA public/private key pair
- Download and Install PuTTY.Look under “A Windows installer for everything except PuTTYtel”
- Open puttygen
- Click Generate
- Click Save Private Key
- Choose a location to save (I’ll use C:\keys for this example)
- Name the file (I’ll use buildserver.ppk for this example)
- Click Save Public Key
- Choose the same location used for the private key
- Name the file (I’ll use buildserver.pub for this example)
The following steps must be done on the WEB SERVER
Add an account for the buildserver
sudo useradd buildserver
Setup public key authentication for the user
- Setup the necessary files, directories, and permissions
- In PuTTYGen, copy the entire contents of the box labeled: “Public key for pasting into OpenSSH authorized_keys file:”
- Paste the contents into authorized_keys on the Web Server and save the file.
su buildserver mkdir ~/.ssh chmod 700 ~/.ssh touch ~/.ssh/authorized_keys chmod 600 ~/.ssh/authorized_keys vim ~/.ssh/authorized_keys
Setup Rsync
The following steps must be done on the BUILD SERVER.
Since Windows doesn’t natively have rsync, I use the cygwin packaged cwrsync.
- Download cwrsync http://www.itefix.no/i2/cwrsync
- Download cygnative
- Create a script which will call cwrsync and pipe the rsync over an SSH connection from the build server to the web server.
I ran into problems with cwrsync being used in conjunction with plink where I received the following error:
“Unable to read from standard input: The parameter is incorrect.”
The problem apparently is when cygwin programs use redirected stdin/stdout handles. The solution I found to this was to use cygnative. From their website:
Cygnative.exe is a wrapper for cygwin programs which call native Win32 programs with stdin and/or stdout handle redirected. Without cygnative.exe it is possible that the native program can not read from the handle and receives a “invalid handle” error.
I placed this script during testing in project\build\doxygen\cwrsync.cmd I was only using it for testing before I put it into a TeamCity build step so I had no plans of commiting it to source control since it ultimately needs the private key which I don’t want in version control. If you aren’t going to use a TeamCity build step to publish the documentation, you can use this script as a starting point for your solution.
[batch]
@ECHO OFF
REM *****************************************************************
REM
REM CWRSYNC.CMD – Batch file template to start your rsync command (s).
REM
REM By Tevfik K. (http://itefix.no)
REM *****************************************************************
REM Make environment variable changes local to this batch file
SETLOCAL
SET LOCAL_DIR=../../documentation/doxygen/html
SET REMOTE_SERVER=yer_remote_machine_name
SET REMOTE_USER=yer_remote_user_name
SET REMOTE_DIR=/var/cache/doxygen/yer_project_name
SET SSH_KEY=yer_ssh_key
SET RSYNC_ARGS=-arz
SET PLINK_CMD=cygnative plink -i %SSH_KEY% -batch
SET REMOTE_CHMOD=chmod -R a+rx %REMOTE_DIR%
REM Specify where to find rsync and related files (C:\CWRSYNC)
SET CWRSYNCHOME=%PROGRAMFILES(x86)%\CWRSYNC
REM *****************************************************************
REM Don’t Change Below This Line
REM *****************************************************************
REM Set HOME variable to your windows home directory. That makes sure
REM that ssh command creates known_hosts in a directory you have access.
SET HOME=%HOMEDRIVE%%HOMEPATH%
REM Make cwRsync home as a part of system PATH to find required DLLs
SET CWOLDPATH=%PATH%
SET PATH=%CWRSYNCHOME%\BIN;%PATH%
REM Publish the files
rsync %RSYNC_ARGS% -e "%PLINK_CMD%" "%LOCAL_DIR%" %REMOTE_USER%@%REMOTE_SERVER%:%REMOTE_DIR%
REM Fix the permissions on the files
%PLINK_CMD% %REMOTE_USER%@%REMOTE_SERVER% %REMOTE_CHMOD%
[/batch]
In a command prompt, cd to the directory that the cwrsync.cmd script is and run it
cd /path/to/cwrsync/script/ cwrsync.cmd
It should ‘just work’. If you get an error running the script or your Web Server isn’t serving up the content, try turning up the verbosity of plink and and rsync by adding -v like this:
SET RSYNC_ARGS=-arzvvvv SET PLINK_CMD=cygnative plink -v -i %SSH_KEY% -batch
Configure TeamCity
- Create a build step to generate the documentation using the build.xml file created earlier in your project’s build configuration.
- Create a build step to publish the documentation to the web server.
- Run your build and verify that everything works!
Runner type: MSBuild
Build file path: build\doxygen\build.xml
Working Directory:
MSBuild version: Microsoft .NET Framework 4.0
MSBuild ToolsVersion: 4.0
Run platform: x86
Targets: Doxygen
Command line parameters:
Reduce test failure feedback time:
.NET Coverage tools:
Report type:Click “Save”
Rather than use a CMD file in version control or pushing it out to all the build agents, I prefer to use a build step in the build configuration for the project in TeamCity. To use the script in the TeamCity build step, you have to use %% rather than % because TeamCity will treat the % as a TeamCity build property.
Runner type: Command Line
Working directory:
Run: Custom Script
Custom script: < the contents of your cwrsync.cmd from earlier, with every '%' replaced with '%%' >
Report type:Click “Save”
6 thoughts