How to display compiler output or custom build steps output when building with xcode?

前端 未结 6 1764
渐次进展
渐次进展 2020-12-09 01:47

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

相关标签:
6条回答
  • 2020-12-09 02:07

    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
    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
    
    

    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
    
    

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

    Apple Ref

    • Apple Script Dialog
    • Apple Script Notification
    0 讨论(0)
  • 2020-12-09 02:08

    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.

    Here is a simple "Hello world" echo

    0 讨论(0)
  • 2020-12-09 02:10

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

    0 讨论(0)
  • 2020-12-09 02:26

    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.

    0 讨论(0)
  • 2020-12-09 02:28

    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.

    0 讨论(0)
  • 2020-12-09 02:29

    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 :)

    0 讨论(0)
提交回复
热议问题