class Pod::HeaderMapsGenerator
Attributes
all_project_headers[RW]
all_targets_headers[RW]
deleted_pod_targets[R]
headers_cache[RW]
project_headers_by_target[RW]
targets_headers_by_target[RW]
Public Class Methods
analyze_cache_from(path, regenerate_pod_targets)
click to toggle source
Fetch headers cache from sandbox if `incremental_installation` enabled.
# File lib/cocoapods-headermap/header_maps_generator.rb, line 47 def analyze_cache_from(path, regenerate_pod_targets) UI.message 'Analyzing Headers Cache' do self.headers_cache = HeaderMapsCache.from_file(path) # Regenerate pod target must remove cache first. unless regenerate_pod_targets.nil? || regenerate_pod_targets.empty? regenerate_pod_targets.each do |pod_target| headers_cache.project_headers_cache.delete(pod_target.pod_name) headers_cache.targets_headers_cache.delete(pod_target.pod_name) end end # Pods that were deleted need to be removed from cache. unless deleted_pod_targets.empty? deleted_pod_targets.each do |pod_name| headers_cache.project_headers_cache.delete(pod_name) headers_cache.targets_headers_cache.delete(pod_name) end end self.project_headers_by_target = headers_cache.project_headers_cache self.targets_headers_by_target = headers_cache.targets_headers_cache project_headers_by_target.each do |pod_target, project_headers| all_project_headers.merge!(project_headers) { |key, pre, new| pre } unless project_headers.empty? end targets_headers_by_target.each do |pod_target, targets_headers| all_targets_headers.merge!(targets_headers) unless targets_headers.empty? end end end
deleted_pod_targets=(deleted_pod_target)
click to toggle source
# File lib/cocoapods-headermap/header_maps_generator.rb, line 27 def deleted_pod_targets=(deleted_pod_target) return if deleted_pod_target.nil? deleted_pod_targets << deleted_pod_target end
generate!(sandbox)
click to toggle source
Generate header map files for all project and targets.
# File lib/cocoapods-headermap/header_maps_generator.rb, line 33 def generate!(sandbox) UI.puts "[cocoapods-headermap]: Generating header maps.." generate_header_files(sandbox, all_project_headers, Sandbox::POD_PROJECT_HEADERS) generate_header_files(sandbox, all_targets_headers, Sandbox::POD_TARGETS_HEADERS) end
generate_header_files(sandbox, headers, file_name)
click to toggle source
Generate `hmap` files for the project of `Pods`. It should be `Pods-all-target-headers.hmap` and `Pods-project-headers.hmap`.
# File lib/cocoapods-headermap/header_maps_generator.rb, line 94 def generate_header_files(sandbox, headers, file_name) return if headers.nil? || headers.empty? header_json_path = sandbox.headers_root + "#{file_name}.json" File.open(header_json_path, "w") do |f| f.write(JSON.pretty_generate(headers)) end json_convert_file(header_json_path) end
install_brew_package(retry_count)
click to toggle source
Install swift headermap tool less than three times if neccessary.
# File lib/cocoapods-headermap/header_maps_generator.rb, line 115 def install_brew_package(retry_count) raise Informative, "[cocoapods-headermap]: Excuting `brew install milend/taps/hmap` error!" if retry_count > 3 if_install_success = system "brew install milend/taps/hmap" install_brew_package(retry_count + 1) unless if_install_success end
json_convert_file(json_path)
click to toggle source
Convert json file to headermap file.
# File lib/cocoapods-headermap/header_maps_generator.rb, line 105 def json_convert_file(json_path) install_brew_package(1) if `which hmap`.empty? hmap_path = json_path.sub_ext(".hmap") `hmap convert #{json_path} #{hmap_path}` File.delete(json_path) if File.exist?(json_path) end
merge_target_headers(pod_target)
click to toggle source
Merge the headers for every target and the whole project. If there is a header file with the same name between different pods, it will keep the previous one.
# File lib/cocoapods-headermap/header_maps_generator.rb, line 80 def merge_target_headers(pod_target) pod_project_headers = pod_target.build_headers.pod_project_headers all_project_headers.merge!(pod_project_headers) { |key, pre, new| pre } unless pod_project_headers.empty? pod_target_headers = pod_target.build_headers.pod_target_headers all_targets_headers.merge!(pod_target_headers) unless pod_target_headers.empty? # Store original data structure of header ordered by target. project_headers_by_target[pod_target.pod_name] = pod_project_headers unless pod_project_headers.empty? targets_headers_by_target[pod_target.pod_name] = pod_target_headers unless pod_target_headers.empty? end
update_cache_to(path)
click to toggle source
Store headers cache to sandbox.
# File lib/cocoapods-headermap/header_maps_generator.rb, line 40 def update_cache_to(path) return unless headers_cache headers_cache.update_headers!(project_headers_by_target, targets_headers_by_target) headers_cache.save_as(path) end