Skip to content

Instantly share code, notes, and snippets.

@levantAJ
Last active Sep 12, 2019
Embed
What would you like to do?
Convert back to use dylib for generate test coverage when using https://gist.github.com/levantAJ/b8eef8121573085d130fde46442e9658
#!/usr/bin/env ruby
def supported_staticlib_pods
return ['YouTubeVideoPlayer']
end
# After we improve Pre-main time app in [improve-pre-main-time-loading.rb](https://gist.github.com/levantAJ/b8eef8121573085d130fde46442e9658)
# Xcode can't generate test coverage with static libs http://www.openradar.me/41024315
# We have to convert back to dylib when running test coverage
# You need to run this before runing unit-test for checking test coverage
# Make sure `supported_staticlib_pods` is matched with `improve-pre-main-time-loading.rb` here (https://gist.github.com/levantAJ/b8eef8121573085d130fde46442e9658)
def use_dylibs
project_name = "YouProjectName"
pods_path = "Pods/Pods.xcodeproj/project.pbxproj"
pod_frameworks_path = "Pods/Target Support Files/Pods-#{project_name}/Pods-#{project_name}-frameworks.sh"
if(File.exist?(pods_path)) and (File.exist?(pod_frameworks_path))
pods_content = File.read(pods_path)
pod_frameworks_content = File.read(pod_frameworks_path)
is_updated_files = false
supported_staticlib_pods.each do |pod|
pods_mach_o_modulemap = "MODULEMAP_FILE = \"Target Support Files/#{pod}/#{pod}.modulemap\";"
pods_mach_o = "MACH_O_TYPE = staticlib;\n #{pods_mach_o_modulemap}"
if pods_content.include? pod
# Use dylib
pods_content = pods_content.gsub(pods_mach_o, pods_mach_o_modulemap)
# For Pods script file
lib_path = "\"${BUILT_PRODUCTS_DIR}/#{pod}/"
if pod == "UINavigationBar+Addition"
lib_path = "#{lib_path}UINavigationBar_Addition.framework\""
elsif pod == "GzipSwift"
lib_path = "#{lib_path}Gzip.framework\""
else
lib_path = "#{lib_path}#{pod}.framework\""
end
unless pod_frameworks_content.include? lib_path
pod_frameworks_content = pod_frameworks_content.gsub(".framework\"\nfi", ".framework\"\n\tinstall_framework #{lib_path}\nfi")
is_updated_files = true
end
end
end
File.write(pods_path, pods_content)
if is_updated_files
File.write(pod_frameworks_path, pod_frameworks_content)
end
puts "Converted white-list libs back to use dylib!"
else
puts pods_path ' or ' + pod_frameworks_path + ' not found'
end
end
use_dylibs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment