Add a File Generated by Run Script into The Test Target Compilation List in Xcode

Add a file generated by run script into the test target compilation list in Xcode

  1. your run script phase should be before Compile Sources phase
  2. you need to add output file paths to Output Files.

By doing this you're letting Xcode know that it should wait this script to be finished before capturing the file structure.

Sample Image

Add files to an Xcode project from a script?

This can be done by adding a new build phase to your application.

  1. In your Xcode project browser, find the target for your application, and expand it to show all of the build phases.

  2. Add a new "run script" build phase to your target. The easiest way is to right-click on the target and choose "Add/New Build Phase/New Run Script Build Phase"

  3. Adding the new build phase should bring up an inspector window. In this window, you can enter the entire shell script, or simply a command line to run the script.

  4. Here's the gold: At the bottom of the inspector window you can specify input files and output files. Specifying input files sets up dependencies automatically (the shell script will only be executed if some of the input files have been modified). Specifying output files automatically propagates the dependencies to those files. When your shell script is run, Xcode knows that it needs to deal with those files that the shell script has modified.

  5. Be sure to drag your new build phase up to the top of the list of phases as shown in the screenshot below. The order will be important if you need those resource files to be included in the bundle.

  6. Save, build, commit to the repository, ask for a raise, get some fresh air and have a nice day! :)

Add source code to Xcode target programmatically

CocoaPods uses this project to modify project files: https://github.com/CocoaPods/Xcodeproj

Xcode 13 error: input file [...] was modified during the build

I'm debugging a similar issue in R.swift, I think I've found the cause of the issue.

Xcode 13 appears to execute Run Script build phases during index builds. This can cause a file to be written to by an index pass, in parallel with a build.

To check if this is happening for you, add this to your build script: say $ACTION

On Xcode 12, it only says "build", but in Xcode 13 I hear it saying "indexbuild" during compilation, whenever I save .swift files or otherwise navigate through my code.

To prevent your script from running during indexing, add this check:

if [ $ACTION != "indexbuild" ]; then
# your script here
fi

Is it possible to script adding a directory of source files into an Xcode project for compile?

Xcode makes it possible to script adding resource files such as images to the project file using the "Build Phases" tab however this does not work for source code files that need to be recognized at compile time. Luckily I managed to come across a nice community-developed Python script which does allow us to do this.

https://github.com/kronenthaler/mod-pbxproj

With this script we can make all sorts of modifications to the project file including adding or deleting files.

See this link for a full list of available operations:

https://github.com/kronenthaler/mod-pbxproj/wiki

Where is Run Script on the target?

  1. Select target in outline view
  2. In the context menu, select "Add..." → "New Build Phase" → "New Run Script Build Phase"
  3. A window will appear where you can edit the script


Related Topics



Leave a reply



Submit