ISDi
ISDi

Reputation: 165

Xcode Post Build Copy File Actions

In Xcode, how can I call a 'shell script' which is a Perl script that copies the .app and .dsym files to a different directory?

I want to pass the name of the project and/or the project's root directory to the script. I want to have the script called every time I build in release and distribution modes but not in debug mode.

Upvotes: 5

Views: 16005

Answers (3)

idbrii
idbrii

Reputation: 11956

Instead of a script, Xcode 12.4 has an build phase for copying files:

  1. Show the project navigator (blue folder button)
  2. Click on your project (blueprint icon)
  3. Click "Build Phases" header in the opened settings pane
  4. Click the + in the top left of the settings pane
  5. Click "New Copy Files Phase"
  6. Change Destination to Absolute Path and set your path
  7. Click the + at the bottom to add a file to be copied
  8. Save. If you run without saving, your new phase is ignored.

If you don't want an absolute path or one of the destinations provided, you'll have to use a Run Script Phase instead.

Upvotes: 2

Chris Conover
Chris Conover

Reputation: 9039

For anyone else who is wondering, you can also do a simple copy via

[Click on Scheme Name] -> Edit Scheme... -> [Select Scheme] -> Run "Target" -> Post-actions

and add a cp command. In my case, for quick testing and ease of use, I wanted to copy my binary back to the project directory so that I could process some data files. I used the following:

cp ${TARGET_BUILD_DIR}/${TARGET_NAME} ${PROJECT_DIR}/"binaryFileName"

Upvotes: 9

Shaggy Frog
Shaggy Frog

Reputation: 27601

Right-click on your target and choose Add->New Build Phase->New Run Script Build Phase.

Inside the "Script" text area, add:

if [ ${CONFIGURATION} != "Debug" ]
then
    /usr/bin/perl "${PROJECT_DIR}/myperlscript.pl" "${PRODUCT_NAME}" "${PROJECT_DIR}"
fi

Change the location and name of myperlscript.pl to be the location and name of your script.

Make sure to move the Run Script step to be after Link Binary With Libraries, since you're copying the built .app.

(Might also want to add the "perl" tag to the question)

Upvotes: 5

Related Questions