Last active
August 29, 2015 14:23
-
-
Save vfn/9258b25f7c994e0af833 to your computer and use it in GitHub Desktop.
Podfile post hook
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
post_install do |installer_representation| | |
workDir = Dir.pwd | |
xcconfigFilesPath = "#{workDir}/Pods/Target Support Files/Pods/Pods.*.xcconfig" | |
xcconfigFiles = Dir[xcconfigFilesPath] | |
xcconfigFiles.each do |xcconfigFilename| | |
next if File.directory? xcconfigFilename | |
puts "----------- Post hook will modify #{xcconfigFilename}" | |
xcconfig = File.read(xcconfigFilename) | |
newXcconfig = xcconfig | |
prefix = "PODS_" | |
regexString = "^(?!#{prefix})(.*)( = .*)$" | |
regex = /#{regexString}/ | |
keys = xcconfig.scan(regex) | |
keys.each do |row| | |
key = row[0] | |
pods_key = prefix + key | |
newXcconfig = newXcconfig.sub(key, pods_key) | |
end | |
newXcconfig += "\n\n\n\n// Create association, just in case the the values are not overriden anywhere else\n// If you need to override the following xcconfig keys, make sure to add the respective `POD_` prefixed key\n" | |
keys.each do |row| | |
key = row[0] | |
next if keys_to_keep_intact.include? key | |
newXcconfig += key + " = $(inherited) $#{prefix + key}\n" | |
end | |
newXcconfig = xcconfig_string_modifier_hook(newXcconfig) | |
File.open(xcconfigFilename, "w") { |file| file << newXcconfig } | |
puts "-----------" | |
end | |
end | |
# An array with the keys that shouldn't be mofidied, | |
# because you are modifying it yourself and is | |
# including the respective `PODS_` key | |
def keys_to_keep_intact | |
return ["OTHER_LDFLAGS"] | |
end | |
def xcconfig_string_modifier_hook(string) | |
# Remove reference to Reveal lib otherwise it will fail when building for device | |
string = string.sub(" -framework \"Reveal\"", "") | |
return string | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment