Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 139 Vote(s) - 3.68 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Add run script build phase to Xcode project from podspec

#1
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][1] 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.

[1]:

[To see links please register here]

Reply

#2
The complete guide can be found here:

[To see links please register here]


But as a short version, you can add you can add Build Phase scripts like this:

```
s.script_phase = {
:name => 'Hello World',
:script => 'echo "Hello World"',
:execution_position => :before_compile
}
```

If you want to execute a shell script this syntax can be used: (Your file should be executable `chmod +x setup.sh`)

```
s.script_phases = [
{ :name => 'Precompile',
:script => '${PODS_TARGET_SRCROOT}/setup.sh',
:execution_position => :before_compile
}
]
```
If you want to add multiple scripts you can do it like this:
```
s.script_phases = [
{ :name => 'Precompile',
:script => '${PODS_TARGET_SRCROOT}/setup.sh',
:execution_position => :before_compile
},
{ :name => 'Postcompile',
:script => 'echo "yay!"',
:execution_position => :after_compile
}
]
```

**Note**: Do not forget to preserve the path to your script file:
`s.preserve_paths = '{path}/setup.sh'`
Reply

#3
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](

[To see links please register here]

)

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:

[To see links please register here]


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:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through