Updated Podfile postinstall script
Showing
| ... | ... | @@ -47,6 +47,15 @@ def application_pods |
| end | ||
| #-------Targets------- | ||
| #Analytics | ||
| target 'OneWeatherAnalytics' do | ||
| project 'OneWeatherAnalytics/OneWeatherAnalytics.project' | ||
| shared_pods | ||
| analytics_pods | ||
| end | ||
| #Application | ||
| target '1Weather' do | ||
| shared_pods | ||
| core_pods | ||
| ... | ... | @@ -92,81 +101,53 @@ target 'WDTWeatherSource' do |
| shared_pods | ||
| end | ||
| #Analytics | ||
| target 'OneWeatherAnalytics' do | ||
| project 'OneWeatherAnalytics/OneWeatherAnalytics.project' | ||
| shared_pods | ||
| analytics_pods | ||
| end | ||
| target 'OneWeatherNotificationServiceExtension' do | ||
| use_frameworks! | ||
| pod 'MORichNotification' | ||
| end | ||
| post_install do |installer| | ||
| auto_process_target(['1Weather'], 'OneWeatherAnalytics', installer) | ||
| end | ||
| def auto_process_target(app_target_names, embedded_target_name, installer) | ||
| words = find_words_at_embedded_target('Pods-' + embedded_target_name, | ||
| installer) | ||
| handle_app_targets(app_target_names.map{ |str| 'Pods-' + str }, | ||
| words, | ||
| installer) | ||
| end | ||
| def find_line_with_start(str, start) | ||
| str.each_line do |line| | ||
| if line.start_with?(start) | ||
| return line | ||
| end | ||
| end | ||
| return nil | ||
| end | ||
| def remove_words(str, words) | ||
| new_str = str | ||
| words.each do |word| | ||
| new_str = new_str.sub(word, '') | ||
| end | ||
| return new_str | ||
| end | ||
| def find_words_at_embedded_target(target_name, installer) | ||
| target = installer.pods_project.targets.find { |target| target.name == target_name } | ||
| target.build_configurations.each do |config| | ||
| xcconfig_path = config.base_configuration_reference.real_path | ||
| xcconfig = File.read(xcconfig_path) | ||
| old_line = find_line_with_start(xcconfig, "OTHER_LDFLAGS") | ||
| if old_line == nil | ||
| next | ||
| end | ||
| words = old_line.split(' ').select{ |str| str.start_with?("-l") }.map{ |str| ' ' + str } | ||
| return words | ||
| end | ||
| end | ||
| def handle_app_targets(names, words, installer) | ||
| installer.pods_project.targets.each do |target| | ||
| if names.index(target.name) == nil | ||
| next | ||
| end | ||
| puts "Updating #{target.name} OTHER_LDFLAGS" | ||
| target.build_configurations.each do |config| | ||
| xcconfig_path = config.base_configuration_reference.real_path | ||
| xcconfig = File.read(xcconfig_path) | ||
| old_line = find_line_with_start(xcconfig, "OTHER_LDFLAGS") | ||
| if old_line == nil | ||
| next | ||
| applicationTargets = [ | ||
| 'Pods-OneWeatherAnalytics' | ||
| ] | ||
| libraryTargets = [ | ||
| 'Pods-1Weather' | ||
| ] | ||
| embedded_targets = installer.aggregate_targets.select { |aggregate_target| | ||
| libraryTargets.include? aggregate_target.name | ||
| } | ||
| embedded_pod_targets = embedded_targets.flat_map { |embedded_target| embedded_target.pod_targets } | ||
| host_targets = installer.aggregate_targets.select { |aggregate_target| | ||
| applicationTargets.include? aggregate_target.name | ||
| } | ||
| # We only want to remove pods from Application targets, not libraries | ||
| host_targets.each do |host_target| | ||
| host_target.xcconfigs.each do |config_name, config_file| | ||
| host_target.pod_targets.each do |pod_target| | ||
| if embedded_pod_targets.include? pod_target | ||
| pod_target.specs.each do |spec| | ||
| if spec.attributes_hash['ios'] != nil | ||
| frameworkPaths = spec.attributes_hash['ios']['vendored_frameworks'] | ||
| else | ||
| frameworkPaths = spec.attributes_hash['vendored_frameworks'] | ||
| end | ||
| if frameworkPaths != nil | ||
| frameworkNames = Array(frameworkPaths).map(&:to_s).map do |filename| | ||
| extension = File.extname filename | ||
| File.basename filename, extension | ||
| end | ||
| frameworkNames.each do |name| | ||
| puts "Removing #{name} from OTHER_LDFLAGS of target #{host_target.name}" | ||
| config_file.frameworks.delete(name) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| new_line = remove_words(old_line, words) | ||
| new_xcconfig = xcconfig.sub(old_line, new_line) | ||
| File.open(xcconfig_path, "w") { |file| file << new_xcconfig } | ||
| xcconfig_path = host_target.xcconfig_path(config_name) | ||
| config_file.save_as(xcconfig_path) | ||
| end | ||
| end | ||
| end |
This source diff could not be displayed because it is too large.
You can
view the blob
instead.
Please
register
or
sign in
to comment