44

How can I see the output from the compiler of from the custom build steps (pre-action or post-action)?

sorin
  • 161,544
  • 178
  • 535
  • 806
  • the correct answer is cody's - to see the Log just click to the, well, Log Button in Xcode :) – Fattie Jul 26 '19 at 14:24

7 Answers7

37

You'll find (and you can watch during the build) the complete build output in the Log Navigator. That's the right most icon of the small icons just below the Run and Build buttons.

Codo
  • 75,595
  • 17
  • 168
  • 206
  • 4
    Thanks for giving me this hint, the only problem is that I do not see anything reffering to the pre-action or post-action for build. I included and `echo` on the shell script and I do not see it. – sorin Mar 24 '11 at 16:44
  • Thanks for posting this. I was trying to find the item by item build results ala xcode 3 and this is about as close as you get. – TahoeWolverine May 25 '11 at 20:28
  • Log Navigator output doesn't include output from Scheme "Run Script" pre-actions. As Jonah notes it can be seen in Console.app – daver Aug 24 '12 at 06:14
  • 3
    For anyone who can't find the raw compiler output simply by "showing" the Log Navigator: With the Log Navigator showing, there should be a list of overall steps, in XCode format, with check marks next to them, in the main pane. Find the step of interest (in mine, it says "compile main.cpp"). Click on it. To the very right, will appear a tiny little icon that looks like a text file. Click on this, to finally reveal the %&^%* compile output. – Dan Nissenbaum Dec 13 '13 at 21:58
15

Pre-action output at least appears in system.log and is visible in Console.app.

Jonah
  • 17,918
  • 1
  • 43
  • 70
  • +1. I have been looking at the Log Navigator, but was unable to see my echo's being outputted. Then I checked Console.app and I now see them listed there. So Console.app works. – neoneye Jul 16 '11 at 09:41
  • 5
    xcode 5.1 - I don't see my echoes in there. Did it change or is my pre-action script not actually being run? – OrangeDog May 19 '14 at 10:22
  • 3
    what does "checked Console.app" mean? I can't seem to find my scheme pre-action script output – hunteros Oct 08 '14 at 21:47
  • http://stackoverflow.com/questions/19014359/how-do-i-view-the-full-build-log-on-xcode5 discusses for Xcode 5, thanks! Whew. – david van brink Mar 08 '15 at 05:01
9

EDIT: as pointed out in the comment below this answer only works for Build phase scripts, not pre action and post action scripts.


In Xcode 8 you need need to select your latest build in "Navigator -> Report Navigator". In the main area you will be able to see the complete build log including your output.

Navigator selection

Here is a simple "Hello world" echo

Log

Nikola Lajic
  • 3,985
  • 28
  • 34
  • 4
    This only applies for scripts added to Build phases, the question specifically asks for pre action and post action scripts where it doesn't work. – Pranshu Feb 09 '17 at 11:21
6

Per my answer here ( Is it normal for Xcode not to detect if a pre-action failed? ) this is an issue that's been discussed in the dev forums. Pre-/post-action script non-zero status doesn't seem to have an affect, nor does the output seem to make it into any logs.

Community
  • 1
  • 1
Joshua Nozzi
  • 60,946
  • 14
  • 140
  • 135
  • I was not able to find any discussion about this on the devforum, but I added a new tread https://devforums.apple.com/message/427106#427106 – sorin May 03 '11 at 08:05
  • the forums have moved, and I didn't see any discussion of this topic in the new forum. https://forums.developer.apple.com/search.jspa?q=xcode+log – AnneTheAgile Sep 03 '15 at 19:40
5

In my case, I have to show the user the error from pre-action scripts in a friendly way. Inspired by this custom archive script, I figured out that I can show dialog or script in Xcode.

  1. add pre-action script enter image description here
  2. In prebuild.sh, use AppleScript to show Dialog
show_dialog() {
  /usr/bin/osascript -e 'set titleText to "pre actions script error"
set dialogText to "Please install xxx to fix it"
display dialog dialogText with icon stop with title titleText' 
}
show_dialog

enter image description here

I use stop icon here, You can also use other icons, like note, and caution

  1. If showing dialog or alter is too harsh, you might consider notification as well.
show_notification() {
/usr/bin/osascript -e 'display notification "Please install xxx to fix it" with title "A error happens" subtitle "Prebuild" sound name "Frog"'
}

show_notification

enter image description here

For me, I usually use Script Editor to edit the AppleScript functions, then copy them to the Shell script

Apple Ref

RY_ Zheng
  • 3,041
  • 29
  • 36
3

So I figured out a way to both:

  1. Show output from pre-build scripts
  2. Stop the build script in the case of a build error

The basic concept is to send all output from the build event to various files, and then present that output as a part of a target build script (which does show it's output and can be exited or canceled).

Warning Hacks be near


Setup a build script that automagically handles pumping the output to 2 different files... 1 for the regular logs, and one for stderr. Or use mine (I posted on my blog because it seems stack overflow code detection sucks at shell scripts.)

Then you should call that script in the scheme prebuild phase like so:

"${PATH_TO_LOG_SCRIPT}/log_prebuild.sh" "${PATH_TO_PREBUILD_SCRIPT_TO_EXECUTE}/scriptToExecute.sh" 2> "${SOURCE_ROOT}/build/prebuild_error.log"

Then you need to setup a script in prior to the compile phase in the target build phases that checks for the presence of those files, dumps them to the logs, and interrupts the build if there was a failure. Or you could again use mine

Then build and cross your fingers :)

BadPirate
  • 25,802
  • 10
  • 92
  • 123
2

Add this line to the top of your run script and put the output file where you can access it:

exec > ${PROJECT_DIR}/prebuild.log 2>&1
echo "this line will be in prebuild.log"
Claytog
  • 618
  • 8
  • 8
  • Out of all the answers here, this is the only one that worked for me. Just had to replace `${PROJECT_DIR}` with the manual path to my directory. I also wrote a command that `tail`s the `prebuild.log` file so I can see the log as it runs. – Luc Apr 10 '22 at 05:11