Pre-Actions Run Script not working in Xcode 12.2 beta 2 ?

I am trying to run different command line executables like SwiftLint, Sourcery, etc. from a Scheme's pre-action and / or post-action run script in the Build phase -- I can't use a target build phase run script because I am creating a Swift Package.

It seems that those scripts don't get called. Is there a known issue with those in Xcode 12 or 12.2 ?

Replies

Using a simple script with an echo command, I confirmed (what I already knew!) that, for the same project :
  • a target's "Build Phases" run script gets triggered (i.e. normal behavior)

  • a scheme's "Build Pre-actions" (or Post-actions) run script will NOT be triggered


Code Block
# Type a script or drag a script file from your workspace to insert its path.
echo "warning: RUN SCRIPT in ACTION"


For the target's "Build Phases" run script I see the following in the Build Report Navigator (i.e. I know the script is running) :

Code Block
Showing Recent Messages
...
    write-file /somepath/CoreLocation-Redux-deixbbxleyyndwgicetkzwybusoj/Build/Intermediates.noindex/CoreLocation-Redux.build/Debug-iphoneos/CoreLocation-Redux\ \(iOS\).build/Script-8E1070E4252F51F600F35D59.sh
PhaseScriptExecution Run\ Script /somepath/CoreLocation-Redux-deixbbxleyyndwgicetkzwybusoj/Build/Intermediates.noindex/CoreLocation-Redux.build/Debug-iphoneos/CoreLocation-Redux\ (iOS).build/Script-8E1070E4252F51F600F35D59.sh (in target 'CoreLocation-Redux (iOS)' from project 'CoreLocation-Redux')
.....
    /bin/sh -c /somepath/CoreLocation-Redux-deixbbxleyyndwgicetkzwybusoj/Build/Intermediates.noindex/CoreLocation-Redux.build/Debug-iphoneos/CoreLocation-Redux\\\ \\\(iOS\\\).build/Script-8E1070E4252F51F600F35D59.sh
warning: RUN SCRIPT in ACTION


There's nothing for the scheme's pre or post actions run scripts. Bug ?

This is for :

Xcode version 12.2 beta 2 (12B5025f)
macOS Catalina version 10.15.7 (19H2)


After reading this answer, it seems that's the correct behavior and the traces for a scheme's run script won't appear in the Build logs of a project inside Xcode (and rather in stdErr).

However I still can get the same result for a Swift package build (maybe . So my original question still stands : how do you add a build script for a Swift package (for things like SwiftLint, Sourcery, etc.) ?
Did you find a solution? I'm still facing this issue on Xcode 12.2
For me, the "not working" effect was caused by a directory path lookup failure in my script.

If you run your script at your target's Build Phases, A relative directory path like this will work:
Code Block
INFO="MyApp/Info.plist"

However in Pre-Actions it fails silently.
Instead, you must use an absolute directory path like this:
Code Block
INFO="${PROJECT_DIR}/MyApp/Info.plist"