free hit counter

Friday, July 22, 2011

awk out the git hash

I'm using the first 5 of the git hash as a build number so we can get some automated traceability of developer builds around here.

git log | head | awk '/commit/ {print substr($2,0,5)}' | head -1

ain't unix great?

The first to head at the beginning saves a few milliseconds of your CPU's time by not processing the entire history, and the last call to head -1 makes sure you just get one hash back.

To coerce CMake into stuffing that into a versionInfo.h file you'll need to put the command into a two line script file as CMake execute_process doesn't support a fully piped call like this.

Labels: ,

Thursday, July 21, 2011

cmake and reswrap


profile for Rian Sanderson at Stack Overflow, Q&A for professional and enthusiast programmers

I was trying to package up some test data files into an object file so my unit tests wouldn't depend on anything external. StackOverflow was a bit of help, but I eventually pried the answer from the cryptic CMake documentation.

I solved it with reswrap and CMake, using add_custom_command and some additional dependency magic with set_property.


add_custom_command(
OUTPUT testData.cpp
COMMAND reswrap
ARGS testData.src > testData.cpp
DEPENDS testData.src
)
set_property(SOURCE unit-tests.cpp APPEND PROPERTY OBJECT_DEPENDS testData.cpp)

add_executable(app main.cpp)
add_executable(tests unit-tests.cpp)


So now testData.cpp will generated before unit-tests.cpp is compiled, and any time testData.src changes. If the command you're calling is really slow you get the added bonus that when you build just the app target you won't have to wait around for that command (which only the tests executable needs) to finish.

It's not shown above, but careful application of ${PROJECT_BINARY_DIR}, ${PROJECT_SOURCE_DIR} and include_directories() will keep your source tree clean of generated files.

Labels: ,

Tuesday, July 12, 2011

memory leak check in unit tests



I'd like to easily check for memory leaks inside my unit tests, and it seems that lots of other people want to as well, but it's not natively supported under Linux:

http://stackoverflow.com/questions/3559938/memory-leak-unit-test-c
http://stackoverflow.com/questions/169058/memory-leak-detection-while-running-unit-tests
http://stackoverflow.com/questions/2980917/c-is-it-possible-to-implement-memory-leak-testing-in-a-unit-test
http://stackoverflow.com/questions/3652028/unit-testing-memory-leaks

Score one point for Redmond, apparently this is supported in MSVC under Windows; it's even implemented in Boost::Test.

However, under Linux it looks like people who want to do this are running their unit test suite under valgrind, or compiling each unit test into its own executable and running valgrind on that.

Labels: ,

Good way to market consulting services

This guy has a good idea for marketing his consulting services.

1. write a book
2. create a sizeable video lecture (high on information, low on sales pitch)
3. advertise a free $99 value, pointing people to your video
4. raffle off an hour of consulting time to people who blog about video

http://appsumo.com/google-analytics-video-2

* traffic is driven to him because of the $99 offer
* saves time because anyone who contacts him has heard the core of his sales pitch
* anyone who blogs about him has some skin in the game, and at the least is more likely to buy his book
* anyone who actually wins the raffle is likely to purchase at least a few more hours of consulting
* blog traffic will up his rank in google search

Labels: