views:

57

answers:

1

Is there any way to write to the XCode build transcript? What i want to do, is throw a warning if a device is not attached to the computer instead of an assertion failure in my unit test cases (some cases rely on an attached ipod).

I thought of something like the standard compiler warnings (only with custom message).

Thanks.

+4  A: 

In shell build phases you can write to stderr using the following format:

<filename>:<linenumber>: error | warn | note : <message>\n

It's the same format gcc uses to show errors. The filename:linenumber part can be omitted. Depending on the mode (error, warn, note), Xcode will show your message with a red or yellow badge.

If you include an absolute file path and a line number (if the error occurred in a file), double clicking the error in the build log lets Xcode open the file and jumps to the line, even if it is not part of the project. Very handy.

Nikolai Ruhe
I've made myself a macro for this, but somehow it doesn't seem to show up in the buildlog, although it prints exactly the same string as gcc :( #define STWarning(msg) fprintf(stderr, "%s:%d: warning: %s\n", __FILE__, __LINE__, msg)
Erik Aigner
the file and line underscores got lost somehow, assume they're there.
Erik Aigner
oh sorry... you ment BUILD PHASES. mhm is there some method that would work directly from code? (i guess not)
Erik Aigner
eaigner: You can't write to the build log after the build has finished.
Peter Hosey
Thought so. But how are unit tests executed? Their runs/assertions appear in the build transcript too.
Erik Aigner
They are run from a shell script build phase. As such, output from test cases should appear in the build log if properly formatted.
Peter Hosey