Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add run script build phase to Xcode project from podspec

I'm trying to write Cocoapods specification for my library which must modify Xcode project and add "Run Script Build Phase" to project's target. I thought I can use post_install hook. But "pod spec lint" says that this hook is deprecated:

- WARN  | [iOS] The post install hook of the specification DSL has been deprecated, use the `resource_bundles` or the `prepare_command` attributes. 

I have no idea how I can replace post_install hook with *resource_bundles* or *prepare_command*. Who knows any other approach to solve my problem? Is it possible?

And another problem is how to modify Xcode project to add build phase, but it is actual only when "post_hook problem" is solved.

like image 257
opedge Avatar asked Nov 19 '13 13:11

opedge


People also ask

How do I run a build phase script in Xcode?

Go to the Build Phases section of your project. (Click on the project, then on the main target, then on the “Build Phases” tab along the top.) Click the + at the top left to create a new build phase; choose “New Run Script Phase.” Xcode creates the script at the end of the list, naming it “Run Script.”


1 Answers

Use the Xcodeproj ruby gem (which is part of Cocoapods) to write a script that modifies your Xcode project.

You then call this script using the prepare_command

require 'xcodeproj' path_to_project = "${SOURCE_ROOT}/${PROJECT_NAME}.xcodeproj" project = Xcodeproj::Project.open(path_to_project) main_target = project.targets.first phase = main_target.new_shell_script_build_phase("Name of your Phase") phase.shell_script = "do sth with ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/your.file" project.save() 

Documentation: http://rubydoc.info/gems/xcodeproj

You can get a list of build setting variables and their values by running…

xcodebuild -project [ProjectName].xcodeproj -target "[TargetName]" -showBuildSettings 

UPDATE: A few things have changed since this answer was written. The issue of accessing environment variables is currently being discussed here: https://github.com/CocoaPods/CocoaPods/issues/2115

like image 136
Onato Avatar answered Sep 23 '22 08:09

Onato