-
-
Save romainbriche/151a7d4489fe036c2afbd1a56fbd6a2f to your computer and use it in GitHub Desktop.
POC of a Pod which installs a run script into Xcode (CocoaPods 0.33 or less)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require 'pathname' | |
| require 'xcodeproj' | |
| path_to_xcode_build_script = '"${SRCROOT}/Pods/POD_NAME/run_script.sh"' | |
| xcode_build_script_name = 'Unique Run Script Name' | |
| puts Dir.pwd | |
| puts ARGV[0] | |
| path_to_spec = ARGV[0] # Passed from podspec using path variable | |
| if path_to_spec.start_with?('/private/tmp/CocoaPods/Lint') | |
| # CocoaPods Lint | |
| # e.g. /private/tmp/CocoaPods/Lint/Pods/Local Podspecs/POD_NAME.podspec | |
| puts 'CocoaPods linting, bail now before fail' | |
| exit 0 | |
| elsif path_to_spec.include?('.cocoapods') | |
| # Pod installed from spec repo | |
| # podspec: /Users/ben/.cocoapods/repos/REPO_NAME/POD_NAME/1.0.0/POD_NAME.podspec | |
| # Dir.pwd: /Users/ben/APP_PATH/Pods/POD_NAME | |
| path_to_project = Dir.glob(Pathname.new(Dir.pwd) + '../../*.xcodeproj')[0] | |
| else | |
| # Pod installed via :path in Podfile | |
| # podspec: /Users/ben/LOCAL_POD_PATH/POD_NAME/POD_NAME.podspec | |
| # Dir.pwd: /Users/ben/LOCAL_POD_PATH/POD_NAME | |
| path_to_project = Dir.glob(Pathname.new(path_to_spec) + '../../../*.xcodeproj')[0] | |
| end | |
| puts path_to_project | |
| project = Xcodeproj::Project.open(path_to_project) | |
| main_target = project.targets.first | |
| script_installed = false | |
| main_target.shell_script_build_phases.each { |run_script| | |
| script_installed = true if run_script.name == xcode_build_script_name | |
| } | |
| if (!script_installed) | |
| puts "Installing run script in Xcode project #{path_to_project}" | |
| phase = main_target.new_shell_script_build_phase(xcode_build_script_name) | |
| phase.shell_script = path_to_xcode_build_script | |
| project.save() | |
| else | |
| puts "Run script already installed" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Pod::Spec.new do |s| | |
| s.name = 'POD_NAME' | |
| s.version = '1.0.0' | |
| s.license = { :type => 'MIT', :file => 'LICENSE' } | |
| s.summary = 'Example of pod which installs a run script into the Xcode project (first target)' | |
| s.homepage = 'https://github.com/phatblat/POD_NAME' | |
| s.authors = { 'Ben Chatelain' => 'benchatelain@gmail.com' } | |
| s.source = { :git => 'https://github.com/phatblat/POD_NAME.git', :tag => s.version.to_s } | |
| s.ios.deployment_target = '6.0' | |
| s.requires_arc = true | |
| s.source_files = "Classes/**/*.{h,m}" | |
| s.preserve_paths = 'run_script.sh', 'install_run_script.rb' | |
| s.prepare_command = "ruby install_run_script.rb '#{path}'" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| echo "Every build is awesome!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment